clear all
close all
A = [-100,0;0,-1];
tstar = 40;
y0 = [1;1];
yesatta = [exp(tstar*(-100));exp(tstar*(-1))];
% ts > 2000 per avere la convergenza a 0 per Eulero esplicito
% ts > 4000 per avere una soluzione positiva per Eulero esplicito
tsrange = 2000:500:4500;
counter = 0;
for ts = tsrange
    counter = counter+1;
    k = tstar / ts;
    yee = y0;
    yei = y0;
    for n = 1:ts
        yee = yee+k*A*yee; % Eulero esplicito
        yei = (eye(2)-k*A) \ yei; % Eulero implicito
    end
    eee(counter) = norm (yee-yesatta,inf);
    eei(counter) = norm (yei-yesatta,inf);
end
loglog(tsrange,eei,'*',...
       tsrange,eee,'o',...
       tsrange,eei(end)*(tsrange/tsrange(end)).^(-1))
legend('Eulero implicito','Eulero esplicito','ordine 1')
