Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Part 1: Root Finding

Numerical Methods Module 2 | COMP 521

Learning Objectives

By the end of this section, you will be able to:


The Fundamental Problem

Root/Zero: A value x∗x^* where f(x∗)=0f(x^*) = 0. The x-intercept of the function. In physics, often represents equilibrium points.

Transcendental equation: An equation involving transcendental functions such as sine, exponential, or logarithm. Many require numerical solution, but some have explicit solutions: ex=2e^x=2 gives x=ln⁡2x=\ln 2.

In physics, equilibrium occurs where the net force vanishes, where a differentiable potential energy is stationary, or where competing effects balance. Mathematically, these all reduce to finding roots of equations: solving f(x)=0f(x) = 0.

Many equations in computational physics have no closed-form solution. For example, a stellar model must satisfy hydrostatic equilibrium:

dPdr=−GM(r)ρ(r)r2\frac{dP}{dr} = -\frac{GM(r)\rho(r)}{r^2}

This is a differential equation, not itself a scalar root equation. Once we discretize a stellar model or impose a boundary condition, root finding can determine an unknown central value, radius, or model parameter. We need to distinguish solving the ODE from solving that resulting residual equation.

Root sensitivity: For a simple scalar root rr, 1/∣f′(r)∣1/|f'(r)| describes the sensitivity to an additive perturbation in the function value. Its numerical meaning depends on the chosen units and on the error model.

Building Intuition: The Geometry of Root Finding

Before diving into algorithms, let’s understand the geometry. Finding roots is about locating zeros; a curve can cross the x-axis or touch it without crossing. Different methods use different geometric insights:

Bracketing: Maintaining an interval whose endpoint values have opposite signs. If the function is continuous on that interval, the Intermediate Value Theorem guarantees at least one root inside.

Interpolation: Approximating a function between known points using simpler functions (lines, parabolas, etc.).

  1. Bracketing methods (bisection) maintain an interval with a sign change.

  2. Local methods (Newton) use a tangent-line model near an iterate.

  3. Interpolation methods (secant) replace the analytic derivative with a slope from two evaluations.

Each approach has trade-offs between:

Root-finding geometry for $f(x)=x^3-2x-5$

Figure 1:Root-finding geometry for f(x)=x3−2x−5f(x)=x^3-2x-5. Bisection starts on [1.5,2.5][1.5,2.5], Newton at 2.3, and secant with 1.5 and 2.3. The first three iterates show how each method obtains its next position. The fourth panel compares errors against a reference bracketed in 70-digit decimal arithmetic, then rounded to binary64. The horizontal axis counts function and derivative calls separately, with one unit for each; these calls need not have equal runtime. Bracket half-width tolerance is 10-10 and the cap is 40 iterations. Zero computed residuals and floating-point stagnation end a run. Zero plotted errors are omitted, not replaced by an invented floor.

Open full-size figure


Method 1: Bisection

The Mathematical Foundation

Intermediate Value Theorem: If ff is continuous on [a,b][a,b] and kk is any value between f(a)f(a) and f(b)f(b), then there exists at least one c∈[a,b]c \in [a,b] where f(c)=kf(c) = k. Strictly intermediate values occur in the open interval.

The bisection method is based on the Intermediate Value Theorem:

If ff is continuous on [a,b][a,b] and f(a)⋅f(b)<0f(a) \cdot f(b) < 0, then there exists at least one root r∈(a,b)r \in (a,b) where f(r)=0f(r) = 0.

The algorithm repeatedly halves the interval, keeping the half that contains the root.

Algorithm Analysis

Starting with interval [a0,b0][a_0, b_0] where f(a0)⋅f(b0)<0f(a_0) \cdot f(b_0) < 0:

  1. Compute midpoint: cn=an+bn2c_n = \frac{a_n + b_n}{2}

  2. Evaluate f(cn)f(c_n)

  3. Update interval:

    • If f(cn)=0f(c_n)=0: return the sampled zero; otherwise stop only when the half-width meets the requested position tolerance

    • If f(an)⋅f(cn)<0f(a_n) \cdot f(c_n) < 0: root in [an,cn][a_n, c_n], so set bn+1=cnb_{n+1} = c_n, an+1=ana_{n+1} = a_n

    • Otherwise: root in [cn,bn][c_n, b_n], so set an+1=cna_{n+1} = c_n, bn+1=bnb_{n+1} = b_n

After nn iterations, the interval width is:

∣bn−an∣=∣b0−a0∣2n|b_n - a_n| = \frac{|b_0 - a_0|}{2^n}

Linear convergence of the bound: Bisection halves its bracket half-width at each update. Its actual midpoint error need not decrease by exactly one half, or even decrease at every update.

