%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function odedemo3
% Spring and mass
clear
disp(['Starting at:   ' datestr(now)])

x0 = 1;  v0 = 0;
zzero = [x0 v0];
tspan = linspace(0,20, 101);


  %%%%%%%%%%%
  [t zarray] = ode45(@myrhs,tspan,zzero);
  %%%%%%%%%%%
  
  x = zarray(:,1);  % x is the first col of zarray
 
  plot(t, x); xlabel('t'); ylabel('x')

end %       end odedemo3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function zdot = myrhs(t,z)
x = z(1);  v = z(2);
k=1; m = 1;

xdot = v;
vdot = -k*x/m;

zdot = [xdot;vdot]; % has to be a column array 
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%