% du/ dt = d^2u/dt^2+2exp(t)*sin(x), 0<x<pi/2
% u(0,x) = sin(x)
% u(t,0) = 0
% du/dx (t,pi/2) = 0
clear all
close all
method = 2;
t0 = 0;
tstar = 1-t0;
m = 50;
timesteps = 50;
[x,y] = ese3kernel(m,timesteps,method);
yexact = exp(t0+tstar)*sin(x);
plot(x,y,'*',x,yexact)
legend('soluzione numerica','soluzione analitica')
% ordine spaziale
mrange = 5:5:20;
timesteps = 5000; 
counter = 0;
for m = mrange
  counter = counter + 1;
  [x,y] = ese3kernel(m,timesteps,method);
  yexact = exp(t0+tstar)*sin(x);
  errores(counter) = norm(y-yexact,inf);
end
figure
loglog(mrange,errores,'*',mrange,mrange.^(-2))
legend('ordine spaziale','ordine 2')
% ordine temporale
timestepsrange = 15:10:55;
m = 100; % grande, in modo che non influenzi l'errore temporale.
counter = 0;
for timesteps = timestepsrange
  counter = counter + 1;
  [x,y] = ese3kernel(m,timesteps,method);
  yexact = exp(t0+tstar)*sin(x);
  erroret(counter) = norm(y-yexact,inf);
end
figure
loglog(timestepsrange,erroret,'*',timestepsrange,timestepsrange.^(-method))
legend('ordine temporale',sprintf('ordine %1d',method))
