Numerical Methods

All books

M01 — Error, tolerance and order of convergence

Every number a solver returns is wrong. The useful questions are how wrong, how fast the error shrinks when you work harder, and when working harder stops helping. This notebook answers them with the smallest possible example: the derivative of exe^x at x=1x = 1, whose exact value ee you know.

Book pages: Error, and what a tolerance is and Convergence, and how to measure it in books/numerical-methods.

The question. You approximate f′(1)f'(1) for f(x)=exf(x) = e^x with a difference quotient and a step hh. Does a smaller hh always give a better answer?

By the end you can:

  • say what machine epsilon bounds, and why relative error is the measure
  • spot a cancellation and remove it by rewriting the formula
  • read the order pp off a convergence table, and say why halving hh divides the error by 2p2^p
  • estimate the order and an improved answer with no exact solution (Richardson)
  • explain the round-off floor and find the best step h∼ϵ1/(p+1)h \sim \epsilon^{1/(p+1)}

Assumes: Taylor series to the third term, and logarithms base 2.

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: as hh goes from 10−110^{-1} down to 10−1510^{-15}, the error of the central difference

Choose a prediction

Check answer (without scripting)

Answer: falls, then rises again below some step. Truncation error Ch2Ch^2 falls with hh, but rounding contributes about ϵ/h\epsilon/h, which rises. Their sum is a V with its floor near h=10−5h = 10^{-5}.

1. Relative error and machine epsilon

Setting: the problem, its sets and its symbols

Problem. Given a true value x∈R∖{0}x \in \mathbb{R} \setminus \{0\} and a computed value x^∈F\hat x \in \mathbb{F}, measure the error of x^\hat x on a scale that does not depend on the magnitude of xx; and, for the rounding map fl:R→F\mathrm{fl} : \mathbb{R} \to \mathbb{F}, find a bound uu such that fl(x)=x(1+δ)\mathrm{fl}(x) = x(1 + \delta) with ∣δ∣≤u\lvert \delta \rvert \le u for every xx in the range of F\mathbb{F}.

Symbol In Meaning
F\mathbb{F} ⊂R\subset \mathbb{R} the finite IEEE 754 doubles: 53 significant bits
xx R∖{0}\mathbb{R} \setminus \{0\} the true value (the data)
x^\hat x F\mathbb{F} the computed value
fl\mathrm{fl} R→F\mathbb{R} \to \mathbb{F} round to the nearest double
∣x^−x∣\lvert \hat x - x \rvert [0,∞)[0, \infty) the absolute error, in the units of xx
∣x^−x∣/∣x∣\lvert \hat x - x \rvert / \lvert x \rvert [0,∞)[0, \infty) the relative error, dimensionless
gap⁡\operatorname{gap} F→(0,∞)\mathbb{F} \to (0, \infty) the distance from a double to the next larger one
ϵ\epsilon F\mathbb{F} machine epsilon: gap⁡(1)\operatorname{gap}(1)
δ, u\delta,\ u R\mathbb{R} the relative rounding error of one operation, and its bound (the unknown)
kk {−20,…,20}\{-20, \dots, 20\} the slider: the table's xx is 10k10^k
κ\kappa R∖{0}→[0,∞)\mathbb{R} \setminus \{0\} \to [0, \infty) the condition number of ff at xx, dimensionless
ff R→R\mathbb{R} \to \mathbb{R} the function being evaluated; here f(x)=exf(x) = e^x
How these symbols connect

A real input x∈R∖{0}x \in \mathbb{R} \setminus \{0\} is mapped by fl:R→F\mathrm{fl} : \mathbb{R} \to \mathbb{F} to a computed double x^=x(1+δ)\hat x = x(1 + \delta), giving either the absolute error ∣x^−x∣\lvert \hat x - x \rvert (in the units of xx) or the dimensionless relative error ∣x^−x∣/∣x∣=∣δ∣\lvert \hat x - x \rvert / \lvert x \rvert = \lvert \delta \rvert. The unknown rounding bound uu caps ∣δ∣\lvert \delta \rvert across the range of F\mathbb{F}, anchored by gap⁡(x)\operatorname{gap}(x) and ϵ=gap⁡(1)\epsilon = \operatorname{gap}(1) as the slider kk sweeps x=10kx = 10^k. Passing xx into f:R→Rf : \mathbb{R} \to \mathbb{R} then links relative input error to relative output error through the dimensionless condition number κ(x)\kappa(x).

