%
%   Tema d'esame CALCOLO NUMERICO - MILANO 11 APRILE 2014 - Esercizio 3
%


clear all;
g=inline('0.5*sin(0.5*cos(x))','x'); 
f=inline('x-0.5*sin(0.5*cos(x))','x');
alpha_vero= fzero(f,0);
f1=inline('1+.25*sin(x).*cos(0.5*cos(x))','x');
x0=0; nmax=100;
for epsilon=[0.5 0.05 0.005];
   [xpf,itpf]=pfissodiff(g,x0,epsilon,nmax);
   err_pf=abs(xpf(itpf)-alpha_vero);
   eps2=epsilon^2;
   [xnew,itnew]=newton(f,f1,xpf(itpf),eps2,nmax);
   err_new=abs(xnew(itnew)-alpha_vero);
   fprintf('epsilon=%6.3f\n',epsilon);
   fprintf('iter pf =%3d err_pf =%12.6e\n',itpf,err_pf);
   fprintf('iter New=%3d err_new=%12.6e alpha_new=%15.12f\n',...
       itnew,err_new,xnew(itnew));
   disp(' ');
end

%epsilon= 0.500
%iter pf =  2 err_pf =5.987267e-003
%iter New=  2 err_new=3.713850e-006 alpha_new= 0.233729215809
 
%epsilon= 0.050
%iter pf =  3 err_pf =3.103701e-004
%iter New=  2 err_new=9.995370e-009 alpha_new= 0.233725511954
 
%epsilon= 0.005
%iter pf =  4 err_pf =1.587592e-005
%iter New=  2 err_new=2.615061e-011 alpha_new= 0.233725501985