Numerical Methods

All books

M02 — Root finding

A rule has to hold at a point: f(x)=0f(x) = 0. When the rule cannot be rearranged, you iterate, and three questions decide whether the answer can be trusted: does the iteration reach a root at all, which root, and how fast. This notebook answers them for bisection, Newton's method and the secant method, and measures each rate with the observed-order tool from M01.

Book pages: Root finding and Why Newton is fast, and when it is not in books/numerical-methods.

The question. You need a root of ff. Which method finds it, how fast does it get there, and how do you know when to stop?

By the end you can:

  • say what bisection guarantees and count its steps before running it
  • derive Newton's step from the tangent, and its squared error ek+1≈f′′2f′ek2e_{k+1} \approx \frac{f''}{2f'} e_k^2
  • measure an iteration's order from successive errors or steps
  • explain why a start can land on a distant root, cycle or diverge
  • recognise a multiple root from a constant error ratio, and restore order 2
  • choose between Newton and the secant method by cost per digit
  • make Newton safe with a line search, and pick a stopping test that means something

Assumes: M01 (relative error, observed order, the round-off floor), and Taylor's theorem with the remainder.

How to use it: predict before you reveal, commit before you check, and move the controls until the equation's behaviour stops surprising you.

Predict first. Try first: bisection on [1,2][1, 2] needs 50 halvings to trap 2\sqrt2 in a bracket of width 10−1510^{-15}. Newton's method on f(x)=x2−2f(x) = x^2 - 2 from x0=1x_0 = 1 gets within 10−1510^{-15} of 2\sqrt2 in about

Choose a prediction

Check answer (without scripting)

Answer: 5 steps. Each step squares the error: 0.410.41, 0.0860.086, 0.00250.0025, 2.1×10−62.1 \times 10^{-6}, 1.6×10−121.6 \times 10^{-12}, then the round-off floor. Digits double per step.

Warm-up: remember M01 (closed book)

1. A method has order p=2p = 2. You halve the step. In the asymptotic region the error

Question 1
How sure?

2. You have fhf_h, fh/2f_{h/2}, fh/4f_{h/4} but no exact answer. What can you still estimate?

Question 2
How sure?

3. Why does shrinking hh below about 10−510^{-5} make a central difference worse?

Question 3
How sure?

Show answers and explanations

1. falls by a factor of 4. E(h)≈Ch2E(h) \approx C h^2, so E(h/2)≈Ch2/4E(h/2) \approx C h^2 / 4: the factor is 2p2^p.

2. The observed order, from the ratio of successive differences. fh−fh/2f_h - f_{h/2} behaves like E(h)E(h), so log⁡2\log_2 of the ratio of successive differences estimates pp with no exact answer.

3. The rounding error, about epsilon / h, grows as h shrinks. The total error is about Ch2+ϵ/hC h^2 + \epsilon/h. The first term falls, the second rises, and below h∼ϵ1/3≈6×10−6h \sim \epsilon^{1/3} \approx 6 \times 10^{-6} the second wins.

1. Bisection: one bit per step

Setting: the problem, its sets and its symbols

Problem. Given f∈C([a,b])f \in C([a, b]) with f(a)f(b)<0f(a) f(b) \lt 0 and a tolerance τ>0\tau > 0, find a bracket [ak,bk]⊆[a,b][a_k, b_k] \subseteq [a, b] with f(ak)f(bk)≤0f(a_k) f(b_k) \le 0 and bk−ak≤τb_k - a_k \le \tau, and the number of halvings kk it takes.

Symbol In Meaning
ff C([a,b])C([a, b]) the continuous function whose root we seek; here x2−2x^2 - 2
[a,b][a, b] ⊂R\subset \mathbb{R} the starting bracket; here [1,2][1, 2]
x∗x^* (a,b)(a, b) a root, f(x∗)=0f(x^*) = 0; here 2\sqrt2
τ\tau (0,∞)(0, \infty) the tolerance on the bracket width, in the units of xx
nn {1,…,15}\{1, \dots, 15\} the slider: τ=10−n\tau = 10^{-n}
kk N\mathbb{N} the number of halvings (the unknown)
[ak,bk][a_k, b_k] ⊆[a,b]\subseteq [a, b] the bracket after kk halvings
mkm_k [ak,bk][a_k, b_k] its midpoint, the estimate of x∗x^*
∣mk−x∗∣\lvert m_k - x^* \rvert [0,∞)[0, \infty) the error of the estimate; bounded by (bk−ak)/2(b_k - a_k)/2
How these symbols connect

Given a continuous map f∈C([a,b])f \in C([a, b]) whose endpoint values satisfy f(a)f(b)<0f(a) f(b) \lt 0, the intermediate value theorem guarantees a root x∗∈(a,b)x^* \in (a, b). Each halving evaluates ff at the midpoint mkm_k of [ak,bk][a_k, b_k] and retains the half preserving the sign change until bk−ak≤τb_k - a_k \le \tau (where τ=10−n\tau = 10^{-n} carries the units of xx). The unknown step count k∈Nk \in \mathbb{N} follows directly from the dimensionless ratio (b−a)/τ(b - a)/\tau, and the estimate error ∣mk−x∗∣\lvert m_k - x^* \rvert (in the units of xx) is always bounded by half the bracket width.

Symbol-by-symbol notes
$f \in C([a, b])$ and $f(a) f(b) < 0$ — continuity and sign change

C([a,b])C([a, b]) is the space of functions continuous on the closed interval [a,b][a, b]; no derivative is needed. The strict inequality f(a)f(b)<0f(a) f(b) \lt 0 means the endpoints have opposite signs, forcing at least one root into the open interval (a,b)(a, b).

$[a\lt em>k, b\lt /em>k]$ and $f(a\lt em>k) f(b\lt /em>k) \le 0$ — nested brackets

The brackets form a nested chain [a,b]=[a0,b0]⊃[a1,b1]⊃…[a, b] = [a_0, b_0] \supset [a_1, b_1] \supset \dots whose widths halve every step. Using ≤0\le 0 rather than <0\lt 0 handles the edge case where a midpoint lands exactly on a root, giving f(ak)f(bk)=0f(a_k) f(b_k) = 0.

$m\lt em>k$ vs $\lvert m\lt /em>k - x^* \rvert$ — midpoint estimate vs error bound

Because both x∗x^* and the midpoint mk=(ak+bk)/2m_k = (a_k + b_k)/2 lie inside [ak,bk][a_k, b_k], ∣mk−x∗∣\lvert m_k - x^* \rvert is at most (bk−ak)/2(b_k - a_k)/2. The true error ∣mk−x∗∣\lvert m_k - x^* \rvert can jump up on an individual step even though the half-width bound shrinks strictly.

$\tau$ and $k$ — width tolerance and step count

τ>0\tau > 0 bounds the bracket width bk−akb_k - a_k in the units of xx, not the function value ∣f(mk)∣\lvert f(m_k) \rvert. Because every step halves the width independently of ff, the integer kk is known before running a single iteration.

Take f(x)=x2−2f(x) = x^2 - 2 on [1,2][1, 2]. ff is continuous and f(1)=−1<0<2=f(2)f(1) = -1 \lt 0 \lt 2 = f(2), so a root lies between (the intermediate value theorem). The midpoint gives f(1.5)=0.25>0f(1.5) = 0.25 > 0, so the root is in [1,1.5][1, 1.5]. Repeat.

Each step keeps the half whose ends differ in sign, so the root never leaves the bracket. After kk halvings the width is (b−a)/2k(b - a)/2^k, and making it at most a tolerance τ\tau takes

