% SMD.m: Plots displacement of under-damped
% spring-mass-damper system
%
% y0 = initial displacement, inches
% dc = damping coefficient
% fr = natural frequency (omega), radians/sec
% fd = damped frequency (omega_D), radians/sec
% t = time,seconds
% y = displacement, inches
y0 = 3.0;
dc = 0.10;
fr = 2*pi;
fd = fr*sqrt(1-dc^2);
for i = 1:101
    t(i) = (i-1)*0.05;
    c = cos(fd*t(i));      % cos(omega t)
    s = sin(fd*t(i));
    e = exp(-dc*fr*t(i));
    y(i) = (y0*c + y0*dc*fr/fd*s)*e;
end
plot(t,y)