Using ODE 45 on a system of equations
2 views (last 30 days)
Show older comments
Hi, having trouble representing dx^2/d^2t = -sinx as a system of two first order ODE's in MATLAB. I have broken down the second order ODE into
y_1 = x
y_1prime = y_2
y_2prime = -siny_1
Here is my matlab code so far
function yprime = siny(t,y)
yprime = -sin(y) ;
in one M file and then the run this function
tspan=[0,5];
yzero=0.5;
[t,y]=ode45(@siny,tspan,yzero);
plot(t,y)
now im just not sure how to represent convert this single plot into a system of equations.
2 Comments
Answers (1)
Jan
on 16 Feb 2013
Your siny function does not correlate to your system of differential equations of order 1. Better:
function yprime = siny(t,y)
yprime = [y(2), -sin(y(1))];
Now you need a [1 x 2] vector as initial value also.
See Also
Categories
Find more on Ordinary Differential Equations 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!