k=⌈log⁡2b−aτ⌉k = \left\lceil \log_2 \frac{b - a}{\tau} \right\rceil

steps, whatever ff is. That is linear convergence with ratio 12\tfrac12: one binary digit per step, or log⁡102≈0.30\log_{10} 2 \approx 0.30 decimal digits, about 3.3 steps per digit. The price of the guarantee is that bisection reads only the sign of ff, never its size.

τ=10−10\tau = 10^{-10} needs k=34k = 34 halvings. They leave the bracket [1.4142135623260401, 1.4142135623842478][1.4142135623260401,\ 1.4142135623842478] of width 5.82e-11; its midpoint is 1.8e-11 from 2\sqrt2.

The error itself is not monotone: 0.086 at step 0, 0.164 at step 1. The ratio of successive errors, M01's raw material, wanders from 0.006 to 82.5 over this run. Only the bound halves cleanly, so bisection's order is read from the bound: 1, with ratio 12\tfrac12.

08.51725.53410⁻¹¹10⁻⁸10⁻⁵10⁻²bound: half the bracket|midpoint − √2|halvings kerror
When bisection breaks
  • Assumes: ff is continuous on [a,b][a, b] and f(a)f(a), f(b)f(b) have opposite signs
  • When it fails: a root of even multiplicity has no sign change, so no bracket exists; at a pole (1/x1/x on [−1,1][-1, 1]) the bracket shrinks onto the pole and reports it as a root
  • Check: evaluate ∣f∣|f| at the returned point: at a pole it grows as the bracket shrinks

2. Newton: the tangent, and a squared error

Setting: the problem, its sets and its symbols