The error in our approximation is bounded by half the interval width:

∣cn−r∣≤∣bn−an∣2=∣b0−a0∣2n+1|c_n - r| \leq \frac{|b_n - a_n|}{2} = \frac{|b_0 - a_0|}{2^{n+1}}

This is linear convergence with rate 12\frac{1}{2}.

Iterations Required

To achieve error <ϵ< \epsilon, we need:

∣b0−a0∣2n+1<ϵ\frac{|b_0 - a_0|}{2^{n+1}} < \epsilon

Solving for nn:

n>log⁡2(∣b0−a0∣ϵ)−1n > \log_2\left(\frac{|b_0 - a_0|}{\epsilon}\right) - 1

For example, to find a root in [0,1][0, 1] to 10 decimal places (ϵ=10−10\epsilon = 10^{-10}):

n>log⁡2(1010)−1≈33.2−1=32.2n > \log_2(10^{10}) - 1 \approx 33.2 - 1 = 32.2

So 33 interval halvings suffice, followed by the new midpoint, provided continuity and reliable function signs hold. Count midpoint evaluations separately from interval updates.

Implementation

This reading uses a compact reference interface to illustrate bracket reduction. It differs from the Project 3 contract:

Reading exampleProject 3
bisection(..., tol=...) returns one scalarbisect(..., atol=..., rtol=...) returns (root, n_iter, history)
An exact sampled root may be passed as (x, x)Require a < b; retain exact sampled roots separately
Absolute position tolerance onlyAbsolute plus relative position allowance

Use the project brief for submitted interfaces, history recording, and failure behavior. The example below is a reading reference, not a replacement module.

An exactly zero computed function value is accepted here. If evaluating the function can underflow to zero or produce unreliable signs, the bracket is no longer certified by these values. Rescale the evaluation or use higher precision; changing the stopping criterion cannot repair the function evaluation.

Predict → Run → Explain: small residual or well-located root?

Multiplying a function by a positive constant does not move its root. Predict whether the same position tolerance should give the same answer for both rows.

scale=1e+00: root=0.899999999965, position error=3.492e-11, residual=3.492e-11
scale=1e-12: root=0.899999999965, position error=3.492e-11, residual=3.492e-23
scale=1e-200: root=0.899999999965, position error=3.492e-11, residual=3.492e-211

The position errors agree although the residuals differ by many orders of magnitude. Near a simple root, f(x)≈f′(r)(x−r)f(x)\approx f'(r)(x-r): a residual measures position error only after accounting for the slope and the function’s units. If ∣f′∣≥m>0|f'|\ge m>0 on the relevant interval, the mean value theorem gives ∣x−r∣≤∣f(x)∣/m|x-r|\le |f(x)|/m. A bracket gives a position bound without estimating that slope.

Rescaling a linear function changes its residual while the bisection half-width is unchanged.

Both functions have root 0.9 and use the same sequence of brackets. Residual size depends on the vertical scale; bracket width measures uncertainty in x.

Open full-size figure

Common Failure Modes and Fixes

ProblemSymptomSolution
No sign changeWon’t startScan interval for brackets first
Multiple rootsFinds arbitrary oneUse smaller initial intervals
DiscontinuityFalse bracketCheck continuity requirement
ff touches zeroNo sign changeBisection cannot certify this root; use a method with different assumptions or bracket a related sign-changing quantity

Method 2: Newton-Raphson — using a local slope

The Geometric Insight

Tangent line approximation: Replacing a curve with its tangent line at a point, valid for small deviations.

Newton’s method uses calculus to accelerate convergence. The key insight: near any point, a smooth function looks approximately linear. We follow the tangent line to where it crosses the axis. Sufficiently near a simple root, under suitable smoothness conditions, this can provide a much more accurate estimate. A tangent step from an arbitrary starting point need not improve the estimate.

Mathematical Derivation

Starting at point xnx_n, the tangent line to f(x)f(x) has equation:

y−f(xn)=f′(xn)(x−xn)y - f(x_n) = f'(x_n)(x - x_n)

This line crosses the x-axis (where y=0y = 0) at:

0−f(xn)=f′(xn)(xn+1−xn)0 - f(x_n) = f'(x_n)(x_{n+1} - x_n)

Solving for xn+1x_{n+1}:

xn+1=xn−f(xn)f′(xn)\boxed{x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}}

This is the Newton-Raphson iteration formula.

Convergence Analysis

To understand the convergence rate, we analyze the error en=xn−re_n = x_n - r where rr is the true root.

Using Taylor series around rr:

