function [n,x,fx]=Newton(x)

n=0; nmax=50; tol=1.0e-12; 
[fx, dfx] = F(x);

if abs(dfx) < tol
    fprintf('Bad initial guess, |dfx| < %.4e\n', tol);
    return;
end

while (n <= nmax) && (abs(fx) > tol)
    x = x - fx / dfx;
    [fx, dfx] = F(x);
    n = n + 1;
end

fprintf('%5d %.16e %.4e\n', n, x, fx);

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [fx, dfx] = F(x)
    fx = (3*x-2)*(x*x+1);
    dfx = 9*x*x - 4*x + 3;
end