clear;

lambda = -1.0;

yo = 1.0;
y(1) = yo;
yexact(1) = yo;
diff(1) = y(1)-yexact(1);

t(1) = 0.0;
tmax = 5.;
nt = 1000.;
h = tmax/nt;
lambda*h

for i=1:nt
  y(i+1) = y(i)/(1.-lambda*h);
  t(i+1) = t(i)+h;
  yexact(i+1) = yo*exp(lambda*t(i+1));
  diff(i+1) = sqrt((yexact(i+1)-y(i+1))^2)/h;
  end

subplot(2,2,1)
plot(t,y),xlabel('t'),ylabel('y (numerical)')

subplot(2,2,2)
plot(t,yexact),xlabel('t'),ylabel('y (exact)')

subplot(2,2,3)
semilogy(t,abs(y-yexact)),xlabel('t'),ylabel('y(numerical)-y(exact)')

subplot(2,2,4)
semilogy(t,diff),...
   xlabel('t'),ylabel('(y(numerical)-y(exact))/h')