Symbol-by-symbol notes
$\mathbb{F}$ and $\mathrm{fl}$ — finite doubles and rounding

F\mathbb{F} is a finite subset of R\mathbb{R} whose spacing scales with magnitude rather than staying uniform. The map fl\mathrm{fl} rounds each real value in range to the nearest element of F\mathbb{F}, producing x^\hat x.

$\lvert \hat x - x \rvert$ vs $\lvert \hat x - x \rvert / \lvert x \rvert$ — absolute vs relative error

Absolute error keeps the units and scale of xx, so a fixed value means very different accuracy at 10−810^{-8} and 10810^{8}. Dividing by ∣x∣\lvert x \rvert removes the units and scale, which requires x≠0x \ne 0.

$\epsilon$, $\operatorname{gap}(x)$, $\delta$ and $u$ — spacing vs rounding bound

gap⁡(x)\operatorname{gap}(x) is the distance from a double xx to the next larger double, and ϵ=gap⁡(1)\epsilon = \operatorname{gap}(1) is that spacing at 11. Do not confuse ϵ\epsilon with uu: δ\delta is the signed relative error of one rounding, while uu (unit round-off) bounds ∣δ∣\lvert \delta \rvert.

$\kappa$ — condition number of $f$ at $x$

κ(x)\kappa(x) belongs to the mathematical map ff at xx, not to the algorithm or to floating-point arithmetic. It is dimensionless because it compares relative output change to relative input change, and requires x≠0x \ne 0 and f(x)≠0f(x) \ne 0.

Write the true value as xx and the computed value as x^\hat x. The absolute error ∣x^−x∣|\hat x - x| is no verdict on its own: 10−810^{-8} is large next to 10−810^{-8} and tiny next to 10810^{8}. The measure that travels is the relative error

∣x^−x∣∣x∣.\frac{|\hat x - x|}{|x|}.

A double keeps 53 binary digits. The gap between 1 and the next double is ϵ=2−52≈2.2×10−16\epsilon = 2^{-52} \approx 2.2 \times 10^{-16}, machine epsilon. Each arithmetic operation returns the exact result rounded to a double, so it is within a relative ϵ/2\epsilon/2 of the truth. The gap itself scales with the number: move the slider and watch the absolute gap change while the relative gap stays put.

Figure 1

0.1 + 0.2 == 0.3 is False: the two sides differ by 5.55e-17, one gap at 0.3. Neither 0.1 nor 0.2 is a double; each was rounded on the way in. Compare floats with a relative tolerance, never with ==.

Conditioning. Some problems amplify an input error whoever solves them. The condition number κ(x)=∣xf′(x)/f(x)∣\kappa(x) = |x f'(x) / f(x)| is the factor: for exe^x it is ∣x∣|x|, so at x=10x = 10 an input rounded by ϵ\epsilon gives an answer good to about 10ϵ10\epsilon. That loss belongs to the question, not to the method.

2. Cancellation

Setting: the problem, its sets and its symbols

Problem. Given x∈F∩[10−16,10−1]x \in \mathbb{F} \cap [10^{-16}, 10^{-1}] and g:[0,∞)→Rg : [0, \infty) \to \mathbb{R}, g(x)=1+x−1g(x) = \sqrt{1+x} - 1, find a formula for gg, equal to it in exact arithmetic, whose evaluation in F\mathbb{F} has a relative error of order ϵ\epsilon for every such xx.

Symbol In Meaning
F\mathbb{F} ⊂R\subset \mathbb{R} the finite doubles
ϵ\epsilon F\mathbb{F} machine epsilon, 2−522^{-52}
xx F∩[10−16,10−1]\mathbb{F} \cap [10^{-16}, 10^{-1}] the argument (the data), dimensionless
gg [0,∞)→R[0, \infty) \to \mathbb{R} the exact function
g^\hat g F→F\mathbb{F} \to \mathbb{F} gg evaluated operation by operation in doubles, for a given formula
∣g^(x)−g(x)∣/g(x)\lvert \hat g(x) - g(x) \rvert / g(x) [0,∞)[0, \infty) the relative error, against a 50-digit decimal reference for g(x)g(x)
How these symbols connect

