function y = h(x)
    y = x - (1 + x.^2) .* atan(x)
endfunction
//
function y = dh(x)
    y = -2 * x .* atan(x)
endfunction
//
// grafici
clf();
x = linspace(-1,1,201)';
plot(x,[h(x),abs(dh(x)),%pi * abs(x)]);
xgrid();
legend('h(x)','|dh(x)|','%pi |x|');
xlabel('x','fontsize',2);
// modifica grafico
ac = gca();
curva_h = ac.children(2).children(3);
curva_h.thickness = 2;
curva_dh = ac.children(2).children(2);
curva_dh.thickness = 2;
curva_pi = ac.children(2).children(1);
curva_pi.thickness = 2;
leg = ac.children(1);
leg.font_size = 3;
ac.font_size = 2;
// Metodo Newton
function x = MetodoNewton(f,df,x0,delta)
    x = x0;
    k = 0; kmax = 50;
    while ( abs(f(x($))) >= delta & k < kmax ),
        x($+1) = x($) - f(x($)) / df(x($))
        k = k + 1;
    end
endfunction
//
function y = f(x)
    y = atan(x)
endfunction
//
function y = df(x)
    y = 1 ./ (1 + x.^2)
endfunction
//
x0 = 0.5;
delta = 1D-10;
xN = MetodoNewton(f,df,x0,delta);
//
clf();
plot('nl', [0:length(xN)-1]', abs(xN));
xgrid();
xlabel('k','fontsize',2);
ylabel('iterazione','fontsize',2);
