Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Newton’s method and the secant method

ProblemFind a root of a smooth function near a starting guess, without a bracket
Devised byNewton’s method: Isaac Newton (1669, for polynomials), Joseph Raphson (1690), Thomas Simpson (1740, for general functions); convergence theory by Fourier, Cauchy and Kantorovich (1948). The secant method: as old as false position; its order was analysed in the twentieth century
AccuracyFull precision near a simple root; convergence is local and not guaranteed
CostNewton: one and one per step, order 2. Secant: one per step, order
Read firstBracketing methods: bisection, false position, Ridders and Brent
APInewton_raphson, secant_method

Overview

Newton’s method improves a guess for a root of in the simplest way imaginable. Near the graph of looks like its tangent line, and the zero of a straight line is easy to find. So replace by its tangent at the current point and take the tangent’s zero as the next point:

Near a simple root (one where the graph crosses the axis with nonzero slope, ) this roughly doubles the number of correct digits at every step. That makes it the most important iteration in numerical analysis: it computes square roots and reciprocals in hardware, solves the implicit equations of stiff ODE solvers, drives optimisation, and extends to systems of equations. The secant method replaces the tangent by the line through the last two points. It needs no derivative and is almost as fast.

Both are open methods: unlike the bracketing methods, they do not keep the root trapped in an interval, and from a poor starting point they can wander off, cycle or diverge. They are best used when a good starting guess is available, or to finish off after a bracketing method has done the rough work.

Where it is used

Newton’s method is the fastest general way to solve a smooth equation.

  • Power systems and circuits. The Newton-Raphson power-flow calculation and DC operating point of a nonlinear circuit are Newton iterations.
  • Calculators and libraries. Square roots and reciprocals have been computed by Newton’s method since antiquity; floating-point units still use variants.
  • Optimisation. Applied to the gradient, it becomes the Newton method for minimisation.
  • Secant method. When derivatives are not available, the secant method gives nearly the same speed.

History

Newton described his method in De analysi (written in 1669, published in 1711), solving the cubic by repeatedly substituting , neglecting the higher powers of , and repeating with the correction; John Wallis published the example in 1685. Newton’s process worked on the polynomial, not on the sequence of approximations. Joseph Raphson (1690) gave the simpler form that updates directly, and Thomas Simpson (1740) first stated it with derivatives (fluxions) for general functions and for systems of two equations. Joseph Fourier (1818) and Augustin-Louis Cauchy (1829) studied when it converges, and Leonid Kantorovich (1948) proved the theorem that guarantees convergence from conditions at the starting point alone.

The secant method is a descendant of the ancient rule of false position, without the bracket. Its order of convergence, the golden ratio, follows from a recurrence of Fibonacci type for the errors.

The idea

Newton’s method

Deriving the step. The tangent line to at is . Setting and solving for gives the formula in the overview. For example, to compute take , so that and the step simplifies to . Starting from :

error
11.5
21.416666666666667
31.414215686274510
41.414213562374690

Each error is roughly the square of the one before. The fifth iterate is correct to all 16 digits.

Why the error is squared. Let be the root and the error. Taylor’s theorem with remainder, expanding about and evaluating at , says

for some between and . Divide by and rearrange:

The left side is exactly . Therefore

The new error is a constant times the square of the old one. This is quadratic convergence: if the error is , the next is about and the one after about . The tangent line captured the constant and linear terms of the Taylor series exactly, so the only error left is the quadratic term.

Three conditions are hidden in this formula.

  • The root must be simple, , or the constant is infinite.
  • must be twice differentiable near the root.
  • The error must already be small: squaring only helps if . Far from the root the formula promises nothing.

Multiple roots. A root has multiplicity if behaves like near it; a double root () touches the axis without crossing. Then , so and the Newton step gives

The error shrinks only by a fixed factor at each step. This is linear convergence: at a double root the error halves each time, no better than bisection. If is known, the modified step cancels the error to first order and restores quadratic convergence.

Figure 4.2. Orders of convergence.

When Newton’s method fails

