
function esercizio3_2021

esperimento=2;

t0=0; y0=1; tol=10^(-6); lambda=-100;
f=@(x,y) 0*x+lambda*y;
t_end=20;

switch esperimento
    
     case 1 % eulero esplicito
        
        
        h=0.1;[t1,y1]=eulero_esplicito(t0,y0,t_end,h,f);
        e1=abs(exp(lambda*t_end)-y1(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e1);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
       
        
        h=0.05;[t2,y2]=eulero_esplicito(t0,y0,t_end,h,f);
        e2=abs(exp(lambda*t_end)-y2(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e2);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        
        h=0.02;[t3,y3]=eulero_esplicito(t0,y0,t_end,h,f);% 
        e3=abs(exp(lambda*t_end)-y3(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e3);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        
        h=0.01;[t4,y4]=eulero_esplicito(t0,y0,t_end,h,f);% 
        e4=abs(exp(lambda*t_end)-y4(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e4);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        
        h=0.001;[t5,y5]=eulero_esplicito(t0,y0,t_end,h,f);% 
        e5=abs(exp(lambda*t_end)-y5(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e5);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
    
    
    case 2 % eulero implicito
        
        
        h=0.1;[t1,y1,flag1]=eulero_implicito(t0,y0,t_end,h,f,tol);
        e1=abs(exp(lambda*t_end)-y1(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e1);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        h=0.05;[t2,y2,flag2]=eulero_implicito(t0,y0,t_end,h,f,tol);
        e2=abs(exp(lambda*t_end)-y2(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e2);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        h=0.02;[t3,y3,flag3]=eulero_implicito(t0,y0,t_end,h,f,tol);
        e3=abs(exp(lambda*t_end)-y3(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e3);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        h=0.01;[t4,y4,flag4]=eulero_implicito(t0,y0,t_end,h,f,tol);
        e4=abs(exp(lambda*t_end)-y4(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e4);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
        h=0.001;[t5,y5,flag5]=eulero_implicito(t0,y0,t_end,h,f,tol);
        e5=abs(exp(lambda*t_end)-y5(end));
        fprintf('\n \t * h: %1.1e err: %1.1e',h,e5);
        if abs(1+h*lambda) < 1, fprintf('\n \t Nel disco EE'); end
        
end

fprintf('\n \n');
