
function esercizio

x0=[0; 0];

% Newton method
maxit=1000; tol=10^(-12);
[x, steps, flag]=newton_sistemi(x0,maxit,tol,@G,@JG);
sol=x(:,end);  res2=norm(G(sol),2); step2=norm(x(:,end)-x(:,end-1),2);
fprintf('\n \t * Newton method');
fprintf('\n \t Residual: %1.1e',res2);
fprintf('\n \t Step    : %1.1e',step2);
fprintf('\n \t Iterates: %3.0f',size(x,2));
fprintf('\n \t x             : %1.15e',sol(1));
fprintf('\n \t y             : %1.15e',sol(2));
fprintf('\n \n');

% Fixed point
[x,flag]=punto_fisso(x0,maxit,tol,@phi);
sol=x(:,end); res2=norm(G(sol),2); step2=norm(x(:,end)-x(:,end-1),2);
fprintf('\n \t * Fixed-point method');
fprintf('\n \t Residual: %1.1e',res2);
fprintf('\n \t Step    : %1.1e',step2);
fprintf('\n \t Iterates: %3.0f',size(x,2));
fprintf('\n \t x             : %1.15e',sol(1));
fprintf('\n \t y             : %1.15e',sol(2));
fprintf('\n \n');



function res=G(P)
x=P(1); y=P(2);
res(1,1)=x-atan(x+y).*sin(y)/10; 
res(2,1)=y-cos(x/4)-sin(y/4);

function res=JG(P)
x=P(1); y=P(2);
res(1,1)=1 - sin(y)./(10*((x + y).^2 + 1));
res(1,2)=- sin(y)./(10*((x + y).^2 + 1)) - (atan(x + y)*cos(y))/10;
res(2,1)=sin(x/4)/4;  
res(2,2)=1 - cos(y/4)/4;

function res=phi(P)
x=P(1); y=P(2);
res(1,1)=atan(x+y).*sin(y)/10; 
res(2,1)=cos(x/4)+sin(y/4);




