MATH-300 · Lesson 2 of 5 · 31 min
Root finding
Engineering is full of equations that cannot be solved with algebra. The friction factor in a pipe appears on both sides of the Colebrook equation. The depth at which a float settles satisfies a cubic. The natural frequencies of a beam satisfy cos βL cosh βL = −1. The interest rate that makes a project break even satisfies a polynomial of high degree. Each is a root-finding problem: find x such that f(x) = 0.
ENCM-100 introduced bisection as a programming exercise. This chapter treats root finding properly: bracketing and open methods, how fast they converge, when they fail, and how professional library routines combine them.
Setting up the problem
Any equation can be rearranged as f(x) = 0. Before reaching for a method, sketch or plot f: it shows how many roots there are, roughly where, and whether anything odd (a discontinuity, a near-double root) is lurking. A good starting guess, from a plot, a simplified model or engineering judgment, is half the battle.
Worked problem
A floating ball
A wooden ball of radius 5.5 cm and specific gravity 0.6 floats in water. Archimedes' principle gives the depth x (in m) to which it sinks as the root of \(f(x) = x^3 - 0.165x^2 + 3.993 \times 10^{-4} = 0\). Where is the physically meaningful root?
Show solution
- The depth must lie between 0 and the diameter, 0.11 m.
- \(f(0) = 3.993 \times 10^{-4} > 0\) and \(f(0.11) = -2.66 \times 10^{-4} < 0\), so a root lies in [0, 0.11].
- A plot shows exactly one root there, near 0.06 m. (The cubic's other two roots, one negative and one greater than 0.11, are not physical.)
Answer: One root in [0, 0.11], near 0.06 m. Bracketing it first guarantees the methods below find the right one
Bracketing methods
Bisection
If f is continuous and f(a) and f(b) have opposite signs, the intermediate value theorem (MATH-100) guarantees a root in [a, b]. Bisection evaluates the midpoint m = (a + b)/2, keeps the half where the sign changes, and repeats. Each step halves the bracket, so after n steps the error is at most \((b - a)/2^{n+1}\), and the number of steps for a tolerance ε is
Worked problem
Bisection on the floating ball
Apply bisection to the floating ball on [0, 0.11]. How many iterations guarantee an error below \(10^{-6}\) m?
Show solution
- m = 0.055: f = +6.65 × 10⁻⁵ > 0, so the root is in [0.055, 0.11].
- m = 0.0825: f < 0, so [0.055, 0.0825]. m = 0.06875: f < 0, so [0.055, 0.06875].
- m = 0.061875: f > 0, so [0.061875, 0.06875]. The bracket keeps halving toward 0.06238.
- Iterations needed: \(\log_2(0.11/10^{-6}) = 16.7\), so 17.
Answer: The root is 0.06238 m (6.24 cm). Bisection needs 17 steps for micrometer accuracy, but it is guaranteed to get there
Bisection is slow (one binary digit per step, about 3.3 steps per decimal digit) but bulletproof: it cannot diverge. The false position (regula falsi) method replaces the midpoint by the point where the straight line through (a, f(a)) and (b, f(b)) crosses zero. It is often faster, but can stall with one end of the bracket stuck.
Open methods
Open methods start from one or two guesses that need not bracket the root. They are usually much faster, but they can diverge.
Fixed-point iteration
Rearrange f(x) = 0 as x = g(x) and iterate \(x_{k+1} = g(x_k)\). Near the root r, the error is multiplied by about \(g'(r)\) at each step, so the iteration converges if \(|g'(r)| < 1\), and faster the smaller \(|g'(r)|\) is. The same equation can be rearranged in ways that converge or diverge.
Worked problem
Friction factor from the Colebrook equation
For turbulent flow in a pipe, the Darcy friction factor f satisfies the Colebrook equation \(\dfrac{1}{\sqrt{f}} = -2\log_{10}\left(\dfrac{\varepsilon/D}{3.7} + \dfrac{2.51}{Re\sqrt{f}}\right)\). Find f for Re = 10⁵ and relative roughness ε/D = 0.0002.
Show solution
- Let \(u = 1/\sqrt{f}\) and iterate \(u_{k+1} = -2\log_{10}(0.0002/3.7 + 2.51u_k/10^5)\), starting from f = 0.02 (u₀ = 7.071).
- u₁ = 7.2708 (f = 0.018917); u₂ = 7.2522 (f = 0.019014); u₃ = 7.2539 (f = 0.019005); u₄ = 7.25371 (f = 0.0190055).
- The error shrinks by about 0.09 each step, matching \(|g'(u)| = 0.092\) at the root.
Answer: f = 0.01901 after four iterations. The explicit Haaland approximation gives 0.01874, about 1.4% low, which is often good enough; the iteration gives the Colebrook value itself
Newton's method
Newton's method (MATH-100) follows the tangent line at the current guess to where it crosses zero:
Near a simple root, Newton converges quadratically: the error is roughly squared at each step, \(e_{k+1} \approx C e_k^2\), so the number of correct digits roughly doubles each iteration.
Worked problem
Newton on the floating ball
Apply Newton's method to the floating ball from x₀ = 0.05 with \(f'(x) = 3x^2 - 0.33x\).
Show solution
- x₁ = 0.0624222, error \(4.5 \times 10^{-5}\).
- x₂ = 0.06237758, error \(5.0 \times 10^{-9}\).
- x₃ = 0.0623775815137, error at the level of machine precision.
Answer: Full double precision in three steps, against 17 bisection steps for just six decimals. The errors 10⁻⁵, 10⁻⁹, 10⁻¹⁷ show the squaring
Newton's method for √a, applied to \(x^2 - a = 0\), gives \(x_{k+1} = \frac{1}{2}(x_k + a/x_k)\), the method of the ancient Babylonians. From x₀ = 1, the errors in √2 are 0.086, 0.0025, 2.1 × 10⁻⁶, 1.6 × 10⁻¹² and then machine precision.
When Newton fails
Newton's method needs a derivative and a reasonable starting point. It can fail in several ways:
- A zero or tiny derivative sends the next guess far away (a horizontal tangent never meets the axis).
- From a poor start it can diverge or cycle. For \(f(x) = \tan^{-1}x\), starting from x₀ = 1.3 converges to 0, but from 1.5 the guesses go −1.69, 2.32, −5.11, 32.3, −1575: each overshoot is worse.
- At a multiple root (where f' is also zero, as in \((x - 1)^2\)), convergence slows to linear.
The secant method
When f' is unavailable or expensive, replace it with the slope through the last two points:
The secant method needs two starting values but only one new function evaluation per step. Its order of convergence is the golden ratio, about 1.618: slower than Newton per step, but often faster per unit of work. On the floating ball from 0.02 and 0.05, its errors are 2.2 × 10⁻³, 3.7 × 10⁻⁵, 2.3 × 10⁻⁷, 2.1 × 10⁻¹¹ and then machine precision.
Comparing convergence
If the error satisfies \(|e_{k+1}| \approx C|e_k|^p\), p is the order of convergence. Bisection is linear (p = 1, C = 1/2), fixed-point iteration is linear with C = |g'(r)|, the secant method has p ≈ 1.618 and Newton p = 2.
Professional solvers combine the strengths. Brent's method (scipy.optimize.brentq, MATLAB fzero) keeps a bracket, so it cannot fail, but takes secant or inverse-quadratic steps when they behave well and falls back to bisection when they do not. If you can bracket the root, this is the method to use.
Systems of nonlinear equations
Newton's method extends to n equations in n unknowns, \(\mathbf{F}(\mathbf{x}) = \mathbf{0}\). The derivative becomes the Jacobian matrix J of partial derivatives (MATH-209), and each step solves a linear system (Lesson 3):
This is how circuit simulators solve nonlinear circuits, how structural programs handle large deflections and how process simulators converge flowsheets. Convergence is again quadratic near the solution, and again a good starting guess matters.
Worked problem
Two curves
Find the intersections of the circle \(x^2 + y^2 = 4\) and the curve \(y = 1 - e^x\).
Show solution
- Write \(F_1 = x^2 + y^2 - 4\), \(F_2 = e^x + y - 1\). Jacobian: \(J = \begin{pmatrix} 2x & 2y \\ e^x & 1 \end{pmatrix}\).
- A sketch shows two intersections, one near (1, −1.7) and one near (−1.8, 0.8). Start Newton at each.
Answer: (1.0042, −1.7296) and (−1.8163, 0.8374). Different starting points converge to different roots, which is why the sketch comes first
from scipy.optimize import brentq, newton, fsolve
import numpy as np
f = lambda x: x**3 - 0.165*x**2 + 3.993e-4
print("ball depth (Brent):", brentq(f, 0, 0.11))
print("ball depth (Newton):", newton(f, 0.05, fprime=lambda x: 3*x**2 - 0.33*x))
def colebrook(u, rel=0.0002, Re=1e5):
return u + 2*np.log10(rel/3.7 + 2.51*u/Re)
u = brentq(colebrook, 1, 20)
print(f"friction factor f = {1/u**2:.5f}")
F = lambda v: [v[0]**2 + v[1]**2 - 4, np.exp(v[0]) + v[1] - 1]
print("intersection:", fsolve(F, [1, -1]))Output: ball depth 0.0623775815… m by both methods; friction factor f = 0.01901; intersection [1.00416874 −1.72963729].
Common mistakes
MistakeStarting an open method without knowing roughly where the root is.
InsteadPlot f first, bracket the root, and use a sensible starting guess.
MistakeAccepting a root without checking it is physical.
InsteadCheck the answer against the problem: a depth must lie between 0 and the diameter.
MistakeLetting an iteration run without a limit.
InsteadAlways set a maximum number of iterations and report failure.
MistakeUsing bisection when f does not change sign.
InsteadA double root (touching the axis) cannot be bracketed; use Newton or minimize |f|.
MistakeRearranging into x = g(x) without checking |g′| < 1.
InsteadFixed-point iteration converges only if |g′(r)| < 1; try another rearrangement.
MistakeWriting your own solver for production work.
InsteadUse a robust library routine such as brentq, and understand what it does.
Summary and key terms
- Write the problem as f(x) = 0, plot f, and bracket the root before choosing a method.
- Bisection halves the bracket each step: guaranteed but linear, needing log₂((b − a)/ε) steps.
- Fixed-point iteration x = g(x) converges linearly if |g′(r)| < 1.
- Newton's method x − f/f′ converges quadratically near a simple root but can diverge from poor starting points or at zero slopes.
- The secant method replaces f′ with a difference quotient and converges with order about 1.618.
- Brent's method combines bracketing safety with fast steps; Newton's method with the Jacobian solves nonlinear systems.
- Root
- A value x where f(x) = 0.
- Bracket
- An interval [a, b] where f changes sign, so it contains a root.
- Bisection
- Repeatedly halving a bracket, keeping the half with the sign change.
- Fixed-point iteration
- Iterating x = g(x) from a starting value.
- Newton's method
- Iterating x − f(x)/f′(x), following tangent lines.
- Secant method
- Newton's method with the derivative replaced by the slope through two recent points.
- Order of convergence
- The exponent p in |e_{k+1}| ≈ C|e_k|^p.
- Quadratic convergence
- Convergence of order 2: correct digits roughly double each step.
- Brent's method
- A hybrid bracketing method combining bisection, secant and inverse quadratic steps.
- Jacobian
- The matrix of partial derivatives of a vector function, used in Newton's method for systems.
- Multiple root
- A root where f′ is also zero, slowing Newton's convergence.
- Stopping criterion
- The test that decides when an iteration is accurate enough.
Practice problems
Work each problem on paper first, then reveal the answer to check.
How many bisection steps are needed to find a root in [1, 2] to within 10⁻⁸?
Show answer
log₂(1/10⁻⁸) = 26.6 → 27.
Do two bisection steps for f(x) = x³ − x − 2 on [1, 2].
Show answer
m = 1.5: f = −0.125 < 0 → [1.5, 2]; m = 1.75: f = 1.609 > 0 → [1.5, 1.75].
Write Newton's iteration for f(x) = x³ − x − 2 and take one step from x₀ = 1.5.
Show answer
x₁ = 1.5 − (−0.125)/(3(2.25) − 1) = 1.5 + 0.125/5.75 = 1.5217.
Write Newton's iteration for computing the cube root of 10.
Show answer
f = x³ − 10: x_{k+1} = x_k − (x_k³ − 10)/(3x_k²) = (2x_k + 10/x_k²)/3.
For x = cos x, does fixed-point iteration x_{k+1} = cos x_k converge? (The root is 0.739.)
Show answer
g′ = −sin x; |g′(0.739)| = 0.674 < 1: yes, linearly, each error multiplied by about 0.67.
The equation x² − 2x − 3 = 0 is rearranged as x = (x² − 3)/2. Will iteration converge to the root x = 3?
Show answer
g′ = x; g′(3) = 3 > 1: no, it diverges from that root.
Take one secant step for f(x) = x² − 5 with x₀ = 2, x₁ = 3.
Show answer
x₂ = 3 − 4(3 − 2)/(4 − (−1)) = 3 − 0.8 = 2.2.
Errors in an iteration are 10⁻², 10⁻⁴, 10⁻⁸. What is the order of convergence?
Show answer
Each error is the square of the previous one: order 2 (quadratic).
Why does Newton's method converge slowly for f(x) = (x − 2)²?
Show answer
x = 2 is a double root where f′ = 0 too; Newton becomes linear, halving the error each step.
Write the Jacobian for F₁ = x² − y, F₂ = x + y² − 3.
Show answer
J = [[2x, −1], [1, 2y]].
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.