%
% Calcolo Numerico 1 -  20 giugno 2013 - MILANO ESERCIZIO 2
%
clear all
f=inline('x.^k.*exp(x-1)','x','k');
I(1)=1/exp(1);
kstop=[12:2:18];
for j=1:max(kstop)-1;
    I(j+1)=1-(j+1)*I(j);
end
a=0; b=1;
m=[100 200];
for i=1:length(kstop)
    for im=1:2
        Itrap=trapezi_k(f,kstop(i),a,b,m(im));
        err=abs(Itrap-I(kstop(i)));
        fprintf('Kmax=%2d \t m=%2d \t Itrap=%12.6f \t I_Kmax=%12.6f \t err=%12.6e \n',...
        kstop(i),m(im),Itrap,I(kstop(i)),err); 
    end
end

%Kmax=12 	 m=100 	 Itrap=    0.071882 	 I_Kmax=    0.071773 	 err=1.082884e-004 
%Kmax=12 	 m=200 	 Itrap=    0.071800 	 I_Kmax=    0.071773 	 err=2.706118e-005 
%Kmax=14 	 m=100 	 Itrap=    0.062857 	 I_Kmax=    0.062736 	 err=1.212056e-004 
%Kmax=14 	 m=200 	 Itrap=    0.062763 	 I_Kmax=    0.062736 	 err=2.749174e-005 
%Kmax=16 	 m=100 	 Itrap=    0.055861 	 I_Kmax=    0.056621 	 err=7.597946e-004 
%Kmax=16 	 m=200 	 Itrap=    0.055755 	 I_Kmax=    0.056621 	 err=8.659909e-004 
%Kmax=18 	 m=100 	 Itrap=    0.050278 	 I_Kmax=    0.325949 	 err=2.756714e-001 
%Kmax=18 	 m=200 	 Itrap=    0.050159 	 I_Kmax=    0.325949 	 err=2.757900e-001
 