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

Bracketing methods: bisection, false position, Ridders and Brent

ProblemFind a root of a continuous function in an interval over which changes sign
Devised byBisection: implicit in Bolzano’s intermediate value theorem (1817). False position: ancient (Egypt, China, India; Fibonacci 1202); the Illinois modification: Dowell and Jarratt (1971). Ridders’ method: C. J. F. Ridders (1979). Brent’s method: Theodorus Dekker (1969) and Richard Brent (1973), after van Wijngaarden and colleagues
AccuracyTo the requested tolerance, or the limit of floating point; the root always stays bracketed
CostBisection: evaluations. False position (Illinois): order 1.44 per evaluation. Ridders: order 1.41 per evaluation. Brent: order up to 1.84, never far from bisection’s worst case
Read firstPreliminaries: floating-point arithmetic
APIbracket_root, bracket_roots_scan, bisection, false_position, ridders_method, brent_method

Overview

If a continuous function is negative at and positive at , it must cross zero somewhere in between. This intermediate value theorem is the basis of the most reliable methods in numerical analysis. A bracket with and of opposite signs is a trap for a root: evaluate at a point inside, keep the half (or part) of the interval where the sign still changes, and repeat. The trap only shrinks, so the method cannot fail to converge to a point where changes sign. The theorem needs to be continuous on : a sign change can also be produced by a pole or a jump, and then the method converges just as confidently to a point that is not a root (see In practice).

The methods of this entry differ in how they choose the point inside. Bisection takes the midpoint, which is slow but has a guaranteed rate. False position and Ridders’ method use the function values to guess where the root is. Brent’s method combines fast interpolation with bisection as a safeguard, and is the method of choice for a scalar equation with a bracket.

Where it is used

Bracketing methods are the safe choice when a root must be found.

  • Engineering calculations. Finding the operating point of a pump, the pipe friction factor from the Colebrook equation, or the wavelength that satisfies a resonance condition.
  • Library functions. Brent’s method is behind brentq and many solvers inside other algorithms, such as computing quantiles of a distribution.
  • Event finding. When does a signal cross a threshold, when does a simulated trajectory hit the ground?

History

Bisection is as old as the intermediate value theorem, proved by Bernard Bolzano in 1817 (and used implicitly long before). False position (regula falsi) is one of the oldest algorithms of all: a single false position, guessing an answer and correcting it proportionally, appears in the Egyptian Rhind papyrus (about 1650 BC), and the double false position used here, interpolating linearly between two guesses, is in the Chinese Nine Chapters on the Mathematical Art (around 200 BC) and in Fibonacci’s Liber Abaci (1202). Its tendency to stall was cured by the Illinois modification, analysed by M. Dowell and P. Jarratt in 1971.

C. J. F. Ridders published his exponential variant of false position in 1979, in an electronics journal. The idea of combining a fast open method with bisection was developed by Adriaan van Wijngaarden and colleagues at the Mathematisch Centrum in Amsterdam in the 1960s and published by Theodorus Dekker in 1969; Richard Brent (1973) added inverse quadratic interpolation and a stricter safeguard, and proved a bound on the worst case. Brent’s ALGOL procedure zero became fzero in MATLAB and brentq in SciPy; this library’s version follows the zbrent of Numerical Recipes.

The idea

Finding a bracket

A bracketing method needs a sign change to start. Two simple strategies find one:

  • Expansion (bracket_root): starting from , repeatedly move the end where is smaller outward, by 1.6 times the current width, until changes sign (or 50 attempts fail).
  • Scanning (bracket_roots_scan): divide into pieces and report each piece over which changes sign.

Neither can be guaranteed: a function such as has no sign change to find, and a scan misses pairs of roots closer together than its spacing, since the two sign changes cancel. Roots of even multiplicity, where touches zero without crossing, are invisible to all bracketing methods.

Bisection

Evaluate at the midpoint . If has the same sign as , the sign change is in ; otherwise it is in . Keep that half and repeat.

Each step halves the bracket, whatever is. After steps the root lies in an interval of width . To reach a tolerance we need , that is

