function zdot=springfn(t,z);  % Save as springfn.m
% This is Andy Ruina's right hand side for a bouncy spring
% It works for both 2 and 3 dimensions.

global k Lzero m g jhat n
r=z(1:n); v=z(n+1:2*n);
L= norm(r);   %gives the length of r
T= ( L > Lzero )  * k * (L - Lzero);
Lam= r/L;
rddot= - T * Lam / m - g * jhat;
zdot=[v rddot];
%end of function file.