% note how I keep calculations exact rather than retype in decimal
% approximations. Making Matlab do as much as possible is best.

t = 0:0.001:3;                                      % time range to plot
w = 3.2*pi;                                         % omega_0
l = -w; c1 = 0.1; c2 = -l*c1;                       % critical coeffs
figure; plot(t, c1*exp(-w*t) + c2*t.*exp(-w*t), '-');    % note .* elementwise
r1 = w*(-10-sqrt(99)); r2 = w*(-10+sqrt(99));       % overdamped roots
c1 = 0.1*r2/(r1-r2); c2 = 0.1 - c1;                 % coeffs
hold on; plot(t, c1*exp(r1*t) + c2*exp(r2*t), 'r--');
l = -w/10; mu = sqrt(99/100)*w; c1 = 0.1; c2 = -l*c1/mu; % underdamped
plot(t, exp(l*t).*(c1*cos(mu*t) + c2*sin(mu*t)), 'g-.');
xlabel('t (sec)'); ylabel('y (meters)'); title('comparison of car motion');
legend('critical damping','overdamped','underdamped');
