function [Vout,t] = mystep(A,F,doplot) if ~exist('doplot') doplot=0; % no plot, by default! end K=1; Ka=2; Km=.17; Kp=.25; J=1e-3; dt=1e-4; t=0:dt:5; y=0*t; v=y; a=y; Vout=y; for n=2:length(y) a(n)=((K*Ka*Km*(A-Kp*y(n-1)))-sign(v(n-1))*F)/J; v(n)=v(n-1) + dt*a(n); y(n)=y(n-1) + dt*v(n); end Vout=.25*y; if doplot plot(t,Vout); end