halvings: 44 for an interval of length 1 and , since . Counting the two evaluations at the ends of the starting bracket, that is about 46 evaluations of . The error is multiplied by at every step. This is linear convergence, one binary digit per evaluation. It is slow, but the count is known in advance and does not depend on , and it is the best possible guarantee for a method that uses only the signs of .

False position and the Illinois modification

Bisection ignores the sizes of and . If is much smaller than , the root is probably nearer to . False position (in Latin, regula falsi) uses this information: it draws the straight line through and and takes the point where the line crosses zero,

then keeps the part of the interval where the sign changes, as bisection does. If is a straight line the answer is exact in one step.

The weakness appears when is curved in one direction throughout the bracket (convex or concave). The chord of a convex function lies above its graph, so the chord’s zero always falls on the same side of the root. One end of the bracket is replaced at every step, and the other never moves. The bracket does not shrink to zero, and the estimates creep towards the root with linear convergence, sometimes extremely slowly.

The Illinois modification fixes this with one line of code. When the same end has been kept twice in a row, its stored function value is halved. This tilts the next chord so that its zero moves towards the stuck end, and usually lands on the other side of the root, which frees that end. The order of convergence becomes per evaluation.

Ridders’ method

False position is exact for straight lines and struggles with curvature. Ridders’ idea is to remove the curvature first. One step, on a bracket with function values :

  1. Evaluate at the midpoint .
  2. Find the exponential factor for which the three values of at lie on a straight line. (This is one condition on the one unknown , and it reduces to a quadratic equation for .) Multiplying by a positive factor does not move the root, so has the same root as .
  3. Apply false position to the straightened function . The result simplifies to

Where the formula comes from. Let and , so that , and . Three equally spaced values lie on a line when the middle one is the average of the outer two, . Dividing by , this is , that is , with roots , where and . On a bracket , so and exactly one root is positive: the one with . The line through the three points has slope and passes through , so it crosses zero at . In terms of , , and (use ), so . Hence . Since and have opposite signs, , which is the formula above.

  1. Evaluate and form the new bracket from and whichever neighbouring point has the opposite sign.

The formula has two reassuring properties. Since and have opposite signs, is positive, so the square root is real and larger than ; consequently the fraction is smaller than 1 in magnitude and always lies inside the bracket. Each step costs two evaluations and converges quadratically, which makes the order per evaluation. Ridders’ method is simple and robust, a good alternative to Brent’s method when a short implementation is wanted.

Brent’s method

Brent’s method aims for the best of both worlds: the speed of interpolation when the function is well behaved and the guarantee of bisection when it is not.

The points it keeps. Three points are maintained: the best estimate so far, ; the previous estimate, ; and a contrapoint at which has the opposite sign to . The root always lies between and .

The fast step. At each iteration the method proposes a new point by interpolation:

  • Inverse quadratic interpolation, when the three function values are distinct. Instead of fitting as a quadratic in (a parabola, which may cross the axis twice or not at all), it fits as a quadratic function of through the three points and evaluates that at . This always gives exactly one answer.
  • The secant step through and otherwise.

The safeguard. The proposed point is accepted only if it falls inside the bracket and the step is less than half the size of the step before last. The second condition insists that the steps keep shrinking quickly, as they would if interpolation were working. If either test fails, the method bisects instead.

Near a simple root the interpolation steps are always accepted and the order of convergence is about 1.84. On difficult functions the safeguard forces a bisection often enough that the method is never much worse than bisection. Brent proved that it needs at most about the square of bisection’s count of evaluations, and in practice it rarely needs more than a few times that count.

Comparison

The figure at the top of the chapter compares the methods on Newton’s own test equation, : the interpolating methods need 8 to 13 evaluations where bisection needs 46. On harder problems the picture is more varied (evaluations to a tolerance of ; the open methods, from the next entry, start from the ends or the midpoint of the interval, and Newton’s count includes its evaluations of ):

Table 4.3. Evaluations used by bracketing and open methods.

