clear all
close all
ordine = 2;
m = 200;
x = linspace(0,1,m)';
h = 1/(m-1);
u0 = sin(pi*x);
tstar = 1;
u = u0;
A = toeplitz(sparse([-2/h^2,1/h^2,zeros(1,m-2)]));
A(1,:) = 0;
A(m,:) = 0;
g = (1+pi^2)*sin(pi*x);
tsrange = [20:10:60];
counter = 0;
for timesteps = tsrange
  counter = counter+1;
  t = 0;
  u = u0;
  k = tstar/timesteps;
  E = expm(k*A);
  P = phi1m(k*A);
  for n = 1:timesteps
    u = E*u+k*P*exp(t+(ordine-1)*k/2)*g;
    t = t+k;
  end
  errore(counter) = norm(u-exp(tstar)*sin(pi*x),Inf);
end
loglog(tsrange,errore,'o',tsrange,errore(1)*(tsrange/tsrange(1)).^(-ordine))
legend('errore',sprintf('ordine %d',ordine))
xlabel('timesteps')
ylabel('errore')