Second order non linear differential
이전 댓글 표시
I have to solve the following equation: y''(s) + cos(y) = 0
BC: y(0) = pi/2 and y(L/4) = 0
I actually have no idea what function is the correct one in this case or even if MatLab can solve this, do you have any suggestion?
댓글 수: 1
Torsten
2024년 6월 2일
답변 (1개)
Manikanta Aditya
2024년 6월 1일
편집: Manikanta Aditya
2024년 6월 1일
Solving a second-order nonlinear differential equation analytically can be challenging, and often such equations do not have closed-form solutions. However, MATLAB can be used to solve this numerically.
You can use the ode45 function, which is a versatile solver for ordinary differential equations.
Check this script which will help you:
function solve_nonlinear_ode
% Initial conditions
y0 = [0; 0]; % y(0) = 0, y'(0) = 0
% Time span
tspan = [0 10];
% Solve the system
[t, y] = ode45(@nonlinear_ode, tspan, y0);
% Plot the solution
figure;
plot(t, y(:,1));
xlabel('s');
ylabel('y(s)');
title('Solution of y''''(s) + cos(y) = 0');
grid on;
end
function dydt = nonlinear_ode(~, y)
dydt = zeros(2, 1); % Initialize the output
dydt(1) = y(2); % y' = v
dydt(2) = -cos(y(1)); % v' = -cos(y)
end
I hope this helps.
댓글 수: 8
John D'Errico
2024년 6월 1일
Please, do not do what are obvious homework assignments for students. This does not helpl the student. it teaches them only that someone will often step forward to do their assignments for them. And that hurts both the student and the forum. It teaches other students to do the same, to post their work as a question here.
If you want to help the student, then give them a nudge in the right direction. That nudge should artfully be calibrated to the effort they have shown. If they show no effort at all, and you still want to offer them help, then just point them to the help docs for ODE45, which has examples of how to solve a second order ODE.
Manikanta Aditya
2024년 6월 1일
Thanks @John D'Errico for the suggestation, will follow it from now on. Actually the user mentioned they are not sure if it's doable or not in MATLAB, that didn't sound like a student to me. So I tried to clear and prove it is doable, that's my reason to answer in detail.
Anyhow thanks for the input, will note it!
Manikanta Aditya
2024년 6월 1일
@Alessandro Meda Hope you too got the point told by John!
Alessandro Meda
2024년 6월 2일
Sam Chak
2024년 6월 2일
Hi Manikanta, but John's point to ode45 doesn't guide or help Alessandro to solve the problem because this is a Boundary Value Problem with this clue y(L/4) = 0.
If you are familiar with solving the ring tension problem, you can provide some examples.
Manikanta Aditya
2024년 6월 2일
"BC: y(0) = pi/2 and y(L/4) = 0" in the question. So I did not knew it then.
Sam Chak
2024년 6월 2일
Hi Manikanta,
Thank you for your clarification. The OP has updated the description of the problem, but there does not appear to be an edit history available for tracking the changes.
However, your efforts to be helpful are commendable. It is important to remain motivated, as some individuals may not be adept at framing their problems when asking questions for the first time. However, that does not necessarily imply that their questions are simply obvious homework assignments for students.
Manikanta Aditya
2024년 6월 3일
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!