function xNew = Newton(f, x0, tol)

fprintf('\n Newton method solver \n\n');
horzLine = '_________________________________________________';
fprintf(' n |        x(n)        |x(n)-x(n-1)|  f(x(n)) \n%s\n', horzLine);

df = diff(f);
xOld = x0;

for n = 1:100
    xNew = xOld - subs(f,xOld) / subs(df,xOld);
    
    fprintf('%2d | %18.12g | %9.2e | %9.2e \n', n, xNew, abs(xNew-xOld), subs(f,xNew));  
    if  abs(xNew - xOld) < tol
        return
    end

    xOld = xNew;
end
fprintf('*** Newton method failed to converge after 100 iterations');