% test_newton.m % Example 1: usual case, quadratic convergence f = @(x) x^2 -2; fp = @(x) 2*x; % Example 2 root of multiplicity > 1, linear convergence f = @(x) (x-5)^4; fp = @(x) 4*(x-5)^3; % Example 3 possibility of non-convergence f = @(x) tanh(x); fp = @(x) 1 - tanh(x)^2; abstol = 1.0e-14 maxits = 20 x0 = 1.0 x0 = 1.09 r = newton(f,fp,x0,abstol,maxits)