Each dimensionless input x∈F∩[10−16,10−1]x \in \mathbb{F} \cap [10^{-16}, 10^{-1}] passes into both the exact function g:[0,∞)→Rg : [0, \infty) \to \mathbb{R} and a floating-point evaluation g^:F→F\hat g : \mathbb{F} \to \mathbb{F} defined by a specific algebraic formula executed in F\mathbb{F}. Two formulas that represent the same exact gg can yield very different maps g^\hat g once each intermediate operation rounds. Measuring the dimensionless relative error ∣g^(x)−g(x)∣/g(x)\lvert \hat g(x) - g(x) \rvert / g(x) tests whether a formula stays within order ϵ\epsilon across the whole domain.

Symbol-by-symbol notes
$g$ vs $\hat g$ — exact function vs floating-point evaluation

gg is the mathematical map x↦1+x−1x \mapsto \sqrt{1+x} - 1, whereas g^\hat g depends on the exact sequence of rounded operations in F\mathbb{F}. An algebraic rewrite leaves gg unchanged while replacing g^\hat g with a different finite-precision map.

$x \in \mathbb{F} \cap [10^{-16}, 10^{-1}]$ — exact small inputs

Taking x∈Fx \in \mathbb{F} means the input itself needs no initial rounding, so every digit lost comes from evaluating the formula. The lower end 10−1610^{-16} sits just below ϵ=2−52≈2.2×10−16\epsilon = 2^{-52} \approx 2.2 \times 10^{-16}.

$\lvert \hat g(x) - g(x) \rvert / g(x)$ — relative error against the reference

Since g(x)>0g(x) > 0 on [10−16,10−1][10^{-16}, 10^{-1}], no absolute-value bars are needed in the denominator. Evaluating 1+x−1\sqrt{1+x} - 1 to 50 decimal digits supplies an exact reference for g(x)g(x) independent of double-precision rounding.

Compute 1+x−1\sqrt{1+x} - 1 at x=10−16x = 10^{-16}. The true value is about 5×10−175 \times 10^{-17}. But 1+10−161 + 10^{-16} rounds to exactly 1, its square root is 1, and the subtraction returns 0. Each operand was accurate to ϵ\epsilon; their difference kept none of their digits.

The cure is algebra, not more precision. Multiply by the conjugate:

1+x−1=x1+x+1.\sqrt{1+x} - 1 = \frac{x}{\sqrt{1+x} + 1}.

The right side divides two numbers of size about 1 and xx, with no subtraction of nearly equal values. The chart compares both against a 50-digit decimal reference, with values below machine epsilon clipped to the floor ϵ\epsilon.

10⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁻¹⁶10⁻¹²10⁻⁸10⁻⁴10⁰√(1+x) − 1x / (√(1+x) + 1)xrelative error
When the rewritten formula breaks
  • Assumes: the rewrite removes the subtraction of nearly equal numbers
  • When it fails: a rewrite that only reorders the same subtraction loses the same digits
  • Check: compare both forms over xx from 10−110^{-1} to 10−1610^{-16}: the stable one stays at relative error near ϵ\epsilon

3. Order of convergence

Setting: the problem, its sets and its symbols

Problem. Given f∈C3(R)f \in C^3(\mathbb{R}), here f(x)=exf(x) = e^x, the point x=1x = 1, and a difference quotient D:(0,∞)→RD : (0, \infty) \to \mathbb{R} that approximates f′(x)f'(x), find the order p>0p > 0 and the constant CC, independent of hh, such that E(h)=Chp+O(hp+1)E(h) = C h^p + O(h^{p+1}) as h→0h \to 0.

Symbol In Meaning
ff C3(R)C^3(\mathbb{R}) the function differentiated; here exe^x
xx R\mathbb{R} the point; here 11, so f′(x)=ef'(x) = e exactly
hh {0.2⋅2−j}⊂(0,0.2]\{0.2 \cdot 2^{-j}\} \subset (0, 0.2] the step
jj {0,…,n−1}\{0, \dots, n - 1\} the halving index
nn {3,…,12}\{3, \dots, 12\} the slider: the number of steps tabulated
D+(h)D_+(h) R\mathbb{R} the forward difference (f(x+h)−f(x))/h(f(x+h) - f(x))/h
Dc(h)D_c(h) R\mathbb{R} the central difference (f(x+h)−f(x−h))/(2h)(f(x+h) - f(x-h))/(2h)
EE (0,∞)→[0,∞)(0, \infty) \to [0, \infty) the error ∣D(h)−f′(x)∣\lvert D(h) - f'(x) \rvert of a quotient
pp (0,∞)(0, \infty) the order (an unknown)
CC R\mathbb{R} the leading constant: depends on ff and xx, not on hh (an unknown)
How these symbols connect