problembisectionfalse position (Illinois)RiddersBrentsecantNewton
on 4613138912
on 46913889
on 46171310fails45
on 4610973131101136
on 4711191111fails
  • On smooth functions with simple roots, Brent’s method is the fastest bracketing method.
  • is nearly flat at 0 and steep at 1.3: the open methods are thrown far away, and the secant method fails; plain false position takes 123 evaluations, the Illinois version 17.
  • At a triple root, , every interpolating method degrades to linear convergence, and even Brent’s method, whose safeguard bisects only every fourth step, takes almost three times as long as bisection. Bisection, which ignores the values, is unaffected.
  • is almost a step: Newton’s method from 0 is thrown out to where the function is flat, and fails, while the bracketing methods are untroubled.

Algorithm

All four methods share the same skeleton. Input: a function , an interval and a tolerance.

  1. Check the bracket. Evaluate and . If either is exactly zero, return that end. If they have the same sign, report an error.
  2. Choose a point inside the bracket by the method’s rule (below) and evaluate .
  3. Shrink the bracket. If , return . Otherwise replace the end at which has the same sign as , so that the sign change is preserved.
  4. Test. Stop when the bracket, or the last step, is smaller than the tolerance. Otherwise go to 2.

The methods differ only in step 2:

  • Bisection: the midpoint.
  • False position (Illinois): the zero of the chord through the two ends. If the same end has now survived two steps running, halve its stored function value before the next step.
  • Ridders: evaluate at the midpoint, then apply Ridders’ formula to the three points (two evaluations per iteration).
  • Brent: the inverse quadratic or secant step if it passes the two safeguards, otherwise the midpoint. Its convergence test uses the tolerance .

Bisection needs about steps whatever the function. The others give up with an error after a fixed number of iterations (500 for false position, 100 for Ridders, 200 for Brent).

Finding a bracket by expansion (bracket_root): while and have the same sign, move whichever end has the smaller outwards by 1.6 times the current width, and re-evaluate there; fail after 50 expansions.

Implementation

Bisection is short enough to show whole:

    for _ in 0..200 {
        let m = 0.5 * (a + b);
        let fm = f(m);
        if fm == 0.0 || 0.5 * (b - a).abs() < tol {
            return Ok(m);
        }
        if !same_sign(fa, fm) {
            b = m;
        } else {
            a = m;
            fa = fm;
        }
    }

The heart of Brent’s method is the choice between interpolation and bisection:

        if e.abs() >= tol1 && fa.abs() > fb.abs() {
            let s = fb / fa;
            let (mut p, mut q);
            if a == c {
                p = 2.0 * xm * s;
                q = 1.0 - s;
            } else {
                let qq = fa / fc;
                let r = fb / fc;
                p = s * (2.0 * xm * qq * (qq - r) - (b - a) * (r - 1.0));
                q = (qq - 1.0) * (r - 1.0) * (s - 1.0);
            }
            if p > 0.0 {
                q = -q;
            }
            p = p.abs();
            let min1 = 3.0 * xm * q - (tol1 * q).abs();
            let min2 = (e * q).abs();
            if 2.0 * p < min1.min(min2) {
                e = d;
                d = p / q;
            } else {
                d = xm;
                e = d;
            }
        } else {
            d = xm;
            e = d;
        }
  • The signs of are compared directly, never through the product , which underflows to zero when both values are tiny (below about ) and once sent bisection to the wrong end of its bracket.
  • Brent’s tolerance is relative as well as absolute, , so it cannot ask for more digits than floating point can give.
  • Every method also stops when is exactly zero; bisection never errs once it has a bracket, while the others give up after a fixed number of iterations (200 for Brent).
  • The functions return Result<f64, ErrorsJSL>: InvalidInputRange when there is no sign change, RuntimeError when the iteration does not converge.

In practice

//! Bracketing root finders: find every root of a function in an interval.
//!
//! Run with `cargo run -p lib_jsl_root_finding --example root_finding_bracketing`.

use lib_jsl_root_finding::{bisection, bracket_root, bracket_roots_scan, brent_method, false_position, ridders_method};

