% damped simple harmonic oscillator demo
% x''(t) = - x(t) - 2*a*x'(t) 

 a = input('enter damping paramter, a >= 0: ');

 A = [0 1; -1 -2*a];

 eig(A);
 
 x0 = [1;0];

 t = linspace(0,5*pi,100);
 traj = zeros(length(t));
 figure(1), clf
 plot([min(t) max(t)],[0 0],'-','linewidth',1,'color',.7*[1 1 1]), hold on
 for k=1:length(t)
    x = expm(t(k)*A)*x0;
    traj(k) = x(1);
    if k>1,
       plot(t(k-1:k),traj(k-1:k),'b-','linewidth',2)
       axis([min(t) max(t) -1.1 1.1])
       xlabel('$t$','interpreter','latex','fontsize',20)
       ylabel('$x(t)$','interpreter','latex','fontsize',20)
       pause(0.04) 
    end
 end 

 
