ODE45 solver solution : subprogram

%
%   Mass-Spring-Damper system 
%   ODE45 solver solution
%   ODE45 subprogram
%

function ydot = pmsd_sol(t,y)

m = 1;                      %  mass of the system in meter
k = 50;                     %  stiffness of the spring (N/m)
c = 20;                     %  damping coefficient

yd1 = y(2);
yd2 = -(k*y(1)+c*y(2))/m;

ydot = [yd1;yd2];