fn main() {
    // The roots of cos x · cosh x + 1 = 0 in [0, 12], which give the vibration frequencies of a
    // cantilever beam: scan for sign changes, then refine each bracket.
    let f = |x: f64| x.cos() * x.cosh() + 1.0;
    for (a, b) in bracket_roots_scan(f, 0.0, 12.0, 120) {
        let root = brent_method(f, a, b, 1e-14).unwrap();
        println!("beam mode at x = {root:.12}");
    }

    // When only a starting interval is known, expand it until it brackets a root.
    let g = |x: f64| x.exp() - 50.0;
    let (lo, hi) = bracket_root(g, 0.0, 1.0).unwrap();
    println!("bracket for eˣ = 50: [{lo:.3}, {hi:.3}]");

    // All four bracketing methods find the same root.
    for (name, r) in [
        ("bisection", bisection(g, lo, hi, 1e-13)),
        ("false position", false_position(g, lo, hi, 1e-13)),
        ("Ridders", ridders_method(g, lo, hi, 1e-13)),
        ("Brent", brent_method(g, lo, hi, 1e-13)),
    ] {
        println!("{name:>15}: {:.13} (ln 50 = {:.13})", r.unwrap(), 50f64.ln());
    }
}

Strengths

  • Guaranteed convergence once a bracket is known, with no derivative needed.
  • Brent’s method is nearly as fast as the open methods on smooth functions.
  • Bisection’s cost is known in advance and independent of .

A sign change is not always a root. The guarantee is about the sign, and the sign can change without passing through zero. Bisection on over starts with and and converges, in the usual number of steps, to , where is unbounded. The returned point has a tiny bracket but an enormous residual. Two habits protect against this: check (it should be small compared with at the ends of the original bracket), and know whether your function is continuous on the bracket. The opposite failure is also real: a bracket exists only where the sign changes, so a double root such as never has one, and an interval holding two roots has the same signs at both ends.

Weaknesses

  • A bracket is needed, and finding one is not always easy.
  • Roots of even multiplicity (no sign change) cannot be found, and roots of odd multiplicity are found slowly by the interpolating methods.
  • They apply only to one equation in one unknown.

Exercises

  1. How many bisection steps are needed to locate a root in to the full precision of double precision arithmetic? Why does it not help to ask for more?
  2. Show that plain false position on over keeps the end fixed for ever, and find its rate of convergence.
  3. Derive Ridders’ formula: find such that takes values on a straight line at , and , and apply false position to it.
  4. Write down the inverse quadratic interpolation formula through three points and show that it is exact when is a quadratic function of .
  5. Use bracket_roots_scan and brent_method to find all the roots of in . How fine must the scan be to find them all?
  6. What does bisection return for on ? Is the result a root? What does the residual tell you?
Hints and answers
  1. About 53 halvings for a root near 1: the bracket cannot become narrower than the spacing of doubles, which is about . Beyond that, the midpoint of two adjacent doubles is one of them and the bracket stops shrinking. (A root near 0 has finer spacing and needs more steps.)
  2. is convex and increasing, so the chord from to always crosses zero to the left of the root: is replaced and never moves. With fixed, the error ratio tends to : linear convergence.
  3. Put and require the three values at the equally spaced points to be collinear, . With this is , so . False position on then gives .
  4. Regard as a function of and interpolate it through with Lagrange’s formula; evaluate at : . If is exactly quadratic in , the interpolant is itself.
  5. The zeros are , and lie in (, ). The two closest, and , are apart, so the scan step must be smaller than that: at least about 90 subintervals.
  6. It converges to , where is unbounded, because changes sign there. The result is not a root: the residual is of the order of , enormous rather than small.

Further reading

  • R. P. Brent, Algorithms for Minimization without Derivatives, Prentice-Hall, 1973 (Dover reprint, 2002), chapter 4.
  • T. J. Dekker, “Finding a zero by means of successive linear interpolation”, in Constructive Aspects of the Fundamental Theorem of Algebra, Wiley, 1969.
  • M. Dowell and P. Jarratt, “A modified regula falsi method for computing the root of an equation”, BIT 11 (1971) 168–174.
  • C. J. F. Ridders, “A new algorithm for computing a single root of a real continuous function”, IEEE Transactions on Circuits and Systems 26 (1979) 979–980.
  • W. H. Press, S. A. Teukolsky, W. T. Vetterling and B. P. Flannery, Numerical Recipes, 3rd ed., Cambridge University Press, 2007, §9.1–9.3.