MATLAB: Solving a coupled system of differential equations with matrix form!!

differential equationsMATLABsystem

I am trying to solve this system of differential equation with matrixes:
_y'=v
v'=-ay, y(0)=y0, v(0)=y1_
Is there anyone who can help me???

Best Answer

Sure,
Lets introduce a new variable z such that
z(1) = y;
z(2) = v;
Then we have for Dz:
Dz(1) = z(2);
Dz(2) = -a*z(1);
Then you write your ODE-function (preferably in an m-file):
function Dy = harmonic_ode(t,z)
Dz = [0;0];
Dz(1) = z(2);
Dz(2) = -a*z(1);
To solve your ODE you should preferably use one of the built-in ODE-solvers, for example ode23 z0 = [y0;y1]; [sol] = ode23(@(t,z) harmonic_ode(t,z),t_span,z0);
HTH