The convergence analysis is local: it assumes we are already near the root. From a poor starting point the tangent can point anywhere. The classic example is , whose only root is 0. The graph flattens out for large , so a tangent drawn far from the origin is nearly horizontal and crosses the axis far away on the other side. There is a critical starting value, :

  • from each step lands closer to 0 and the iteration converges;
  • from exactly the critical value the step lands at , and the iteration cycles between forever;
  • from beyond it each step lands further out than the last, and the iteration oscillates with growing amplitude and diverges.

Figure 4.3. Newton's method on arctan.

The orange path () shows the knife edge: it oscillates for several steps before falling into the region of quadratic convergence. There are other ways to fail.

  • Where the tangent is horizontal and never meets the axis; near such a point the iterate is thrown very far away.
  • For we have , so : the iteration doubles the error at each step from any starting point. The function is not differentiable at its root.
  • In the complex plane, on say, the set of starting points that lead to each of the three roots (its basin) has a fractal boundary, which makes the sensitivity to the starting point visible.

The secant method

If the derivative is unavailable or expensive, approximate it by the slope of the line through the last two iterates, . Substituting into Newton’s step gives

Geometrically, is where the line through the two latest points (a secant of the graph) crosses the axis. The method needs two starting points and then only one new value of per step.

The order of convergence. An analysis like the one above shows that the errors satisfy

To see where this comes from, note that the secant line is the linear interpolant of at and , and is its root. The interpolation error formula (see polynomial interpolation) at the point says , and , so . Near the root is close to a line of slope , and , so . Equating the two expressions for gives .

The new error is the product of the two previous errors, not the square of the last. To find the order, suppose for some power . The same relation one step earlier, , gives . Substituting this into the right side,

Both sides must be the same power of , so .

So , whose positive root is the golden ratio . The number of correct digits is multiplied by about 1.6 at each step instead of 2.

That sounds slower than Newton’s method, but the comparison should be per unit of work. If evaluating costs as much as evaluating , one Newton step costs two evaluations. Two secant steps cost the same and multiply the number of correct digits by , against 2 for Newton’s method. Measured per function evaluation, the secant method is often the faster of the two.

Algorithm

Newton’s method. Input: , its derivative , a starting point and a tolerance. Repeat at most 100 times:

  1. evaluate and ;
  2. if , return ; if is zero or not finite, report an error;
  3. compute the step and set ; if the new is not finite, report an error;
  4. if is below the tolerance, return .

If the loop ends without step 4 succeeding, report failure to converge.

The secant method. Input: , two starting points and a tolerance. Keep the two latest points with their function values. Repeat at most 100 times:

  1. compute the next point from the secant formula and evaluate ;
  2. if , return ;
  3. if is below the tolerance, accept provided the two points confirm a root between or beside them: either changes sign from to , or the secant through these two nearby points places the root within the tolerance (see the implementation notes for why a small step alone is not enough);
  4. otherwise discard the older point and continue with .

Each Newton iteration costs one evaluation of and one of ; each secant iteration costs one evaluation of .

Implementation

    for _ in 0..100 {
        let fx = f(x);
        if fx == 0.0 {
            return Ok(x);
        }
        let d = df(x);
        if d == 0.0 || !d.is_finite() {
            return Err(ErrorsJSL::RuntimeError("newton_raphson: derivative is zero or non-finite"));
        }
        let step = fx / d;
        x -= step;
        if !x.is_finite() {
            return Err(ErrorsJSL::RuntimeError("newton_raphson: iterate diverged"));
        }
        if step.abs() < tol {
            return Ok(x);
        }
    }

