N = 30;   % number of nodes

V = zeros(N,1);
dV = zeros(N,1);

t = 0;
dt = 0.01;

while(t < 100)

   if (t < 2) V0 = 100 * ( ( sin(0.5*pi*t) )^2 ); 
      else V0 = 0;
      end

   ddV(1) = 50*V0 - 100*V(1) + 50*V(2) - 0.01*dV(1);

   for i=2:N-1
      ddV(i) = 50*V(i-1) - 100*V(i) + 50*V(i+1) - 0.01*dV(i);
      end

   ddV(N) = 50*V(N-1) - 50*V(N) - 1*dV(N);

   for i=1:N
      dV(i) = dV(i) + ddV(i)*dt;
      V(i) =  V(i) +  dV(i)*dt;
      end
   t = t + dt;
 
   hold off
   plot([0,N],[-150,250],'w+');
   hold on
   plot([0:N],[V0;V],'.-');
   pause(0.01);

   end
