solving a second order linear differential equation

조회 수: 7 (최근 30일)
Eliraz Nahum
Eliraz Nahum 2018년 9월 23일
답변: Eliraz Nahum 2018년 9월 23일
hello everybody, I was trying to solve a simple pendulum second order linear differential equation of the form y''=-(g/l)*sin(y) while using the ode45 function. since it's a second order equation I understood that I have to manipulate the problem, so it will fit the ode45.
The mathematical manipulation I did is described in the attached picture.
I can't understand why my code fails...please help
g=9.8;
l=0.5;
t_span=[0 30];
teta0=deg2rad(60);
F=@(t,q) [q(2);-(g/l)*sin(q(2))];
[t,q]=ode45(@(t,q) F(t,q),t_span,teta0)

채택된 답변

Mischa Kim
Mischa Kim 2018년 9월 23일
편집: Mischa Kim 2018년 9월 23일
Almost there:
g = 9.8;
l = 0.5;
t_span = [0 30];
teta0 = deg2rad(60);
tetad0 = 0;
F = @(t,q) [q(2);-(g/l)*sin(q(1))]; % check your derivation
[t,q_t] = ode45(@(t,q) F(t,q),t_span,[teta0; tetad0])
This is a second order DE so you need two initial conditions, one for teta and one for tetad.

추가 답변 (1개)

Eliraz Nahum
Eliraz Nahum 2018년 9월 23일
thank you very much... sometimes it's not about the code, but the mathematics :-)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by