f(xn)=f(r)+f′(r)(xn−r)+f′′(r)2(xn−r)2+O((xn−r)3)f(x_n) = f(r) + f'(r)(x_n - r) + \frac{f''(r)}{2}(x_n - r)^2 + O((x_n - r)^3)

Since f(r)=0f(r) = 0:

f(xn)=f′(r)en+f′′(r)2en2+O(en3)f(x_n) = f'(r)e_n + \frac{f''(r)}{2}e_n^2 + O(e_n^3)

Similarly:

f′(xn)=f′(r)+f′′(r)en+O(en2)f'(x_n) = f'(r) + f''(r)e_n + O(e_n^2)

Through algebraic manipulation of the Newton iteration formula:

en+1=f′′(r)2f′(r)en2+O(en3)e_{n+1} = \frac{f''(r)}{2f'(r)}e_n^2 + O(e_n^3)

Quadratic convergence: Error is squared each iteration, doubling the number of correct digits.

For a sufficiently smooth function, a simple root with f′(r)≠0f'(r)\ne0, and a sufficiently close initial guess, this shows quadratic convergence! The error is squared each iteration, meaning the number of correct digits approximately doubles.

When Newton Fails

The tangent model can fail for several distinct reasons:

  1. Zero derivative away from a root: If f′(xn)=0f'(x_n)=0 and f(xn)≠0f(x_n)\ne0, the horizontal tangent has no zero

  2. Poor initial guess: May diverge or converge to wrong root

  3. Cycles: Can oscillate between points without converging

  4. Sensitive root: A small ∣f′(r)∣|f'(r)| amplifies a given absolute function error; interpret that error together with units and function scaling

Four panels show Newton cycling, divergence from a poor guess, a non-differentiable cube-root zero, and linear convergence at a repeated root.

Figure 3:Four directly computed Newton histories isolate different mechanisms. For x3−2x+2x^3-2x+2, the initial value 0 cycles exactly between 0 and 1. For arctan⁡x\arctan x, starting at 2 gives rapidly growing iterate magnitudes. For the real cube root, every nonzero iterate obeys xk+1=−2xkx_{k+1}=-2x_k; the derivative is undefined at the root, and starting nearby does not help. For (x−1)2(x-1)^2, Newton halves the position error rather than squaring it. These are separate failure or convergence mechanisms; a small derivative at an arbitrary iterate is not the same thing as a sensitive root.

Open full-size figure

Common Failure Modes and Fixes

ProblemSymptomSolution
f’(x) ≈\approx 0Division by small numberUse bisection if a valid sign-changing bracket is available
Bad initial guessDivergenceFind and verify a sign-changing bracket, then use bisection
OscillationRepeating valuesDetect cycles, switch methods
Repeated rootSlow convergenceUse modified Newton: xn+1=xn−mf(xn)f′(xn)x_{n+1} = x_n - m\frac{f(x_n)}{f'(x_n)}

Method 3: Secant - The Practical Compromise

Motivation: No Derivatives Required

Finite difference approximation: Estimating derivatives using function values at nearby points.

Newton’s method requires f′(x)f'(x), but what if:

The secant method approximates the derivative using a finite difference:

f′(xn)≈f(xn)−f(xn−1)xn−xn−1f'(x_n) \approx \frac{f(x_n) - f(x_{n-1})}{x_n - x_{n-1}}

The Iteration Formula

Substituting this approximation into Newton’s formula:

xn+1=xn−f(xn)⋅xn−xn−1f(xn)−f(xn−1)\boxed{x_{n+1} = x_n - f(x_n) \cdot \frac{x_n - x_{n-1}}{f(x_n) - f(x_{n-1})}}

Geometrically, we’re replacing the tangent line with a secant line through two points.

Convergence Analysis

For a sufficiently smooth function with a simple root and sufficiently close starting points, the convergence of the secant method is more complex. Through detailed analysis (involving difference equations), one can show that the order of convergence is:

ϕ=1+52≈1.618\phi = \frac{1 + \sqrt{5}}{2} \approx 1.618

This is the golden ratio! The error satisfies:

∣en+1∣≈C∣en∣1.618|e_{n+1}| \approx C|e_n|^{1.618}

Superlinear convergence: ∣ek+1∣/∣ek∣→0|e_{k+1}|/|e_k|\to0 as the root is approached. Quadratic convergence is also superlinear; secant convergence is specifically superlinear and subquadratic.

This superlinear convergence is slower than Newton’s quadratic rate but faster than bisection’s linear rate.

Where the golden ratio comes from

The secant slope contains information from two previous errors. Expanding f(r+e)=ae+be2+O(e3)f(r+e)=a e+b e^2+O(e^3), with a=f′(r)≠0a=f'(r)\ne0 and b=f′′(r)/2b=f''(r)/2, gives

f(xk)−f(xk−1)xk−xk−1=a+b(ek+ek−1)+⋯ .\frac{f(x_k)-f(x_{k-1})}{x_k-x_{k-1}} =a+b(e_k+e_{k-1})+\cdots.

Substituting in the secant update and cancelling the leading linear term gives

ek+1≈baekek−1.e_{k+1}\approx\frac{b}{a}e_k e_{k-1}.

Suppose this nonzero leading term controls the iteration and the errors obey ∣ek∣∼K∣ek−1∣p|e_k|\sim K|e_{k-1}|^p. Then ∣ek−1∣|e_{k-1}| scales like ∣ek∣1/p|e_k|^{1/p}, so

∣ek+1∣∝∣ek∣1+1/p,p=1+1/p.|e_{k+1}|\propto |e_k|^{1+1/p},\qquad p=1+1/p.

Thus p2−p−1=0p^2-p-1=0, and the positive root is (1+5)/2(1+\sqrt5)/2. The result comes from reusing two iterates, not from a universal empirical ranking of solvers. If the leading coefficient vanishes, the root is repeated, or rounding dominates, this particular asymptotic calculation does not describe the measured sequence.

Comparison of Convergence Rates

MethodOrderError ReductionDigits Gained/IterationFunction Evals
Bisection1.0 (bound)Half-width halves; actual error need notAbout 0.30 in the bound1
Secant1.618∣en+1∣≈C∣en∣1.618\lvert e_{n+1}\rvert \approx C\lvert e_n\rvert^{1.618}Correct-digit count grows by roughly 1.6181 new, after initialization
Newton2.0en+1≈Cen2e_{n+1} \approx Ce_n^2Doubles2 (f and f’)

The bracket bound can contract even when successive midpoint errors do not. The computed example below uses f(x)=x2−2f(x)=x^2-2; it compares actual errors with the bisection bound, not with residuals or update sizes.

Log plot for the root of x squared minus two. Bisection midpoint errors sometimes rise, while the dashed bracket-error bound halves each iteration; Newton errors fall rapidly until zero errors are omitted from the log axis.

The measured midpoint error can rise while its guaranteed bracket bound falls. Zero error cannot be displayed on a logarithmic axis.

Open full-size figure

There is no universal absolute cutoff for a “small” secant denominator: multiplying the equation by a constant scales that denominator while leaving the exact secant step unchanged. Compare evaluation uncertainty with the local function-value scale and inspect the proposed step. If function error dominates the difference, report an unreliable slope or use a justified safeguard. Project 3 requires explicit handling of zero denominators and nonfinite values; it does not prescribe an extra arbitrary near-zero threshold.

Common Failure Modes and Fixes

ProblemSymptomSolution
f(x₀) ≈\approx f(x_{1})Near-zero denominatorReport an unusable slope; restart with justified points or use a bracketed safeguard
Parallel secantsNo convergenceRestart with different points
Leaves bracketMay miss rootUse a bracket-preserving hybrid; Brent is one specific algorithm, not any secant/bisection combination

Backtracking: choose how far to follow Newton

Newton proposes a direction p=−f(x)/f′(x)p=-f(x)/f'(x). A line search chooses a step length α\alpha along that direction:

xtrial=x+αp,0<α≤1.x_{\rm trial}=x+\alpha p,\qquad 0<\alpha\le1.

The full Newton step uses α=1\alpha=1. Backtracking starts there and shortens the step when it fails an acceptance test. This controls a local proposal; it does not preserve a root bracket or select a physically meaningful root.

Arctangent curve at x equals two with a tangent whose zero is near minus 3.536, far beyond the true root at zero.

Newton finds the zero of a local tangent. That proposal still needs an actual function evaluation before it can be accepted.

Open full-size figure

Define progress before testing a step

For a scalar equation, use the merit function ϕ(x)=12f(x)2\phi(x)=\tfrac12 f(x)^2. With a differentiable ff and finite nonzero f′(x)f'(x), an exact Newton direction satisfies

ϕ′(x)p=f(x)f′(x)(−f(x)f′(x))=−f(x)2<0\phi'(x)p=f(x)f'(x)\left(-\frac{f(x)}{f'(x)}\right)=-f(x)^2<0

at a nonroot. It is a descent direction locally, although a full step can increase the merit function. The Armijo sufficient-decrease test is

ϕ(x+αp)≤ϕ(x)+cαϕ′(x)p=ϕ(x)−cαf(x)2.\phi(x+\alpha p)\le\phi(x)+c\alpha\phi'(x)p =\phi(x)-c\alpha f(x)^2.

Choose 0<c<1/20<c<1/2 here; the example uses c=10−4c=10^{-4} and halves α\alpha after each rejection. These are illustrative algorithm settings, not accuracy tolerances. Under the differentiability and descent assumptions, sufficiently small positive steps satisfy this test in exact arithmetic. A finite search budget, floating-point stagnation, or unreliable evaluations can still prevent an implementation from accepting a step.

Predict, compare, explain: one accepted step

For f(x)=arctan⁡xf(x)=\arctan x, start at x=2x=2. Predict whether the full Newton step reduces ∣f∣|f|, then compare these candidate trials (including an extra quarter-step for comparison). This is one step, not a complete solve.

Step fraction α\alphaTrial x+αpx+\alpha pResidual magnitudeArmijo test
1-3.5357441.295169Reject
1/21/2-0.7678720.654841Accept
1/41/40.6160640.552148Accept
Merit function along the Newton direction from x equals two. The full step fails the sufficient-decrease line; the half-step passes it, so backtracking accepts that first passing trial.

The acceptance test compares the actual merit value with the sufficient-decrease threshold. The quarter-step is shown only to compare candidates; an ordinary backtracking search would stop at the accepted half-step.

Open full-size figure

Backtracking accepts the first passing trial, not necessarily the best point on the line. Explain why an accepted step neither identifies a root nor preserves a bracket. No line-search implementation is assigned.

The full step reaches approximately −3.536 and increases the residual magnitude. One halving reaches approximately −0.768 and satisfies sufficient decrease. This is progress, not a converged root. A complete solver still needs an outer iteration budget, stopping rules, diagnostics, and a physical-domain check. Domain-restricted functions also need an explicit feasible-trial policy; this example does not turn arbitrary domain errors into successful steps.

Three different ways to control a proposal

ApproachWhat it controlsWhat it does not establish by itself
Backtracking line searchDistance along a direction, using sufficient decreaseA root-error bound, a bracket, or the physical root
Bracket-preserving hybridProposed steps plus reliable bracket reductionContinuity or correctness of supplied function signs
Levenberg regularizationThe linear system that defines the directionA zero residual or a globally successful solve

FNC’s quasi-Newton chapter develops Levenberg’s method for nonlinear systems: regularization changes the proposed step, and residual reduction governs acceptance. It is related to step control but is not the scalar backtracking algorithm above. For a production Newton/line-search interface, see PETSc. Levenberg’s method is a preview for later nonlinear least squares, not another algorithm to implement this week.

Jacobians and local fitting · Week 5 companion

For observations yiy_i and a model g(ti;θ)g(t_i;\theta), define residuals ri=g(ti;θ)−yir_i=g(t_i;\theta)-y_i. With mm observations and nn parameters, the Jacobian JJ has shape m×nm\times n and entries Jij=∂ri/∂θjJ_{ij}=\partial r_i/\partial\theta_j. Each row describes one observation; each column describes sensitivity to one parameter.

Constructed observations beside a candidate exponential decay curve. Vertical segments show each prediction minus observation and therefore the residuals used in the fit.

Changing either parameter changes several residuals at once. These points are constructed for illustration, not measured data or the three-point Jacobian example that follows.

Open full-size figure

For a small parameter update pp, r(θ+p)≈r(θ)+Jpr(\theta+p)\approx r(\theta)+Jp. The product predicts a change, not the new residual itself.

For g(t;A,k)=Ae−ktg(t;A,k)=Ae^{-kt} at A=2A=2, k=ln⁡2k=\ln2, and t=0,1,2t=0,1,2 (scaled, dimensionless coordinates),

J=[101/2−11/4−1].J=\begin{bmatrix}1&0\\1/2&-1\\1/4&-1\end{bmatrix}.

The update p=(0.10,0.02)Tp=(0.10,0.02)^{\mathsf T} predicts changes (0.10,0.03,0.005)T(0.10,0.03,0.005)^{\mathsf T}. Actual changes are approximately (0.10,0.029209,0.004414)T(0.10,0.029209,0.004414)^{\mathsf T}. Reducing the step by ten reduces the largest discrepancy by about 99: the linear approximation improves locally.

The least-squares loss is Φ=12∥r∥2\Phi=\tfrac12\lVert r\rVert^2, where ∥r∥2=∑iri2\lVert r\rVert^2=\sum_i r_i^2. Transpose, written T\mathsf T, exchanges rows and columns. The loss gradient (its parameter partial derivatives) is JTrJ^{\mathsf T}r.

Gauss–Newton minimizes 12∥r+Jp∥2\tfrac12\lVert r+Jp\rVert^2. A Levenberg step adds a penalty on the current update:

qλ(p)=12∥r+Jp∥2+λ2∥p∥2.q_\lambda(p)=\tfrac12\lVert r+Jp\rVert^2+\tfrac\lambda2\lVert p\rVert^2.

Setting ∇pqλ=JT(r+Jp)+λp=0\nabla_p q_\lambda=J^{\mathsf T}(r+Jp)+\lambda p=0 gives

(JTJ+λI)p=−JTr.(J^{\mathsf T}J+\lambda I)p=-J^{\mathsf T}r.

Here II is the identity matrix and λ>0\lambda>0 controls damping. The parameters must be scaled sensibly; Marquardt variants incorporate scaling. This is a penalty on an update, not a fixed prior on the parameters. Check actual loss reduction before accepting a trial. The displayed normal equations explain the method; production solvers can use QR or SVD to avoid the conditioning penalty of explicitly forming JTJJ^{\mathsf T}J.

Contours of a constructed exponential fit's local squared residual. A cross marks the local-model minimum; arrows from zero show alternative damped proposals, not successive iterations. Larger damping shortens and rotates the proposal.

Contours show the local squared-residual model in scaled parameter updates. Each arrow starts at zero and represents a different damping choice, not the next point of one trajectory. Actual loss must be checked separately.

Open full-size figure

In regression and calibration, noisy data generally cannot all have zero residual. This differs from solving a square system F(u)=0F(u)=0, where a nonsingular (invertible) Jacobian gives the Newton proposal JFp=−FJ_Fp=-F. Damping can control a poor step but cannot create information absent from the observations. For example, early observations of a decay curve weakly constrain kk because ∂g/∂k=−Ate−kt\partial g/\partial k=-At e^{-kt} is small near t=0t=0.

Explain: why can a tiny damped step coexist with a large residual? No implementation of these advanced fitting methods is required for Project 3.

Hybrid Methods: preserve a bracket while using local models

A safeguarded method uses interpolation or a derivative when the proposed step is acceptable and falls back to bracket reduction when it is not.

Arctangent curve with a sign-changing bracket from minus one to two. The Newton proposal from two falls outside it; midpoint one half stays inside and supplies a bracket-reducing fallback.

The fallback protects the sign-changing bracket. It does not claim that every accepted local proposal is a root.

Open full-size figure

Brent’s Method

Combines bisection’s reliability with inverse quadratic interpolation’s speed:

Practical Strategy for Robust Root Finding

1. Find a continuous sign-change bracket by physics or a scan, then use bisection
2. Propose a local Newton or interpolation step while retaining the bracket
3. Reject unsafe proposals and enforce regular bracket reduction
4. Monitor bracket width, residual scale, stagnation, and evaluation cost
A function plot and recorded error histories compare bisection, Newton, and safeguarded Newton under a twenty-iteration cap; curves stop at termination.

Figure 10:Measured histories for f(x)=x20−1f(x)=x^{20}-1, with root 1. Bisection and the safeguarded Newton method start with [0.8,1.3][0.8,1.3]; Newton starts at x0=0.8x_0=0.8. All runs have a 20-iteration cap. Bracketed methods stop at half-width 10-10 or a sampled zero. Newton stops at a sampled zero, floating-point stagnation, or the cap. The hybrid takes a midpoint at least every other update. On intervening updates it accepts a finite Newton proposal only strictly inside the bracket; otherwise it also takes the midpoint. This is an illustrative safeguarded Newton method, not Brent’s algorithm. Curves end at termination; zero errors are omitted from the logarithmic axis. A large early Newton step or an unmet iteration cap does not prove eventual divergence. The reference root is exact; this plot reports measured outcomes rather than assigning a universal speed ranking.

Open full-size figure

All three hard-example runs reach the stated 20-iteration cap. Their final position errors are different; none should be reported as satisfying its stopping contract merely because one plotted error is small.


Investigation: which root estimate is justified?

Suppose three methods report nearly the same root. One stopped because the residual was small, one because the last step was small, and one because a bracket was narrow. These are different observations. Which one controls the position of the root, and what additional information does each require?

Return to the cubic f(x)=x3−2x−5f(x)=x^3-2x-5 from the opening figure. It is continuous, and f′(x)=3x2−2≥10f'(x)=3x^2-2\ge10 on [2,2.5][2,2.5], so a sign-changing bracket there contains one root. Before inspecting the recorded histories, predict:

  1. Must a bisection midpoint become more accurate at every iteration?

  2. Can Newton make a small step without a small position error?

  3. Does one Newton iteration cost the same as one secant iteration?

  4. Which conclusion survives multiplying the whole equation by 10-12?

For this problem, a bracket midpoint has position error at most the half-width. At a candidate in [2,2.5][2,2.5], the derivative bound also gives ∣x−r∣≤∣f(x)∣/10|x-r|\le |f(x)|/10. The last step ∣xk−xk−1∣|x_k-x_{k-1}| is neither of these bounds. It measures what the algorithm just did, not its distance from the answer. Stagnation can make it zero even when a target remains unmet.

The final recorded rows from the cubic comparison are:

Method∣f(x)∣\lvert f(x)\rvertLast recorded stepActual position errorff callsf′f' callsStop
bisection6.168e-105.821e-115.526e-11360width tolerance
newton8.882e-164.441e-160.000e+0066floating-point stagnation
secant8.882e-168.882e-160.000e+0090floating-point stagnation

A printed zero position error means agreement with the binary64 reference, not an exact representation of the mathematical root. A sampled zero residual also requires the function-evaluation caveat discussed with bisection.

The comparison figure reports real errors against an independent decimal reference. Those errors are available for this teaching example; the method cannot normally inspect them. Its stopping condition must use information available during the calculation. Count calls to ff and f′f' separately: a derivative may be cheaper, more expensive, or computed together with ff. An iteration count by itself does not settle the cost comparison.

Transfer: an accurate solve of an uncertain function

Now suppose the function values themselves have a bounded additive uncertainty η\eta. This is a different experiment from multiplying an exact equation by a constant. Keep xx and function values dimensionless, and consider

fs(x)=s(x−1),∣δf(x)∣≤η.f_s(x)=s(x-1),\qquad |\delta f(x)|\le\eta.

The unperturbed root is 1. Any perturbed zero obeys ∣x−1∣≤η/∣s∣|x-1|\le\eta/|s|. A smaller slope therefore permits a wider range of root positions for the same absolute uncertainty. A tighter iteration tolerance cannot distinguish among those possible input functions.

Two linear functions with slopes one and 0.05 have the same vertical uncertainty of 0.002; their possible root half-ranges are 0.002 and 0.04.

Figure 11:The vertical band represents allowed changes to the supplied function. Its intersection with the horizontal axis gives possible root positions, not iteration histories or statistical confidence intervals. The same uncertainty produces different position ranges because the slopes differ.

Open full-size figure

slope=1: possible roots in [0.998, 1.002]
slope=0.05: possible roots in [0.960, 1.040]

Predict what happens to this range if we halve the solver tolerance, halve η\eta, or multiply both fsf_s and its uncertainty by 100. Only one of those changes improves the information supplied about the root.

A repeated root makes the issue sharper. For f(x)=(x−1)2f(x)=(x-1)^2, a downward constant perturbation of size η>0\eta>0 produces two zeros, 1±η1\pm\sqrt{\eta}, while an upward perturbation removes the real zero. There is no nonzero derivative lower bound at the original root. For the unperturbed function, Newton’s exact recurrence is

xk+1−1=12(xk−1).x_{k+1}-1=\frac12(x_k-1).

A tiny residual is especially easy to obtain here because it is the square of the position error. For example, residual 10-12 corresponds to position error 10-6, not 10-12.

Further reading: conditioning, residuals, and multiple roots.

Application: Units and Scaling

Choose scales that make the variables and tolerances interpretable. Non-dimensionalization can avoid extreme arithmetic and improve numerical balancing, but it does not remove intrinsic sensitivity:

Dimensional form: Finding radius where ρ(r)=10−7\rho(r) = 10^{-7} g/cm3^3 with rr in cm Scaled form: Define r~=r/R⊙\tilde{r} = r/R_{\odot}, ρ~=ρ/ρ0\tilde{\rho} = \rho/\rho_0 and solve ρ~(r~)=10−7 g cm−3/ρ0\tilde{\rho}(\tilde{r}) = 10^{-7}\,\mathrm{g\,cm^{-3}}/\rho_0 (equal to 1 only if that target is the chosen ρ0\rho_0)

Track the units of the position tolerance and transform it with the variable. Rescaling an equation changes its residual values; it does not by itself make a root better determined by the physical data.


Physical Example: Stellar Structure Equilibrium

In stellar interiors, hydrostatic equilibrium requires:

dPdr=−GM(r)ρ(r)r2\frac{dP}{dr} = -\frac{GM(r)\rho(r)}{r^2}

For a polytrope with P=Kρ1+1/nP = K\rho^{1+1/n}, the Lane-Emden equation describes stellar structure:

1ξ2ddξ(ξ2dθdξ)+θn=0\frac{1}{\xi^2}\frac{d}{d\xi}\left(\xi^2\frac{d\theta}{d\xi}\right) + \theta^n = 0

where ξ\xi is dimensionless radius and θ\theta is related to density.

The stellar surface occurs where θ(ξ1)=0\theta(\xi_1) = 0—a root-finding problem!

For different polytropic indices:

These solutions use θ(0)=1\theta(0)=1 and θ′(0)=0\theta'(0)=0. Reference: analytic polytropes.

A computed Lane–Emden trajectory can supply both θ\theta and its derivative near the surface. Root refinement then depends on the accuracy of that trajectory as well as on the root solver. Tightening a root tolerance cannot remove the ODE or interpolation error. Preserve a credible surface bracket and refine the underlying trajectory before claiming additional digits.


Worked Example: Kepler’s Equation

The most famous root-finding problem in astronomy is Kepler’s equation, which relates mean anomaly MM (proportional to time) to eccentric anomaly EE (related to position):

E−esin⁡(E)=ME - e\sin(E) = M

where ee is the orbital eccentricity and both MM and EE are in radians.

Why This Is Hard

Newton’s Method Applied

Define f(E)=E−esin⁡(E)−Mf(E) = E - e\sin(E) - M

Then f′(E)=1−ecos⁡(E)f'(E) = 1 - e\cos(E)

Newton iteration:

En+1=En−En−esin⁡(En)−M1−ecos⁡(En)E_{n+1} = E_n - \frac{E_n - e\sin(E_n) - M}{1 - e\cos(E_n)}

For an ellipse, 0≤e<10\le e<1, so f′(E)=1−ecos⁡E≥1−e>0f'(E)=1-e\cos E\ge1-e>0. The derivative can become small near periapsis as ee approaches 1, but it cannot vanish in this domain.

Initial Guess Strategy

One heuristic on a reduced mean-anomaly interval is to start with E0=ME_0=M for e<0.8e<0.8 and E0=πE_0=\pi otherwise. The value 0.8 is not a convergence threshold, and the first regime is not uniformly nearly circular. Compare both guesses over the project’s sweep and report failures and iteration counts. If reducing MM modulo 2π2\pi, restore its branch in the returned EE.

Convergence Analysis

The absolute sensitivity to mean anomaly is

dEdM=11−ecos⁡E≤11−e.\frac{dE}{dM}=\frac{1}{1-e\cos E}\le\frac{1}{1-e}.

For e=0e=0, E=ME=M exactly. For e=0.9e=0.9 the upper bound is 10, and for e=0.99e=0.99 it is 100; these are bounds, not the sensitivity at every orbital phase. Iteration counts also depend on MM, the initial guess, and the stopping criterion. Normalize MM to [0,2π][0,2\pi] for the initial-guess choices above. Because the residual is increasing and changes sign on [0,2π][0,2\pi] for an interior MM, bisection provides a useful independent check on Newton’s answer.


Practical Algorithm for Finding Initial Brackets

To find initial brackets for bisection:

[(np.float64(0.5), np.float64(0.5))]

A scan can miss an even-multiplicity root between samples or several crossings within one cell. A sampled zero is reported once, as a zero-width pair; the reading’s bisection accepts it. Project 3’s bisect requires a < b, so retain these sampled roots separately and send only positive-width brackets to that solver. Neither a sign scan nor bisection proves continuity or verifies that a computed zero did not arise from underflow.


Debugging Root Finding

Common root-finding bugs and their diagnosis:

SymptomLikely CauseFix
Bisection won’t startSame sign at endpointsScan for sign changes first
Newton divergesPoor initial guess or a small derivativeFind and verify a sign-changing bracket first, then apply bisection; a line search is another step-control option with different guarantees
Secant oscillatesAn unreliable slope or poor starting pointsInspect the function-value scale, separation of inputs, and proposed step; reject zero/nonfinite denominators or unusable updates, then restart or safeguard
Wrong root foundMultiple roots in regionNarrow search interval
No progressNo representable interior point or unmet iteration capReport failure; reassess position tolerance and scaling
No convergenceDiscontinuous functionCheck function continuity

Bridge to Part 2: From Finding Zeros to Measuring Areas

You can now compare three kinds of evidence: a shrinking bracket, a local iteration model, and a residual interpreted through sensitivity. A method choice should identify which of these supports the reported root.

But finding equilibrium points is only half the story. Next, we tackle integration — measuring quantities across space and time. You’ll discover how the same principles of approximation and error analysis apply to computing areas under curves, volumes of regions, and integrals over high-dimensional spaces.

The synthesis returns to a problem in which an integral defines the root residual. The two algorithms have separate jobs, but their errors contribute to one final answer.

Next: Part 2 - Quadrature