format compact; format longe
n=100;
dx = 1./(n); x = dx*(1:n)';
A = tridiagsp(1,-2,1,n) ./ (dx*dx) ;
I = speye(n);

scale = .501; scale = .500; scale = .499;
dt = scale*dx*dx;
dt = .001;

He = I + dt*A;  He=sparse(He);
Hi = I - dt*A;  Hi=sparse(Hi);

arg = (x-0.4).^2/(0.05).^2; u = exp(-arg);
arg = (x-0.6).^2/(0.05).^2; u = exp(-arg) + u;

plot(x,u,'r-'); pause

T_final = 0.01; time=0;
nstep = T_final/dt;

for loop = 1:9;
  ymax=max(u); 
  ymax=1;
  for k=1:nstep; time=time+dt;
      u = Hi\u;
      model = sum(u)/n - .5*(max(u)-min(u))*cos(2*pi*x);
      plot(x,u,'r-',x,model,'b--'); axis ([0 1 0 ymax]); pause(.01)
  end;
  time, pause
end;
    