Given a smooth function f∈C3(R)f \in C^3(\mathbb{R}) and a fixed point x∈Rx \in \mathbb{R}, each step h=0.2⋅2−jh = 0.2 \cdot 2^{-j} (for j=0,…,n−1j = 0, \dots, n - 1) feeds into a difference quotient D+(h)D_+(h) or Dc(h)D_c(h) to approximate f′(x)f'(x). Subtracting the exact derivative produces the error E(h)=∣D(h)−f′(x)∣E(h) = \lvert D(h) - f'(x) \rvert in the units of f′(x)f'(x). Matching E(h)E(h) to Chp+O(hp+1)C h^p + O(h^{p+1}) as hh is repeatedly halved yields the two unknowns: the dimensionless order pp and the leading constant CC.

Symbol-by-symbol notes
$f \in C^3(\mathbb{R})$ — smoothness requirement

C3(R)C^3(\mathbb{R}) is the set of functions with continuous first, second and third derivatives on R\mathbb{R}. That smoothness ensures Taylor expansions around xx carry a well-behaved cubic remainder.

$D\lt em>+(h)$ vs $D\lt /em>c(h)$ — one-sided vs symmetric quotients

D+(h)D_+(h) samples ff on one side at xx and x+hx + h, whereas Dc(h)D_c(h) samples symmetrically at x−hx - h and x+hx + h across a span of 2h2h. Both return approximations in the units of f′(x)f'(x).

$E(h) = C h^p + O(h^{p+1})$ — error model, $p$ and $C$

O(hp+1)O(h^{p+1}) collects all higher-order terms that shrink at least as fast as hp+1h^{p+1} as h→0h \to 0. The order p>0p > 0 is dimensionless and sets how fast E(h)E(h) shrinks with hh, while CC depends on ff and xx (not hh) and carries units of f′(x)/hpf'(x) / h^p.

$h = 0.2 \cdot 2^{-j}$ — geometric step sequence

Each increment of jj halves hh, giving a geometric sequence of step sizes rather than a uniform grid. Comparing errors at hh and h/2h/2 eliminates CC once hh is small enough that O(hp+1)O(h^{p+1}) is negligible.

Write the error after a step hh as

E(h)=Chp+O(hp+1).E(h) = C h^p + O(h^{p+1}).

pp is the order; CC depends on the problem but not on hh. Halving hh divides the leading term by 2p2^p, so with errors at hh and h/2h/2

p≈log⁡2E(h)E(h/2).p \approx \log_2 \frac{E(h)}{E(h/2)}.

