Simple ODE 2nd order with ODE45 - Where's my problem?
Show older comments
Hello everyone,
Im trying to solve this simple problem since 2 days and I can't seem to figure it out.

I have a simple 2nd order ODE (See Image) Lets assume theta = phi.
In the first case, c = 0. So, the eqn is:
phi'' = -w^2 * sin(phi).
My code is:
function second_oder_ode_2a
l=0.5;
g=9.81;
w=sqrt(g/l)
t=0:0.001:500; % time scale
initial_phi = 45;
initial_dphidt = (1/pi)*180;
[t,phi]=ode45( @rhs, t, [initial_phi initial_dphidt]);
plot(t,phi(:,1));
xlabel('t'); ylabel('phi');
function dphidt=rhs(t,phi,w)
dphidt_1 = phi(2);
dphidt_2 = -w^.2 * sin(phi(1));
dphidt=[dphidt_1; dphidt_2];
I really have no idea where the problem is. Errors occur at:
• ODE45 Function • dphidt = -w^.2 * sin(phi(1));
Any help is appreciated.
Greetings
Answers (1)
[t,phi]=ode45( @(t,y)rhs(t,y,w), t, [initial_phi initial_dphidt]);
And convert degress in radians in your initial conditions.
Best wishes
Torsten.
3 Comments
Robin Malsam
on 8 Jun 2017
Edited: Robin Malsam
on 8 Jun 2017
Torsten
on 8 Jun 2017
I don't know which parameters are taken in your book, but the reason for the discrepancy can only be the value of "w".
Best wishes
Torsten.
Robin Malsam
on 9 Jun 2017
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
