function plotcar
clear all
global t v k m c lambda amp
k=6*10^4;
m=900;
c=4500;
lambda=4;
amp=0.04;
v=75/3600*5280*12*0.0254; % 75 mph converted to m/s
tend=lambda/v;
nduring=20;
dt=tend/nduring;
for i=1:(nduring+1)
   t=(i-1)*dt;
   time(i)=t;
   z=quadl(@integ,0,t,10^-5);
   x(i)=z+amp*(1-cos(2*pi*v/lambda*t));
end
nafter=200;
for i=1:nafter
   t=tend+i*dt;
   time(i+nduring+1)=t;
   x(i+nduring+1)=quadl(@integ,0,tend,10^-5);
end
plot(time,x)
xlabel('time (s)')
ylabel('x (meters)')
%
function f=integ(xi)
global t v k m c lambda amp
cc=2*sqrt(k*m);
zeta=c/cc;
omegan=sqrt(k/m);
h=exp(-zeta*omegan*(t-xi))/sqrt(1-zeta^2) .* sin(sqrt(1-zeta^2)*omegan*(t-xi));
f=-1/omegan*amp*(2*pi*v/lambda)^2*h .* cos(2*pi*v/lambda*xi);
   
