1 function [root, iterations] = newtons_method(f, f_prime, epsilon, x0)
2 % Find a root of the function `f` with initial guess x0.
6 % * ``f`` - The function whose root we seek. Must return a column
9 % * ``f_prime`` - The derivative or Jacobian of ``f``.
11 % * ``epsilon`` - We stop when the value of `f` becomes less
14 % * ``x0`` - An initial guess. Either 1d or a column vector.
18 % * ``root`` - The root that we found.
20 % * ``iterations`` - The number of iterations that we performed
33 while (norm(f_val, Inf) > epsilon)
34 % This uses the modified algorithm (2.11.5) in Atkinson.
35 % Should work in 1d, too.
36 delta = f_prime(xn) \ f_val;
39 iterations = iterations + 1;