No BSD License  

Highlights from
Numerical Methods for Physics

from Numerical Methods for Physics by Alejandro Garcia
Companion Software

sprrk(a,time,param)
function deriv = sprrk(a,time,param)
%  Function to compute 3 mass-spring system
%  using Runge-Kutta integrator
%  The time is not used in this function
%  The vector a is [x(1) x(2) x(3) v(1) v(2) v(3)]
%  The vector param = k_over_m = (spring constant)/mass
%  The vector deriv = [dx(1)/dt dx(2)/dt ... dv(3)/dt]
deriv(1) = a(4);      % dx(1)/dt = v(1)
deriv(2) = a(5);      % dx(2)/dt = v(2)
deriv(3) = a(6);      % dx(3)/dt = v(3)
deriv(4) = -2*param*a(1) + param*a(2);         % dv(1)/dt
deriv(5) = -2*param*a(2) + param*(a(1)+a(3));  % dv(2)/dt
deriv(6) = -2*param*a(3) + param*a(2);         % dv(3)/dt
return;

Contact us at files@mathworks.com