The secant method needs more care in deciding that it has converged:

        let mut x2 = x1 - f1 * (x1 - x0) / (f1 - f0);
        if !x2.is_finite() {
            return Err(ErrorsJSL::RuntimeError("secant_method: iterate diverged"));
        }
        let small = (x2 - x1).abs() < tol;
        if x2 == x1 {
            // A zero step gives no local slope to check it with: probe a little way off.
            let h = (0.5 * tol).max(4.0 * f64::EPSILON * x1.abs()).max(f64::MIN_POSITIVE);
            x2 = if x0 > x1 { x1 + h } else { x1 - h };
        }
        let f2 = f(x2);
        // A small step is convergence only if f changes sign across it, or the slope between these
        // two nearby points (not the secant through a distant earlier point, which can make the
        // step tiny anywhere) puts the root within `tol`.
        if f2 == 0.0 || (small && (f2.signum() != f1.signum() || (f2 * (x2 - x1)).abs() <= (tol * (f2 - f1)).abs())) {
            return Ok(x2);
        }
  • A small step usually means convergence, but not always. On from 0 and 1.3, the secant method throws an iterate out to , where is ; the secant through that point is almost vertical, and the next step is tiny, at , nowhere near a root. Returning 0.18 would be wrong, so a small step is accepted only if changes sign across it, or if the slope between the two nearby points (not the distant one) puts the root within the tolerance.
  • Newton’s method reports an error for a zero or non-finite derivative or a non-finite iterate; when it diverges, the derivative usually underflows to zero first, and that is the error reported.
  • Both give up after 100 iterations.

In practice

//! Newton's method and the secant method.
//!
//! Run with `cargo run -p lib_jsl_root_finding --example root_finding_newton`.

use lib_jsl_root_finding::{brent_method, newton_raphson, secant_method};

fn main() {
    // Kepler's equation M = E − e sin E: the eccentric anomaly E of an orbit at mean anomaly M.
    let (e, m) = (0.6, 1.2);
    let f = |x: f64| x - e * x.sin() - m;
    let df = |x: f64| 1.0 - e * x.cos();
    let newton = newton_raphson(f, df, m, 1e-15).unwrap();
    let secant = secant_method(f, m, m + 0.1, 1e-15).unwrap();
    println!("Kepler: E = {newton:.15} (Newton), {secant:.15} (secant)");

    // Newton's method needs a good start: on arctan it diverges from |x₀| > 1.39.
    let atan_derivative = |x: f64| 1.0 / (1.0 + x * x);
    println!("arctan from 1.3: {:?}", newton_raphson(f64::atan, atan_derivative, 1.3, 1e-15));
    println!("arctan from 1.5: {:?}", newton_raphson(f64::atan, atan_derivative, 1.5, 1e-15));

    // A safe combination: bracket the root, then let a bracketing method finish.
    println!("arctan by Brent on [-5, 1.5]: {:?}", brent_method(f64::atan, -5.0, 1.5, 1e-15));
}

Strengths

  • Quadratic (Newton) or superlinear (secant) convergence: a few steps from a good guess.
  • No bracket needed, so roots of even multiplicity can be found (slowly), and the methods generalise to complex roots and to systems.

Weaknesses

  • Convergence is only local: a poor guess can lead to divergence, cycling or a different root.
  • Newton’s method needs the derivative, which may be expensive or unavailable.
  • Multiple roots reduce convergence to linear.

Exercises

  1. Show that Newton’s method for is the Babylonian square-root iteration , and that for it computes without division.
  2. Find the critical starting point for : the with . Solve the equation with Brent’s method.
  3. Show that Newton’s method at a root of multiplicity has error ratio , and that the modified step with is quadratically convergent.
  4. Derive the recurrence for the secant method and show that the order of convergence is the golden ratio.
  5. Compare Newton and secant on Kepler’s equation for eccentricities starting from . Which starting guess would you use for close to 1?
Hints and answers
  1. For , . For , and : only multiplications.
  2. gives . The positive root is : Newton’s method converges for starting points with below it and diverges above it.
  3. Write with . Then near , so . With the step the linear factor cancels and the next term is quadratic in .
  4. Expand about the root: . If then , so .
  5. Kepler’s equation is . For near 1, is nearly zero near and Newton’s method from can overshoot badly. A start at is a standard safe choice.

Further reading

  • T. J. Ypma, “Historical development of the Newton-Raphson method”, SIAM Review 37 (1995) 531–551.
  • J. E. Dennis and R. B. Schnabel, Numerical Methods for Unconstrained Optimization and Nonlinear Equations, SIAM, 1996, chapter 2.
  • C. T. Kelley, Solving Nonlinear Equations with Newton’s Method, SIAM, 2003.
  • A. M. Ostrowski, Solution of Equations and Systems of Equations, Academic Press, 1960, on orders of convergence and efficiency.