Problem. Given f∈C2(R)f \in C^2(\mathbb{R}) with a simple root x∗x^* (f(x∗)=0f(x^*) = 0, f′(x∗)≠0f'(x^*) \ne 0) and a start x0∈Rx_0 \in \mathbb{R}, find iterates (xk)k∈N⊂R(x_k)_{k \in \mathbb{N}} \subset \mathbb{R} with xk→x∗x_k \to x^*, and the order pp and constant CC such that ∣ek+1∣≈C∣ek∣p\lvert e_{k+1} \rvert \approx C \lvert e_k \rvert^p.

Symbol In Meaning
ff C2(R)C^2(\mathbb{R}) the function whose root we seek; here x2−2x^2 - 2
f′f' C1(R)C^1(\mathbb{R}) its derivative; here 2x2x
x∗x^* R\mathbb{R} the simple root; here 2\sqrt2
xkx_k R\mathbb{R} the kk-th iterate; x0=1x_0 = 1
kk N\mathbb{N} the iteration index
eke_k R\mathbb{R} the error xk−x∗x_k - x^*
ξ\xi R\mathbb{R} a point between xkx_k and x∗x^*, from Taylor's theorem
pp (0,∞)(0, \infty) the order (an unknown)
CC [0,∞)[0, \infty) the asymptotic constant (an unknown)
sks_k [0,∞)[0, \infty) the step ∣xk+1−xk∣\lvert x_{k+1} - x_k \rvert, a stand-in for ∣ek∣\lvert e_k \rvert
δ\delta R\mathbb{R} the relative error in the derivative: the solver uses (1+δ)f′(1 + \delta) f'
How these symbols connect

Given f∈C2(R)f \in C^2(\mathbb{R}), its derivative f′∈C1(R)f' \in C^1(\mathbb{R}), and a starting value x0∈Rx_0 \in \mathbb{R}, each iterate xkx_k produces xk+1x_{k+1} from the zero of the tangent line at (xk,f(xk))(x_k, f(x_k)), generating errors ek=xk−x∗e_k = x_k - x^* in the units of xx. Taylor's theorem at xkx_k with remainder point ξ\xi between xkx_k and x∗x^* links ek+1e_{k+1} to eke_k and determines the unknown order pp and asymptotic constant CC in ∣ek+1∣≈C∣ek∣p\lvert e_{k+1} \rvert \approx C \lvert e_k \rvert^p. When x∗x^* is unknown, the observable step sk=∣xk+1−xk∣s_k = \lvert x_{k+1} - x_k \rvert stands in for ∣ek∣\lvert e_k \rvert, and the dimensionless perturbation δ\delta tests how an inexact derivative affects that rate.

Symbol-by-symbol notes
$x^*$ — simple root ($f(x^*) = 0$, $f'(x^*) \ne 0$)

A root is simple when the graph crosses the axis with non-zero slope, so f′(x∗)≠0f'(x^*) \ne 0. Requiring f∈C2(R)f \in C^2(\mathbb{R}) keeps f′f' and f′′f'' continuous near x∗x^*, ensuring division by f′(xk)f'(x_k) stays well-defined close to the root.

$e\lt em>k$ vs $s\lt /em>k$ — true error vs observable step

ek=xk−x∗e_k = x_k - x^* is signed and requires knowing x∗x^*, whereas sk=∣xk+1−xk∣s_k = \lvert x_{k+1} - x_k \rvert is non-negative and computed purely from consecutive iterates. Both share the units of xx, and sks_k replaces ∣ek∣\lvert e_k \rvert when measuring pp without an exact root.

$\xi$ — Taylor remainder point

ξ\xi is an unspecified real number strictly between xkx_k and x∗x^* supplied by Taylor's theorem, and it changes at every step kk. Only the fact that ξ→x∗\xi \to x^* as xk→x∗x_k \to x^* is needed.

$p$ and $C$ — iteration order and asymptotic constant

Unlike M01 §3's step-size error ChpC h^p, here error decays from one iterate to the next via ∣ek+1∣≈C∣ek∣p\lvert e_{k+1} \rvert \approx C \lvert e_k \rvert^p. The order p>0p > 0 is dimensionless, while CC carries units of x1−px^{1-p} so both sides have the units of xx.

$\delta$ — relative error in $f'$

δ\delta is dimensionless and models replacing f′(xk)f'(x_k) with (1+δ)f′(xk)(1 + \delta) f'(x_k), as from a finite-difference derivative or a coding slip. Setting δ=0\delta = 0 recovers exact Newton; δ=−1\delta = -1 would zero out the denominator.

Bisection ignores the size of ff. At x0=1x_0 = 1, f(1)=−1f(1) = -1 and f′(1)=2f'(1) = 2: the curve is one unit below the axis and climbing at slope 2, so the straight line that matches it there reaches zero half a unit to the right, at 1.5. That line is the tangent

y=f(xk)+f′(xk)(x−xk),y = f(x_k) + f'(x_k)(x - x_k),

and setting y=0y = 0 gives Newton's step

xk+1=xk−f(xk)f′(xk).x_{k+1} = x_k - \frac{f(x_k)}{f'(x_k)}.

Why it is fast. Write ek=xk−x∗e_k = x_k - x^*. Taylor's theorem about xkx_k, evaluated at the root, gives 0=f(xk)−f′(xk) ek+12f′′(ξ) ek20 = f(x_k) - f'(x_k)\, e_k + \tfrac12 f''(\xi)\, e_k^2 for some ξ\xi between xkx_k and x∗x^*. Divide by f′(xk)f'(x_k) and subtract from the step:

ek+1=f′′(ξ)2f′(xk) ek2  ⟶  f′′(x∗)2f′(x∗) ek2.e_{k+1} = \frac{f''(\xi)}{2 f'(x_k)}\, e_k^2 \;\longrightarrow\; \frac{f''(x^*)}{2 f'(x^*)}\, e_k^2 .

For x2−2x^2 - 2 the constant is 2/(2⋅22)=1/(22)2 / (2 \cdot 2\sqrt2) = 1/(2\sqrt2).

Measuring the order of an iteration. If ek+1≈Cekpe_{k+1} \approx C e_k^p, then log⁡ek+1=log⁡C+plog⁡ek\log e_{k+1} = \log C + p \log e_k; subtract the same line one step earlier and CC goes:

p≈log⁡(ek+1/ek)log⁡(ek/ek−1).p \approx \frac{\log (e_{k+1} / e_k)}{\log (e_k / e_{k-1})}.

This is M01 §3 with the iteration count in place of halving hh. With no exact root, use the steps sk=∣xk+1−xk∣s_k = |x_{k+1} - x_k| in place of eke_k, as M01 §4 used differences between runs.

Reveal result (lock in your prediction above first)
012.52537.55010⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰bisectionNewtonstep k|x_k − √2|
k x_k e_k e_k / e_(k-1)^2 order from errors order from steps
0 1.000000000000000 4.14e-01
1 1.500000000000000 8.58e-02 0.5000
2 1.416666666666667 2.45e-03 0.3333 2.258 1.968
3 1.414215686274510 2.12e-06 0.3529 1.984 2.000
4 1.414213562374690 1.59e-12 0.3535 2.000 2.000
5 1.414213562373095 0.00e+00
6 1.414213562373095 2.22e-16
7 1.414213562373095 0.00e+00

Newton is within 10−1510^{-15} after 5 steps. After the first row, taken from a distant start, the ratio column climbs to the predicted 1/(22)=0.35361/(2\sqrt2) = 0.3536 from below: ξ\xi is still travelling towards the root on the early steps. The observed order reads 2 within three rows, and the order from steps agrees with no root in hand. The last rows sit on the round-off floor (M01 §5): an error of 0 or one spacing, where an order means nothing; the chart stops a run at its first exact zero, which a log axis cannot show. Bisection's points scatter under §1's bound, which falls by a factor of 2 per step.

A derivative that is slightly wrong. Multiply f′f' by (1+δ)(1 + \delta), as a coding slip or a difference quotient does. Near the root f(xk)≈f′(x∗) ekf(x_k) \approx f'(x^*)\, e_k, so the step removes ek/(1+δ)e_k / (1 + \delta) and leaves

ek+1≈δ1+δ ek.e_{k+1} \approx \frac{\delta}{1 + \delta}\, e_k .

The order falls to 1. The limit does not move: the step is still zero only where ff is. Choose δ\delta and watch the ratio column settle.

k e_k e_k / e_(k-1) observed order
0 4.14e-01
1 4.03e-02 0.0974
2 4.17e-03 0.1035 0.974
3 3.85e-04 0.0922 1.051
4 3.51e-05 0.0910 1.006
5 3.19e-06 0.0909 1.001
6 2.90e-07 0.0909 1.000
7 2.63e-08 0.0909 1.000
8 2.39e-09 0.0909 1.000
9 2.18e-10 0.0909 1.000
10 1.98e-11 0.0909 1.000
11 1.80e-12 0.0909 1.000

Predicted ratio δ/(1+δ)=0.0909\delta/(1+\delta) = 0.0909; the last ratio above 10−1310^{-13} in the table, row 11, is 0.0909. A factor near 10−810^{-8} is too small to see before the floor, which is why a difference-quotient Jacobian is usually harmless. A factor of 0.1 is a linear method dressed as Newton.

When Newton's quadratic rate breaks
  • Assumes: the root is simple and f′f' is the true derivative at each iterate
  • When it fails: a derivative with relative error δ\delta still converges to the root, but linearly, with ratio δ/(1+δ)\delta / (1 + \delta)
  • Check: the observed order from successive errors or steps should read 2; check f′f' against a central difference (M01 §3) before blaming the start

3. Far from the root: basins, cycles and divergence

Setting: the problem, its sets and its symbols

Problem. Given a differentiable f:R→Rf : \mathbb{R} \to \mathbb{R} with roots Z=f−1(0)Z = f^{-1}(0), and a start x0∈Rx_0 \in \mathbb{R}, find whether the Newton sequence xk+1=N(xk)x_{k+1} = N(x_k) converges, and to which root; that is, find the basin B(r)={x0∈R:xk→r}B(r) = \{x_0 \in \mathbb{R} : x_k \to r\} of each r∈Zr \in Z.

Symbol In Meaning
ff R→R\mathbb{R} \to \mathbb{R} here x3−xx^3 - x; later x3−2x+2x^3 - 2x + 2 and arctan⁡x\arctan x
ZZ ⊂R\subset \mathbb{R} the roots of ff; for x3−xx^3 - x, {−1,0,1}\{-1, 0, 1\}
NN {x:f′(x)≠0}→R\{x : f'(x) \ne 0\} \to \mathbb{R} the Newton map x−f(x)/f′(x)x - f(x)/f'(x)
x0x_0 [−2,2][-2, 2] the start; the slider sets it
xkx_k R\mathbb{R} the kk-th iterate, NN applied kk times to x0x_0
B(r)B(r) ⊂R\subset \mathbb{R} the basin of attraction of the root rr (the unknown)
xcx_c (1,2)(1, 2) for arctan⁡x\arctan x: the start that NN maps to −xc-x_c
How these symbols connect

A differentiable map f:R→Rf : \mathbb{R} \to \mathbb{R} defines both its zero set Z=f−1(0)Z = f^{-1}(0) and the Newton iteration map N(x)=x−f(x)/f′(x)N(x) = x - f(x)/f'(x) wherever f′(x)≠0f'(x) \ne 0. Choosing a start x0∈[−2,2]x_0 \in [-2, 2] and applying NN repeatedly generates the sequence xk=Nk(x0)x_k = N^k(x_0) in the units of xx. Classifying starts by their limit divides R\mathbb{R} into the unknown basins of attraction B(r)B(r) for each r∈Zr \in Z, alongside starts that hit f′(x)=0f'(x) = 0, cycle (such as ±xc\pm x_c for arctan⁡x\arctan x), or diverge.

Symbol-by-symbol notes
$Z = f^{-1}(0)$ — zero set (pre-image of $0$)

f−1(0)f^{-1}(0) means the pre-image {x∈R:f(x)=0}\{x \in \mathbb{R} : f(x) = 0\}, not an inverse function of ff. Every root r∈Zr \in Z with f′(r)≠0f'(r) \ne 0 is a fixed point of NN, because N(r)=r−0/f′(r)=rN(r) = r - 0/f'(r) = r.

$N : \{x : f'(x) \ne 0\} \to \mathbb{R}$ — the Newton map and its domain

NN is undefined at stationary points where f′(x)=0f'(x) = 0, because a horizontal tangent never meets the axis. Iterating NN composes it with itself (x1=N(x0)x_1 = N(x_0), x2=N(N(x0))x_2 = N(N(x_0)), …) as long as no iterate lands where f′=0f' = 0.

$B(r)$ — basin of attraction

For each root r∈Zr \in Z, B(r)B(r) collects every start x0∈Rx_0 \in \mathbb{R} whose iterates xkx_k converge to rr. Basins of distinct roots cannot overlap, and their union need not cover all of R\mathbb{R} because some starts fail to converge.

$x_c$ — symmetric 2-cycle threshold for $\arctan x$

For the odd function f(x)=arctan⁡xf(x) = \arctan x, xc∈(1,2)x_c \in (1, 2) is the positive start satisfying N(xc)=−xcN(x_c) = -x_c; by symmetry N(−xc)=xcN(-x_c) = x_c, so starting at xcx_c bounces between xcx_c and −xc-x_c forever. It marks a boundary between different long-term behaviours of NN on arctan⁡x\arctan x.

§2's rate is local: it needs xkx_k and ξ\xi near x∗x^*. Far away the tangent can point anywhere. Take f(x)=x3−xf(x) = x^3 - x, with roots −1-1, 0 and 1. Each root has a basin of attraction, the set of starts from which Newton reaches it.

Predict first. Newton on f(x)=x3−xf(x) = x^3 - x (roots −1-1, 00, 11) starts at x0=0.5x_0 = 0.5, halfway between the roots 0 and 1. It converges to

Choose a prediction

Check answer (without scripting)

Answer: the root at −1. f(0.5)=−0.375f(0.5) = -0.375, f′(0.5)=−0.25f'(0.5) = -0.25, so the step is −1.5-1.5 and lands exactly on −1-1. The basin of −1-1 reaches across the other two roots.

Reveal result (lock in your prediction above first)
-2-1012-3.26-1.638.88e-161.633.26series-110start x0f(x) = x³ − x

The strip colours each of 801 starts by the root it reaches: 311 reach −1-1, 179 reach 0, 311 reach 1, 0 none. Between 1/5≈0.4471/\sqrt5 \approx 0.447, where Newton maps xx to −x-x (a 2-cycle), and 1/3≈0.5771/\sqrt3 \approx 0.577, where f′=0f' = 0, the basins interleave in ever thinner bands, and the same happens on the negative side. A start there is a coin toss.

k x_k f(x_k)
0 0.5500000000 -3.84e-01
1 -3.5972972973 -4.30e+01
2 -2.4616062888 -1.25e+01
3 -1.7366012767 -3.50e+00
4 -1.3015994195 -9.04e-01
5 -1.0802832289 -1.80e-01
6 -1.0081450681 -1.65e-02
7 -1.0000976576 -1.95e-04
8 -1.0000000143 -2.86e-08
9 -1.0000000000 -4.44e-16
10 -1.0000000000 0.00e+00

Cycles and divergence. Newton on x3−2x+2x^3 - 2x + 2 from 0 visits 0, 1, 0, 1, 0, 1: a 2-cycle that never converges, though a real root lies at -1.7693.

Newton on arctan⁡x\arctan x maps x↦x−(1+x2)arctan⁡xx \mapsto x - (1 + x^2) \arctan x. A start that maps to its own negative bounces for ever; it solves 2x=(1+x2)arctan⁡x2x = (1 + x^2) \arctan x, and bisection (§1) on [1,2][1, 2] gives xc=1.3917452x_c = 1.3917452. Inside xcx_c the iterates shrink; outside they grow. From 1.5: 1.5, -1.694, 2.321, -5.114, 32.3, -1575. The residual ∣arctan⁡xk∣|\arctan x_k| climbs towards π/2\pi/2 the whole time, which is the warning sign §6 acts on.

When Newton from a distant start breaks
  • Assumes: x0x_0 lies in the basin of the root you want; the convergence theorem is local
  • When it fails: the iterate lands on another root, cycles (x3−2x+2x^3 - 2x + 2 from 0) or diverges (arctan⁡x\arctan x from beyond about 1.39)
  • Check: ∣f∣|f| should fall at every step; if it does not, damp the step (§6) or bracket the root first (§1)

4. Multiple roots: Newton goes linear

Setting: the problem, its sets and its symbols

Problem. Given f(x)=(x−x∗)mg(x)f(x) = (x - x^*)^m g(x) with gg smooth, g(x∗)≠0g(x^*) \ne 0 and m≥1m \ge 1 (a multiple root when m≥2m \ge 2), and Newton's iterates xkx_k from x0x_0, find how ek+1e_{k+1} depends on eke_k near x∗x^*, and the limiting ratio ρ\rho where one exists.

Symbol In Meaning
ff C∞(R)C^\infty(\mathbb{R}) here (x−1)m(x+2)(x - 1)^m (x + 2)
x∗x^* R\mathbb{R} the multiple root; here 11
mm {1,2,3,4}\{1, 2, 3, 4\} the multiplicity of x∗x^*; the slider sets it
gg C∞(R)C^\infty(\mathbb{R}) the factor left after removing (x−x∗)m(x - x^*)^m; here x+2x + 2
xkx_k R\mathbb{R} the kk-th iterate; x0=2x_0 = 2
eke_k R\mathbb{R} the error xk−x∗x_k - x^*
ρ\rho [0,1][0, 1] the limit of ∣ek+1∣/∣ek∣\lvert e_{k+1} \rvert / \lvert e_k \rvert (the unknown)
ϵ\epsilon F\mathbb{F} machine epsilon, 2−522^{-52}, for the floor in the reveal
How these symbols connect

Factoring f∈C∞(R)f \in C^\infty(\mathbb{R}) near a root x∗x^* as f(x)=(x−x∗)mg(x)f(x) = (x - x^*)^m g(x) with g(x∗)≠0g(x^*) \ne 0 separates the integer multiplicity mm from the non-vanishing smooth factor gg. Running Newton from x0=2x_0 = 2 generates iterates xkx_k and errors ek=xk−x∗e_k = x_k - x^* (in the units of xx), whose dimensionless ratios ∣ek+1∣/∣ek∣\lvert e_{k+1} \rvert / \lvert e_k \rvert determine the unknown limiting ratio ρ∈[0,1]\rho \in [0, 1]. Comparing exact behaviour against double-precision evaluation then shows how machine epsilon ϵ\epsilon limits how close xkx_k can get to x∗x^*.

Symbol-by-symbol notes
$m$ and $g$ — multiplicity and the non-vanishing factor

m∈{1,2,3,4}m \in \{1, 2, 3, 4\} is the highest power of (x−x∗)(x - x^*) dividing f(x)f(x), and g(x∗)≠0g(x^*) \ne 0 ensures no extra factor of (x−x∗)(x - x^*) is hidden inside gg. When m=1m = 1 the root is simple (f′(x∗)≠0f'(x^*) \ne 0); when m≥2m \ge 2 both f(x∗)f(x^*) and f′(x∗)f'(x^*) vanish.

$C^\infty(\mathbb{R})$ — infinitely differentiable functions

Polynomials such as (x−1)m(x+2)(x - 1)^m (x + 2) have continuous derivatives of all orders on R\mathbb{R}, placing ff and gg in C∞(R)C^\infty(\mathbb{R}). This guarantees every derivative needed around x∗x^* exists and is continuous.

$\rho \in [0, 1]$ — limiting error ratio

ρ=lim⁡k→∞∣ek+1∣/∣ek∣\rho = \lim_{k \to \infty} \lvert e_{k+1} \rvert / \lvert e_k \rvert is dimensionless. A limit ρ=0\rho = 0 means the step-to-step reduction factor shrinks to zero with the error (as at §2's simple root), whereas 0<ρ<10 \lt \rho \lt 1 means each step multiplies the error by a constant factor ρ\rho.

$\epsilon$ — floating-point floor near a multiple root

Although the iterates are analysed in R\mathbb{R}, evaluating an expanded polynomial in doubles F\mathbb{F} adds rounding errors of size proportional to ϵ\epsilon. Because (x−x∗)m(x - x^*)^m flattens near x∗x^*, rounding noise can swamp f(x)f(x) well before ∣ek∣\lvert e_k \rvert reaches ϵ\epsilon.

§2 divided by f′(x∗)f'(x^*). At a root where the curve touches the axis instead of crossing it, f′(x∗)=0f'(x^*) = 0 too. Take f(x)=(x−1)2(x+2)f(x) = (x-1)^2(x+2), which touches zero at 1.

Figure 1

Predict first. Newton on f(x)=(x−1)2(x+2)f(x) = (x - 1)^2 (x + 2) from x0=2x_0 = 2. Close to the double root at 1, each step multiplies the error by about

Choose a prediction

Check answer (without scripting)

Answer: 1/2. f/f′≈ek/2f/f' \approx e_k/2 at a double root, so each step removes half the error: linear convergence with ratio (m−1)/m=12(m-1)/m = \tfrac12.

Reveal result (lock in your prediction above first)
013.226.539.85310⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰Newton, f/f′modified, 2 f/f′step k|x_k − 1|

With m=2m = 2 the last ratio ek+1/eke_{k+1}/e_k above 10−1210^{-12} is 0.5000, against (m−1)/m=0.5000(m-1)/m = 0.5000. The modified step mf/f′m f/f' reaches 0.0e+00 in 5 steps.

How close can you get? Written as x3−3x+2x^3 - 3x + 2, the same m=2m = 2 function evaluates to exactly 0 at x=1.000000007685x = 1.000000007685, 7.7e-09 from the root, and Newton stops there after 28 steps. Near a double root f≈3e2f \approx 3e^2, while the sum x3−3x+2x^3 - 3x + 2 cancels terms of size about 2 and carries a rounding error of a few ϵ\epsilon (M01 §2). Once 3e23e^2 is below that, the computed ff is noise: e≲ϵe \lesssim \sqrt{\epsilon}, about 1.5e-08. The factored form has no cancellation, which is why it keeps converging.

Why the ratio is (m−1)/m(m-1)/m. At a root of multiplicity mm, f(x)=(x−x∗)mg(x)f(x) = (x - x^*)^m g(x) with g(x∗)≠0g(x^*) \ne 0. Then f′=m(x−x∗)m−1g+(x−x∗)mg′f' = m (x - x^*)^{m-1} g + (x - x^*)^m g', and

f(xk)f′(xk)=ek gmg+ekg′≈ekm,ek+1≈(1−1m)ek.\frac{f(x_k)}{f'(x_k)} = \frac{e_k\, g}{m g + e_k g'} \approx \frac{e_k}{m}, \qquad e_{k+1} \approx \left(1 - \frac1m\right) e_k .

The step xk+1=xk−mf(xk)/f′(xk)x_{k+1} = x_k - m f(x_k)/f'(x_k) removes all of eke_k to first order, and order 2 returns. The catch is that mm must be known; a steady ratio ρ\rho estimates it as m≈1/(1−ρ)m \approx 1/(1 - \rho).

When Newton at a multiple root breaks
  • Assumes: f′(x∗)≠0f'(x^*) \ne 0
  • When it fails: the order drops to 1 with ratio (m−1)/m(m - 1)/m, and a double root in a form that cancels can be located only to about ϵ\sqrt{\epsilon}
  • Check: a steady ratio ρ\rho of successive errors or steps gives m≈1/(1−ρ)m \approx 1/(1 - \rho); use the step mf/f′m f / f' with that mm

5. The secant method: no derivative

Setting: the problem, its sets and its symbols

Problem. Given f∈C2(R)f \in C^2(\mathbb{R}) with a simple root x∗x^* and two starts x0,x1x_0, x_1, using values of ff only, find iterates xk→x∗x_k \to x^*, the order pp of the iteration, and which of it and Newton reaches a given error with less work WW.

Symbol In Meaning
ff C2(R)C^2(\mathbb{R}) here x2−2x^2 - 2
x∗x^* R\mathbb{R} the simple root; here 2\sqrt2
x0,x1x_0, x_1 R\mathbb{R} the two starts; here 11 and 22
xkx_k R\mathbb{R} the kk-th iterate
eke_k R\mathbb{R} the error xk−x∗x_k - x^*
pp (0,∞)(0, \infty) the observed order (the unknown)
cc [0,2][0, 2] the cost of one f′f', in evaluations of ff; the slider sets it
WW [0,∞)[0, \infty) the work so far, in evaluations of ff
[a,b][a, b] ⊂R\subset \mathbb{R} a bracket with f(a)f(b)<0f(a) f(b) \lt 0, for Brent's method; here [1,2][1, 2]
How these symbols connect

Using only values of f∈C2(R)f \in C^2(\mathbb{R}) and two starts x0,x1∈Rx_0, x_1 \in \mathbb{R}, the secant rule constructs xk+1x_{k+1} from the line through (xk−1,f(xk−1))(x_{k-1}, f(x_{k-1})) and (xk,f(xk))(x_k, f(x_k)), producing errors ek=xk−x∗e_k = x_k - x^* in the units of xx. Those errors give the unknown dimensionless order pp and let us plot error against work WW (measured in evaluations of ff), with the slider cc pricing one Newton derivative f′f' relative to ff. Pairing a sign-change bracket [a,b][a, b] with derivative-free interpolation then leads to Brent's method.

Symbol-by-symbol notes
$x\lt em>0, x\lt /em>1$ — why two starts are needed

Replacing f′(xk)f'(x_k) with the secant slope (f(xk)−f(xk−1))/(xk−xk−1)(f(x_k) - f(x_{k-1})) / (x_k - x_{k-1}) needs two distinct starts x0≠x1x_0 \ne x_1 with f(x0)≠f(x1)f(x_0) \ne f(x_1) before the first step. Unlike bisection's [a,b][a, b], x0x_0 and x1x_1 do not have to bracket the root.

$c$ and $W$ — relative derivative cost and total work

Both cc and WW are measured in units of one evaluation of ff, putting methods with different step costs on a common axis. Each secant step reuses f(xk−1)f(x_{k-1}) and adds 11 to WW, whereas each Newton step computes both ff and f′f' and adds 1+c1 + c.

$p$ — observed order of the secant iteration

As in §2, p>0p > 0 is dimensionless and estimated from three successive errors by log⁡(∣ek+1∣/∣ek∣)/log⁡(∣ek∣/∣ek−1∣)\log(\lvert e_{k+1} \rvert / \lvert e_k \rvert) / \log(\lvert e_k \rvert / \lvert e_{k-1} \rvert). It measures convergence speed per iteration, before weighting by work WW.

$[a, b]$ — sign-change bracket for Brent's method

Plain secant iterates can wander off without a bracket, just like plain Newton. Brent's method starts from [a,b][a, b] with f(a)f(b)<0f(a) f(b) \lt 0 (as in §1) so every step stays inside a shrinking enclosure of x∗x^*.

Newton needs f′f'. Replace it by the slope of the line through the last two iterates:

xk+1=xk−f(xk) xk−xk−1f(xk)−f(xk−1).x_{k+1} = x_k - f(x_k)\, \frac{x_k - x_{k-1}}{f(x_k) - f(x_{k-1})}.

Each step costs one new evaluation of ff and no derivative. Start from x0=1x_0 = 1, x1=2x_1 = 2.

Predict first. The secant method replaces f′(xk)f'(x_k) by the slope through the last two iterates. On x2−2x^2 - 2 its observed order settles near

Choose a prediction

Check answer (without scripting)

Answer: 1.6. ek+1≈Cekek−1e_{k+1} \approx C e_k e_{k-1} gives p=1+1/pp = 1 + 1/p, the golden ratio (1+5)/2≈1.618(1+\sqrt5)/2 \approx 1.618.

Per step Newton costs one ff and one f′f'; count an f′f' as cc evaluations of ff. The chart in the reveal plots error against total work.

Reveal result (lock in your prediction above first)
k e_k observed order
0 4.14e-01
1 5.86e-01
2 8.09e-02 -5.713
3 1.42e-02 0.878
4 4.21e-04 2.025
5 2.12e-06 1.502
6 3.16e-10 1.667
7 2.22e-16
8 0.00e+00
9 2.22e-16

The first two orders are pre-asymptotic (x1=2x_1 = 2 is further from the root than x0x_0); then they swing about 1.6181.618 until the floor. The reason: the same Taylor argument as §2, with the secant's slope, gives ek+1≈f′′2f′ ekek−1e_{k+1} \approx \frac{f''}{2f'}\, e_k e_{k-1}. Put ek+1≈Aekpe_{k+1} \approx A e_k^p and ek−1≈(ek/A)1/pe_{k-1} \approx (e_k / A)^{1/p}; matching powers of eke_k gives p=1+1/pp = 1 + 1/p, so p2=p+1p^2 = p + 1 and p=(1+5)/2p = (1 + \sqrt5)/2.

13.255.57.751010⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰secantNewtonwork, in evaluations of f|x − √2|

Order per unit of work. One Newton step multiplies the digits by 2 for 1+c1 + c evaluations, so per evaluation by 21/(1+c)=1.4142^{1/(1+c)} = 1.414; the secant method multiplies them by φ=1.618\varphi = 1.618. Newton wins only when c<ln⁡2/ln⁡φ−1=0.44c \lt \ln 2 / \ln \varphi - 1 = 0.44: its derivative must cost less than about half an ff.

Keep the bracket. The secant method has no bracket, so a poor pair of starts can send it away just as Newton is sent. Brent's method keeps a sign-change bracket and takes a secant or inverse-quadratic step when it lands inside, bisecting otherwise: bisection's guarantee at nearly the secant's speed. scipy.optimize.brentq on [1,2][1, 2] with xtol=1e-15 takes 8 iterations and 9 evaluations of ff, error 2.2e-16.

When the secant method breaks
  • Assumes: the two latest points are near a simple root and f(xk)≠f(xk−1)f(x_k) \ne f(x_{k-1})
  • When it fails: with no bracket it leaves a good region as Newton does, and equal residuals give a horizontal secant and a division by zero
  • Check: keep a sign-change bracket and bisect whenever the secant step leaves it, which is what Brent's method does

6. Safeguards and stopping

Setting: the problem, its sets and its symbols

Problem. Given a differentiable f:R→Rf : \mathbb{R} \to \mathbb{R} and a start x0x_0 from which plain Newton may diverge, find step lengths αk∈(0,1]\alpha_k \in (0, 1] such that ∣f(xk+αkdk)∣<∣f(xk)∣\lvert f(x_k + \alpha_k d_k) \rvert \lt \lvert f(x_k) \rvert at every step; and find a stopping test, in tolerances τf\tau_f, τx\tau_x and a cap KK, that bounds the error and not only the residual.

Symbol In Meaning
ff R→R\mathbb{R} \to \mathbb{R} here arctan⁡x\arctan x, root 00; then fsf_s
x0x_0 [0.5,4][0.5, 4] the start for arctan⁡x\arctan x; the slider sets it
dkd_k R\mathbb{R} the Newton direction −f(xk)/f′(xk)-f(x_k)/f'(x_k)
αk\alpha_k (0,1](0, 1] the step length; xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k
xcx_c (1,2)(1, 2) §3's critical start for arctan⁡x\arctan x
fsf_s R→R\mathbb{R} \to \mathbb{R} the rescaled 10s(x2−2)10^s (x^2 - 2), run from x0=3x_0 = 3
ss {−10,…,10}\{-10, \dots, 10\} the scale exponent; the slider sets it
τf\tau_f (0,∞)(0, \infty) the residual tolerance, in the units of ff
τx\tau_x (0,∞)(0, \infty) the relative step tolerance, dimensionless
KK N\mathbb{N} the cap on the number of steps; here 6060
ρ\rho [0,1)[0, 1) the ratio ∣ek+1∣/∣ek∣\lvert e_{k+1} \rvert / \lvert e_k \rvert of a linearly convergent run
rr Rn→Rn\mathbb{R}^n \to \mathbb{R}^n in otkd: the residual vector, root at r=0r = 0
J, δJ,\ \delta Rn×n, Rn\mathbb{R}^{n \times n},\ \mathbb{R}^n in otkd: the Jacobian of rr, and the Newton step solving Jδ=−rJ \delta = -r
How these symbols connect

From a start x0x_0 (including beyond §3's threshold xcx_c for arctan⁡x\arctan x), each step computes the Newton direction dk=−f(xk)/f′(xk)d_k = -f(x_k)/f'(x_k) in the units of xx and scales it by a dimensionless step length αk∈(0,1]\alpha_k \in (0, 1] so xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k reduces ∣f∣\lvert f \rvert; in otkd's vector solver, the residual r:Rn→Rnr : \mathbb{R}^n \to \mathbb{R}^n and its Jacobian J∈Rn×nJ \in \mathbb{R}^{n \times n} define the Newton step δ∈Rn\delta \in \mathbb{R}^n via Jδ=−rJ \delta = -r. For stopping, the rescaled family fs(x)=10s(x2−2)f_s(x) = 10^s(x^2 - 2) contrasts a residual test in τf\tau_f (units of ff) against a dimensionless relative step test in τx\tau_x, both bounded by the step cap KK and adjusted by ρ\rho when convergence is linear.

Symbol-by-symbol notes
$d\lt em>k$ and $\alpha\lt /em>k$ — Newton direction vs step length

dk=−f(xk)/f′(xk)d_k = -f(x_k)/f'(x_k) is the full tangent step in the units of xx, while αk∈(0,1]\alpha_k \in (0, 1] is a dimensionless scaling factor. Taking αk=1\alpha_k = 1 gives plain Newton; reducing αk\alpha_k keeps the same descent direction while preventing overshoot.

$f_s$ and $s$ — rescaled test function

Multiplying x2−2x^2 - 2 by 10s10^s leaves the roots ±2\pm \sqrt2 and every Newton direction dk=−fs(xk)/fs′(xk)d_k = -f_s(x_k)/f_s'(x_k) unchanged because 10s10^s cancels in the quotient. Sweeping s∈{−10,…,10}s \in \{-10, \dots, 10\} mimics changing the units of ff across twenty orders of magnitude.

$\tau\lt em>f$ vs $\tau\lt /em>x$ — residual tolerance vs relative step tolerance

τf\tau_f is compared against ∣f(xk)∣\lvert f(x_k) \rvert, so it carries the units of ff and shifts whenever ff is rescaled. τx\tau_x is dimensionless and tests ∣xk+1−xk∣<τx(1+∣xk+1∣)\lvert x_{k+1} - x_k \rvert \lt \tau_x (1 + \lvert x_{k+1} \rvert), acting as an absolute tolerance near 00 and a relative one for large ∣x∣\lvert x \rvert.

$K$ and $\rho$ — iteration cap and linear-rate correction

K∈NK \in \mathbb{N} ensures the solver always terminates even when a tolerance is unreachable due to scaling or rounding noise. When errors shrink linearly with ratio ρ∈[0,1)\rho \in [0, 1), a single step ∣xk+1−xk∣\lvert x_{k+1} - x_k \rvert underestimates the remaining error whenever ρ\rho is close to 11.

$r$, $J$ and $\delta$ — multidimensional Newton in otkd

In nn unknowns, the scalar function ff becomes a vector residual r:Rn→Rnr : \mathbb{R}^n \to \mathbb{R}^n, the derivative f′f' becomes the n×nn \times n Jacobian matrix JJ, and dividing by f′f' becomes solving Jδ=−rJ \delta = -r for the vector step δ∈Rn\delta \in \mathbb{R}^n. Do not confuse this vector step δ\delta with §2's scalar derivative error.

Far from the root Newton's direction is still right when its length is not. Along d=−f(x)/f′(x)d = -f(x)/f'(x),

ddαf(x+αd)2∣α=0=2f(x)f′(x) d=−2f(x)2<0,\frac{\mathrm d}{\mathrm d\alpha} f(x + \alpha d)^2 \Big|_{\alpha = 0} = 2 f(x) f'(x)\, d = -2 f(x)^2 \lt 0,

so some step x+αdx + \alpha d with 0<α≤10 \lt \alpha \le 1 makes ∣f∣|f| smaller, unless ff is already zero. Two ways to use that:

The test is arctan⁡x\arctan x from §3, where plain Newton diverges from beyond xcx_c.

0510152010⁻¹⁰10⁻⁶10⁻²10²10⁶plain Newtonfixed α = 0.5backtrackingstep k|x_k| (the root is 0)

Plain Newton ends at x = 3.89e+06 after 6 steps. Backtracking chose α\alpha = 0.5, 1, 1, 1: short steps while far away, then 1 and a quadratic finish. Fixed damping is still at 1.8e-07 after 20 steps, halving each time.

The two solvers this repository ships make the two choices.

source: `open_textbook.otkd.solvers.newton.newton` — `solvers/otkd/src/open_textbook/otkd/solvers/newton.py:11`

otkd's newton solves Jδ=−rJ \delta = -r (least squares if JJ is singular), then backtracks: α\alpha halves until max⁡∣r∣\max |r| falls, and once α<10−8\alpha \lt 10^{-8} it takes the step anyway. It stops on the residual alone, max⁡∣r∣<10−12\max |r| \lt 10^{-12} by default, which is safe only if the rows are scaled so that 10−1210^{-12} means something.

def newton(
    system: System,
    q0: np.ndarray,
    *,
    rows: list[int] | None = None,
    tol: float = 1e-12,
    max_steps: int = 60,
) -> tuple[np.ndarray, int, list[tuple[np.ndarray, np.ndarray]]]:
    """Solve `rows(q) = 0` from `q0`. Returns the solution, step count and residual history."""
    q = np.array(q0, dtype=float)
    history: list[tuple[np.ndarray, np.ndarray]] = []
    for step in range(max_steps):
        r = system.residual(q, rows)
        history.append((q.copy(), r.copy()))
        error = float(np.max(np.abs(r))) if r.size else 0.0
        if error < tol:
            return q, step, history
        jac = system.jacobian(q, rows)
        try:
            delta = np.linalg.solve(jac, -r)
        except np.linalg.LinAlgError:
            delta, *_ = np.linalg.lstsq(jac, -r, rcond=None)
        if not np.all(np.isfinite(delta)):
            raise SolverError("Newton step is not finite", residual=error)
        base = float(np.max(np.abs(r)))
        alpha = 1.0
        for _ in range(40):
            trial = q + alpha * delta
            if float(np.max(np.abs(system.residual(trial, rows)))) < base or alpha < 1e-8:
                break
            alpha *= 0.5
        q = q + alpha * delta

    r = system.residual(q, rows)
    index = (rows or system.constrained)[int(np.argmax(np.abs(r)))]
    raise SolverError(
        f"Newton did not converge in {max_steps} steps: |r|inf = {np.max(np.abs(r)):.3e}, "
        f"worst row {system.problem.rows[index].name}",
        residual=float(np.max(np.abs(r))),
    )
source: solvers/ot-solve/src/kernels/newton.rs:90-125

The browser kernel solves x3−2x−5=0x^3 - 2x - 5 = 0 with a fixed damping factor from a slider (0.1 to 1.5). It flags convergence at ∣f∣<10−12|f| \lt 10^{-12} and reports Unstable once ∣x∣>106|x| > 10^6. A factor above 1 overshoots: ek+1≈(1−α)eke_{k+1} \approx (1 - \alpha) e_k changes sign every step.

pub fn step(a: &mut Arena<'_>) -> Status {
    let damping = a.params()[P_DAMPING];
    if !damping.is_finite() || damping <= 0.0 {
        return Status::BadParameter;
    }
    let iteration = a.diag()[D_ITER] as usize;
    let converged = a.diag()[D_CONVERGED] > 0.0;
    if converged {
        return Status::Ok;
    }
    let (x, f, df) = {
        let state = a.state();
        (state[S_X], state[S_F], state[S_DF])
    };
    if df == 0.0 || !df.is_finite() {
        return Status::NotConverged;
    }
    let next = x - damping * f / df;
    let (next_f, next_df) = evaluate(next);
    let state = a.state_mut();
    state[S_X] = next;
    state[S_F] = next_f;
    state[S_DF] = next_df;
    let slot = (iteration + 1).min(HISTORY - 1);
    let out = a.out_mut();
    out[O_X + slot] = next;
    out[O_F + slot] = next_f;
    let diag = a.diag_mut();
    diag[D_ITER] += 1.0;
    diag[D_RESIDUAL] = next_f;
    diag[D_CONVERGED] = if next_f.abs() < 1.0e-12 { 1.0 } else { 0.0 };
    if !next.is_finite() || next.abs() > 1.0e6 {
        return Status::Unstable;
    }
    Status::Ok
}

Stopping. Three tests are in use: the residual ∣f(xk)∣<τf|f(x_k)| \lt \tau_f, the step ∣xk+1−xk∣<τx(1+∣xk+1∣)|x_{k+1} - x_k| \lt \tau_x (1 + |x_{k+1}|), and a cap on the number of steps. The residual reads ∣f∣≈∣f′(x∗)∣ ∣ek∣|f| \approx |f'(x^*)|\, |e_k|, the error times the slope, so its meaning changes with the units of ff. The step measures xx itself. For Newton ∣xk+1−xk∣≈∣ek∣|x_{k+1} - x_k| \approx |e_k|, which overstates the error of xk+1x_{k+1} (about Cek2C e_k^2), so the step test is safe. At a linear rate ρ\rho the error left is ρ1−ρ\frac{\rho}{1 - \rho} steps, so a slow run needs a tighter step test.

Rescale ff and run Newton from 3 with τf=τx=10−8\tau_f = \tau_x = 10^{-8} and a cap of 60.

test steps error at stop
residual ∣f∣<10−8\lvert f\rvert \lt 10^{-8} 0 1.59e+00
relative step <10−8\lt 10^{-8} 6 2.22e-16

The step test does not notice the units. The residual test stops at once when ff is small everywhere, and never when ff is so large that one spacing of xx at the root moves it by more than 10−810^{-8}.

When damping and the line search breaks
  • Assumes: the Newton step is a descent direction for ∣f∣|f|, which holds whenever f≠0f \ne 0 and f′f' is right and non-zero
  • When it fails: at a local minimum of ∣f∣|f| that is not a root, α\alpha shrinks to its floor and the run stalls with ∣f∣>0|f| > 0
  • Check: watch α\alpha: a collapse to its floor means a residual minimum, not a root; restart elsewhere or continue from a solved case

Practice

Practice A (steps partly filled). Bisection shrinks a bracket of width 1 to width 10−610^{-6}. After kk halvings the width is 2−k2^{-k}, so you need k≥log⁡2106=6log⁡210≈  ?k \ge \log_2 10^6 = 6 \log_2 10 \approx \;?, rounded up. Enter kk.

Worked solution

log⁡2106≈19.93\log_2 10^6 \approx 19.93, so k=20k = 20, and 2−20≈9.54e−07≤10−62^{-20} \approx 9.54e-07 \le 10^{-6}.

Practice B (with a hint). The browser kernel's cubic is f(x)=x3−2x−5f(x) = x^3 - 2x - 5. Take one Newton step from x0=2x_0 = 2. Enter x1x_1.

Worked solution

f(2)=−1f(2) = -1, f′(2)=10f'(2) = 10, so x1=2+0.1=2.1x_1 = 2 + 0.1 = 2.1. The root is 2.0945514815: the error fell from 0.0946 to 0.0054.

Hint 1

x1=x0−f(x0)/f′(x0)x_1 = x_0 - f(x_0)/f'(x_0), with f′(x)=3x2−2f'(x) = 3x^2 - 2.

Hint 2

f(2)=8−4−5f(2) = 8 - 4 - 5 and f′(2)=12−2f'(2) = 12 - 2.

Practice C (on your own). On a smooth ff with a checked derivative, Newton's successive errors settle into a constant ratio ek+1/ek=0.75e_{k+1}/e_k = 0.75. Enter the multiplicity mm of the root.

Worked solution

(m−1)/m=0.75(m - 1)/m = 0.75 gives m=1/(1−0.75)=4m = 1/(1 - 0.75) = 4. The step 4f/f′4 f/f' restores order 2.

Mixed practice: which method, and why?

1. ff is the output of a simulation that takes a minute per call. There is no derivative; you know f(0)<0<f(1)f(0) \lt 0 \lt f(1) and need six digits you can rely on. Use

Question 1
How sure?

2. Your Newton solver's error ratios ek+1/eke_{k+1}/e_k read 0.09, 0.09, 0.09. What do you check first?

Question 2
How sure?

3. You want to confirm a new root solver is quadratic, but you have no exact root. What do you compute?

Question 3
How sure?

Show answers and explanations

1. Brent's method on the bracket. It keeps the sign change, so it cannot lose the root, and takes secant or inverse-quadratic steps when they land inside: certainty at nearly secant speed.

2. the derivative code, against a central difference. A steady ratio δ/(1+δ)=0.09\delta/(1+\delta) = 0.09 means δ≈0.1\delta \approx 0.1: f′f' is off by about 10%. M01's central difference checks it in one line.

3. the observed order from successive step sizes. sk=∣xk+1−xk∣s_k = |x_{k+1} - x_k| tracks eke_k, so log⁡(sk+1/sk)/log⁡(sk/sk−1)\log(s_{k+1}/s_k) / \log(s_k/s_{k-1}) estimates pp, as M01 §4 used differences between runs.

Check yourself (closed book)

1. Bisection starts from a bracket of width 1. About how many halvings shrink it to 10−610^{-6}?

Question 1
How sure?

2. Near a simple root, Newton's error is 10−310^{-3}. After one more step it is about

Question 2
How sure?

3. Newton on f(x)=x3−xf(x) = x^3 - x from x0=0.5x_0 = 0.5 lands on the root at −1-1 in one step, though 0 and 1 are closer. Why?

Question 3
How sure?

4. Newton's errors read 0.04, 0.02, 0.01, 0.005 on a function whose derivative you have checked against a central difference. The likeliest cause is

Question 4
How sure?

5. Why is the secant method's order about 1.618 rather than Newton's 2?

Question 5
How sure?

6. A backtracking line search halves the Newton step until ∣f∣|f| falls. Near a simple root it

Question 6
How sure?

7. A Newton solver stops when ∣f(x)∣<10−8|f(x)| \lt 10^{-8}. You change units so that ff is multiplied by 10−1010^{-10}. What happens?

Question 7
How sure?

Show answers and explanations

1. 20. The width after kk halvings is 2−k2^{-k}, and 220≈1.05×1062^{20} \approx 1.05 \times 10^6: k=⌈log⁡2106⌉=20k = \lceil \log_2 10^6 \rceil = 20.

2. a constant times 1e-6. ek+1≈f′′2f′ek2e_{k+1} \approx \frac{f''}{2f'} e_k^2: the error is squared, so the number of correct digits roughly doubles each step.

3. The tangent at 0.5 is shallow, so its crossing lies far away. f(0.5)=−0.375f(0.5) = -0.375 and f′(0.5)=−0.25f'(0.5) = -0.25, so the step is −1.5-1.5. A small slope turns a modest residual into a long jump.

4. the root is a double root. At a root of multiplicity mm, ek+1≈m−1meke_{k+1} \approx \frac{m-1}{m} e_k; a ratio of 12\tfrac12 means m=2m = 2. With mm known, the step mf/f′m f/f' restores order 2.

5. Its new error is proportional to the product of the last two errors. ek+1≈Cekek−1e_{k+1} \approx C e_k e_{k-1}. Trying ek+1∼ekpe_{k+1} \sim e_k^p gives p=1+1/pp = 1 + 1/p, so p=(1+5)/2p = (1 + \sqrt5)/2.

6. accepts the full step, so convergence stays quadratic. Near the root the full step already reduces ∣f∣|f|, so α=1\alpha = 1 is accepted and the quadratic rate survives. The search acts only far from the root.

7. It can stop at once, far from the root. ∣f∣|f| is now below 10−810^{-8} almost everywhere. A residual test means something only in units where the tolerance does; pair it with a relative step test.

Keep these:

  1. Bisection is certain given a sign change: ⌈log⁡2((b−a)/τ)⌉\lceil \log_2((b-a)/\tau) \rceil steps, one bit each, whatever ff is.
  2. Newton squares the error near a simple root, ek+1≈f′′2f′ek2e_{k+1} \approx \frac{f''}{2f'} e_k^2; measure pp from successive errors or steps.
  3. Newton's convergence is local: a start can land on a far root, cycle or diverge, so ∣f∣|f| should fall at every step.
  4. A root of multiplicity mm makes Newton linear with ratio (m−1)/m(m-1)/m; the step mf/f′m f/f' restores order 2.
  5. The secant method has order 1.6181.618 for one ff per step, and beats Newton when f′f' costs more than about 0.440.44 of an ff.
  6. Backtracking keeps Newton safe far away and quadratic near the root; stop on a relative step and a residual in units that mean something.

Your connection

Where does a root finder run in something you use or maintain (otkd's assembly solve, a spreadsheet's goal seek, a CAD sketch)? What does it stop on, and what would a double root do to it?

Answers

Practice A. k=20k = 20.

Practice B. x1=2.1x_1 = 2.1.

Practice C. m=4m = 4.

Mixed practice. Brent's method; the derivative code; the observed order from successive steps.

Where the maths is derived

Optional. These notes give the intuition and application; the sources below give the full derivations and proofs.

§2 Newton's method

§5 The secant method

§6 Damping, line search and stopping

§4 Multiple roots


Compiled from notebooks/methods/m02_root_finding.py — run locally with cd notebooks && uv run marimo edit methods/m02_root_finding.py for live Python scratch cells.

Back to the book: Root finding · Why Newton is fast, and when it is not

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Reading offline

Keep this book on this device and read it offline.