Taylor's theorem gives the two classic orders. The forward difference f(x+h)−f(x)h=f′(x)+h2f′′(x)+O(h2)\frac{f(x+h) - f(x)}{h} = f'(x) + \frac{h}{2} f''(x) + O(h^2) has p=1p = 1. In the central difference f(x+h)−f(x−h)2h\frac{f(x+h) - f(x-h)}{2h} the even terms cancel, leaving −h26f′′′(x)-\frac{h^2}{6} f'''(x), so p=2p = 2. On log–log axes an error ChpC h^p is a straight line of slope pp.

Figure 2

Predict first. In the asymptotic region, halving hh divides the central-difference error by about

Choose a prediction

Check answer (without scripting)

Answer: 4. Order 2: the factor is 222^2. The central order column settles at 2.00.

Reveal result (lock in your prediction above first)
10⁻²10⁻¹10⁻⁵10⁻⁴10⁻³10⁻²10⁻¹forwardcentralstep h|error|
h forward central forward order central order
0.2 0.2909 0.01816 — —
0.1 0.1406 0.004533 1.049 2.002
0.05 0.0691 0.001133 1.024 2.001
0.025 0.03426 0.0002832 1.012 2
0.0125 0.01706 7.079e-05 1.006 2
0.00625 0.008512 1.770e-05 1.003 2

The first forward order is 1.05, not 1.00: at h=0.1h = 0.1 the h2h^2 term is not yet negligible. That is the pre-asymptotic region, visible in one row.

When the observed order breaks
  • Assumes: the function is smooth enough for the Taylor expansion behind ChpC h^p
  • When it fails: at a kink or a discontinuity the expansion does not exist and the observed order drops (a second-order method reads as first order or worse)
  • Check: the observed order should settle over at least two refinements

4. Richardson: the order with no exact answer

Setting: the problem, its sets and its symbols

Problem. Given three computed values fh,fh/2,fh/4∈Ff_h, f_{h/2}, f_{h/4} \in \mathbb{F} of a method whose error is fh−f0=Chp+O(hp+1)f_h - f_0 = C h^p + O(h^{p+1}), with the limit f0f_0, the order pp and the constant CC all unknown, find estimates of pp and of f0f_0.

Symbol In Meaning
hh [10−4,10−0.5][10^{-4}, 10^{-0.5}] the coarsest of the three steps; the slider sets log⁡10h\log_{10} h
fhf_h F\mathbb{F} the method's value at step hh; here the central difference of exe^x at 11
f0f_0 R\mathbb{R} the limit as h→0h \to 0 (the unknown answer; here ee, used only to score the estimate)
pp (0,∞)(0, \infty) the order (an unknown)
CC R\mathbb{R} the leading constant, independent of hh (an unknown)
F\mathbb{F} ⊂R\subset \mathbb{R} the finite doubles
How these symbols connect

From one coarsest step h∈[10−4,10−0.5]h \in [10^{-4}, 10^{-0.5}], evaluating the method in F\mathbb{F} at the three nested steps hh, h/2h/2 and h/4h/4 yields three computed values fh,fh/2,fh/4f_h, f_{h/2}, f_{h/4}, all in the units of the target limit f0f_0. Because all three share the expansion fh−f0=Chp+O(hp+1)f_h - f_0 = C h^p + O(h^{p+1}) with unknowns (f0,p,C)(f_0, p, C), pairwise differences eliminate f0f_0, their ratio eliminates CC to estimate the dimensionless order pp, and combining two runs with that pp extrapolates f0f_0.

Symbol-by-symbol notes
$f\lt em>h$ vs $f\lt /em>0$ — computed method output vs exact limit

Here fh∈Ff_h \in \mathbb{F} is the numerical method's output at step hh (not §3's underlying function f(x)f(x) evaluated at hh). The subscript 00 in f0∈Rf_0 \in \mathbb{R} marks the h→0h \to 0 limit that is unknown in practice.

$h$, $h/2$, $h/4$ — why three nested runs are needed

The leading model fh≈f0+Chpf_h \approx f_0 + C h^p contains three unknowns: f0f_0, CC and pp. Two steps leave pp undetermined; a third halved step supplies a second difference whose ratio with the first cancels both f0f_0 and CC.

$h \in [10^{-4}, 10^{-0.5}]$ — coarsest step and slider

The slider sets log⁡10h\log_{10} h, so the three runs use (h,h/2,h/4)(h, h/2, h/4) with hh the coarsest of the trio. Because fhf_h lives in F\mathbb{F}, the expansion holds only where truncation error dominates both the O(hp+1)O(h^{p+1}) remainder and floating-point rounding.

In real work the exact answer is the thing you do not have, so E(h)E(h) is unknown. But differences of computed values carry the same leading term: fh−fh/2≈Chp(1−2−p)f_h - f_{h/2} \approx C h^p (1 - 2^{-p}). Three runs give

p≈log⁡2∣fh−fh/2∣∣fh/2−fh/4∣,f0≈fh/2+fh/2−fh2p−1.p \approx \log_2 \frac{|f_h - f_{h/2}|}{|f_{h/2} - f_{h/4}|}, \qquad f_0 \approx f_{h/2} + \frac{f_{h/2} - f_h}{2^p - 1}.

The second formula extrapolates: it subtracts the estimated leading error and gains an order for free. Move hh: the estimate is good in the asymptotic region and falls apart near round-off.

Figure 3
When Richardson extrapolation breaks
  • Assumes: the leading error term is ChpC h^p with the same pp at all three steps
  • When it fails: pre-asymptotic or round-off rows give an unstable pp, and the extrapolated value is then no more accurate
  • Check: estimate pp from two different triples; extrapolate only if they agree

5. The round-off floor

Setting: the problem, its sets and its symbols

Problem. Given f(x)=exf(x) = e^x at x=1x = 1 and the difference quotients D+D_+ and DcD_c evaluated in F\mathbb{F}, where each value of ff carries an absolute rounding error of about ϵ\epsilon, find how the total error E(h)E(h) of the computed quotient behaves as hh decreases over [10−15,10−0.5][10^{-15}, 10^{-0.5}], and the step h∗h^* at which it is smallest.

Symbol In Meaning
F\mathbb{F} ⊂R\subset \mathbb{R} the finite doubles
ϵ\epsilon F\mathbb{F} machine epsilon, 2−522^{-52}
ff C3(R)C^3(\mathbb{R}) here exe^x, evaluated at x=1x = 1
hh [10−15,10−0.5][10^{-15}, 10^{-0.5}] the step
D+,DcD_+, D_c (0,∞)→F(0, \infty) \to \mathbb{F} the forward and central differences, computed in doubles
EE (0,∞)→[0,∞)(0, \infty) \to [0, \infty) the total error ∣D(h)−e∣\lvert D(h) - e \rvert: truncation and rounding together
p, Cp,\ C (0,∞), R(0, \infty),\ \mathbb{R} the order and leading constant of the truncation error, from §3
h∗h^* (0,∞)(0, \infty) the step of least total error (the unknown)
How these symbols connect

Each step h∈[10−15,10−0.5]h \in [10^{-15}, 10^{-0.5}] is passed into the finite-precision quotients D+,Dc:(0,∞)→FD_+, D_c : (0, \infty) \to \mathbb{F} applied to f∈C3(R)f \in C^3(\mathbb{R}) at x=1x = 1. Comparing each computed value with ee gives the total error E(h)=∣D(h)−e∣E(h) = \lvert D(h) - e \rvert (in the units of f′(1)f'(1)), which combines the truncation error set by (p,C)(p, C) with the rounding error set by ϵ\epsilon. Tracking E(h)E(h) across fifteen decades of hh shows how those two sources interact and identifies the unknown optimal step h∗h^*.

Symbol-by-symbol notes
$D\lt em>+, D\lt /em>c : (0, \infty) \to \mathbb{F}$ — finite-precision quotients

Unlike §3's idealised real-valued quotients, here D+(h)D_+(h) and Dc(h)D_c(h) land in F\mathbb{F}, so each evaluation of ff, subtraction and division rounds to a double. Because ff is evaluated at x±hx \pm h, rounding errors of size about ϵ\epsilon enter before the division by hh.

$E(h)$ — total error vs truncation error

In §3, E(h)E(h) reflected truncation error because hh stayed relatively large. Over [10−15,10−0.5][10^{-15}, 10^{-0.5}], E(h)=∣D(h)−e∣E(h) = \lvert D(h) - e \rvert measures truncation error (governed by pp and CC) and rounding error (governed by ϵ\epsilon) together.

$h^*$ — step of least total error

h∗h^* is the positive step, in the same units as hh, that minimises E(h)E(h) for a given difference quotient. Each of D+D_+ and DcD_c has its own h∗h^*, set by its order pp and by ϵ\epsilon.

The difference quotient subtracts two nearly equal values and divides by hh, so an absolute rounding error of about ϵ\epsilon in ff becomes about ϵ/h\epsilon / h in the result. The total error is roughly

E(h)≈Chp+ϵh,E(h) \approx C h^p + \frac{\epsilon}{h},

which is smallest near h∗∼ϵ1/(p+1)h^* \sim \epsilon^{1/(p+1)}: about 1.5e-08 for the forward difference and 6.1e-06 for the central one (the dashed lines). Below h∗h^*, working harder makes the answer worse.

Reveal result (lock in your prediction above first)
10⁻¹⁵10⁻¹²10⁻⁹10⁻⁶10⁻³10⁻¹²10⁻⁹10⁻⁶10⁻³10⁰forwardcentralstep h|error|

Measured best steps: central h = 5.0e-06 (error 3.6e-12), forward h = 1.0e-08 (error 6.6e-09). The central difference wins twice: a smaller error at every step, and a larger best step.

When shrinking the step breaks
  • Assumes: truncation error is the only error
  • When it fails: below h∼ϵ1/(p+1)h \sim \epsilon^{1/(p+1)} rounding dominates and the error grows
  • Check: plot the error against hh on log-log axes and find where the V turns

Practice

Practice A (steps partly filled). A method's errors at hh and h/2h/2 are 3.2×10−33.2 \times 10^{-3} and 8.0×10−48.0 \times 10^{-4}. Ratio =3.2×10−3/8.0×10−4=  ?= 3.2 \times 10^{-3} / 8.0 \times 10^{-4} = \;?, then p=log⁡2(ratio)p = \log_2(\text{ratio}). Enter pp.

Worked solution

Ratio =4= 4, so p=log⁡24=2p = \log_2 4 = 2: a second-order method.

Practice B (with a hint). A first-order method (p=1p = 1) gives fh=2.7240f_h = 2.7240 and fh/2=2.7195f_{h/2} = 2.7195. Enter the Richardson-extrapolated value.

Worked solution

2.7195+(2.7195−2.7240)/1=2.71502.7195 + (2.7195 - 2.7240)/1 = 2.7150. (For exe^x at 1 the truth is 2.71828; these made-up runs were not that function.)

Hint 1

Use f0≈fh/2+(fh/2−fh)/(2p−1)f_0 \approx f_{h/2} + (f_{h/2} - f_h)/(2^p - 1).

Hint 2

With p=1p = 1 the denominator is 11, so you add the difference once more.

Practice C (on your own). Estimate log⁡10\log_{10} of the best step for the forward difference in double precision.

Worked solution

Order p=1p = 1, so h∗∼ϵ1/2=(2.2×10−16)1/2≈1.5×10−8h^* \sim \epsilon^{1/2} = (2.2 \times 10^{-16})^{1/2} \approx 1.5 \times 10^{-8}, and log⁡10h∗≈−7.8\log_{10} h^* \approx -7.8. §5's chart finds the measured best step at 10−810^{-8}.

Mixed practice. Put the steps of a convergence study in order.

Show true order
  1. Run the method at three or more steps, each half the last
  2. Compute the observed order from successive differences
  3. Check the order has settled over at least two refinements
  4. Extrapolate with the settled order
  5. Stop refining before the round-off floor

Check yourself (closed book)

1. Machine epsilon for a double is about 2.2×10−162.2 \times 10^{-16}. What does it bound?

Question 1
How sure?

2. 1+x−1\sqrt{1+x}-1 returns 0 for x=10−16x = 10^{-16}. What is wrong?

Question 2
How sure?

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

Question 3
How sure?

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

Question 4
How sure?

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

Question 5
How sure?

6. A convergence table shows observed orders 3.1, 2.4, 2.02, 2.00, 1.3. Which rows are trustworthy?

Question 6
How sure?

Show answers and explanations

1. The relative error of one correctly rounded operation. Each operation returns the exact result rounded to the nearest double, which is within a relative ϵ/2\epsilon/2 of it. That is a statement about relative size.

2. Subtracting two nearly equal numbers discards their shared digits. 1+x\sqrt{1+x} rounds to exactly 1, so the subtraction has nothing left to keep. Rewriting as x/(1+x+1)x/(\sqrt{1+x}+1) removes the subtraction and the loss.

3. 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.

4. 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.

5. 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.

6. The middle rows, where the order has settled. The first rows are pre-asymptotic (higher-order terms still matter) and the last has reached round-off. The order is the stable value in between.

Keep these:

  1. Measure error relatively; one operation is good to about ϵ/2\epsilon/2.
  2. A subtraction of nearly equal numbers loses digits: rewrite the formula.
  3. Order pp means halving hh divides the error by 2p2^p; read it as a slope.
  4. Three runs give the order and an extrapolated answer, no exact value needed.
  5. Total error ≈Chp+ϵ/h\approx Ch^p + \epsilon/h: the best step is near ϵ1/(p+1)\epsilon^{1/(p+1)}, and smaller is worse.

Your connection

Name one number you rely on that comes from a computation with a step or a tolerance (a simulation, a spreadsheet, a solver). How would you check its order?

Answers

Practice A. p=log⁡24=2p = \log_2 4 = 2.

Practice B. 2.71502.7150.

Practice C. log⁡10h∗≈−7.8\log_{10} h^* \approx -7.8, from h∗≈ϵ1/2h^* \approx \epsilon^{1/2}.

Mixed practice. run, compute the order, check it settled, extrapolate, stop before round-off.

Where the maths is derived

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

§1 Relative error and machine epsilon

§2 Cancellation

§3 Order of convergence

§4 Richardson extrapolation


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

Back to the book: Error, and what a tolerance is · Convergence, and how to measure it

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.