Lesson

Course conventions: errors, stopping and notation

The agreements used in every lesson, exercise, assignment and exam of the course: what ε and δ mean, when an iteration stops, which norm is meant, how iterations are counted, and how to round by hand.

Last updated:


Every method in this course is run until it is accurate enough, and “accurate enough” can be written in several ways.
This page fixes the way we write it, so a lesson, a practice question, an assignment and an exam all mean the same thing.
When a question needs something different, it says so in the question.

Two measures: ε and δ

An iteration produces numbers x1,x2,x3,…x_1,x_2,x_3,\ldots that should approach a solution we do not know.
Two quantities tell us how close we are, and they answer different questions:

SymbolNameQuestion it answersTypical formula
ε\varepsilonstep (estimated error)Did the method stop moving?∣xn−xn−1∣\lvert x_n-x_{n-1}\rvert
δ\deltaresidualDoes the answer solve the problem?∣f(xn)∣\lvert f(x_n)\rvert

The threshold we compare them with is a tolerance. A question might say “stop when ε<0.01\varepsilon<0.01” and then ask for xnx_n and for δ\delta⁠.
The two are different numbers, and one can be small while the other is large.

Here is bisection for f(x)=x2−2f(x)=x^2-2 on [1,2][1,2]⁠:

nncnc_nεn=∣cn−an−1∣\varepsilon_n=\lvert c_n-a_{n-1}\rvertδn=∣f(cn)∣\delta_n=\lvert f(c_n)\rvertnew bracket [an,bn][a_n,b_n]
0none yetnone yetnone yet[1,2][1,2] (the start)
11.50.50.25[1,1.5][1,1.5]
21.250.250.4375[1.25,1.5][1.25,1.5]
31.3750.1250.1094[1.375,1.5][1.375,1.5]
41.43750.06250.0664[1.375,1.4375][1.375,1.4375]

At n=2n=2 the step is already half as large as at n=1n=1⁠, but the residual grew.
A small step does not promise a small residual, and a small residual does not promise a small step when ff is nearly flat.
This is why we always check both.

For Newton’s method on the same function, from x0=1.5x_0=1.5⁠, the same two columns are:

nnxnx_nεn=∣xn−xn−1∣\varepsilon_n=\lvert x_n-x_{n-1}\rvertδn=∣f(xn)∣\delta_n=\lvert f(x_n)\rvert
11.4166670.0833330.006944
21.4142160.0024510.000006
31.4142140.0000024.5×10−124.5\times10^{-12}

When does the iteration stop?

  • Weak inequality. An iteration stops at the first nn for which the quantity is at most the tolerance: εn≤εtol\varepsilon_n\le\varepsilon_{\text{tol}}⁠. The reason is the meaning of a tolerance: we require the approximation to be at most εtol\varepsilon_{\text{tol}} away, and a value exactly equal to the tolerance satisfies that requirement. If a question means “strictly smaller”, it writes << explicitly.
  • What we report. The answer is the value in the row where the condition first holds: xnx_n (in bisection cnc_n⁠), with that row’s εn\varepsilon_n and δn\delta_n⁠. In the bisection table above, with tolerance 0.10.1⁠, we stop at n=4n=4 and report c4=1.4375c_4=1.4375⁠.
  • Both conditions. If a question gives two conditions, we stop when both hold, unless it says “either”. Each condition has its own threshold: εn≤εtol\varepsilon_n\le\varepsilon_{\text{tol}} for the step and δn≤δtol\delta_n\le\delta_{\text{tol}} for the residual, both weak. A rule such as “stop when the bracket is at most 10−610^{-6} wide and ∣f(c)∣≤10−6\lvert f(c)\rvert\le10^{-6}” is therefore written εn≤εtol\varepsilon_n\le\varepsilon_{\text{tol}} and δn≤δtol\delta_n\le\delta_{\text{tol}} with εtol=δtol=10−6\varepsilon_{\text{tol}}=\delta_{\text{tol}}=10^{-6}⁠.
  • Not below the gap. A tolerance cannot be smaller than the gap between stored numbers near the iterates: below it, no stored number can satisfy the condition and the loop may never end. Choose tolerances above εmach\varepsilon_{\text{mach}} times the size of the numbers involved, as explained in a tolerance cannot be smaller than the gap.

A program that runs a method also needs guards, because the stopping condition may never be met:

  • An iteration cap. Count the steps and stop after max_iter of them, even if the tolerance has not been reached, and report that the cap was reached instead of returning the last iterate as an answer. A cycling or slowly converging iteration would otherwise run forever.
  • A check that ∣f∣|f| decreases. If ∣f(xn)∣|f(x_n)| grows from step to step, or a step lands outside the range where the problem makes sense, the method is not converging.
  • A fall-back to bisection. When a bracket is known, a fast step that leaves the bracket, or fails the check above, is replaced by a bisection step; bisection always shrinks the bracket.

Counting iterations

  • nn counts the iterations performed. In Newton’s method and fixed-point iteration the starting point is x0x_0 and the first iteration produces x1x_1⁠, so n=1n=1 is the first row, and the table has one row per iteration. The one exception is the secant method: it starts from two points, x0x_0 and x1x_1⁠, and its first iteration produces x2x_2⁠, so it is indexed by the point it produces (nn = iterations + 1) and its first row is n=2n=2⁠.
  • In bisection and regula falsi row n=0n=0 is the start: the given bracket [a0,b0]=[a,b][a_0,b_0]=[a,b]⁠, with no approximation yet. Iteration n≥1n\ge1 takes [an−1,bn−1][a_{n-1},b_{n-1}]⁠, computes cnc_n (in bisection cn=an−1+bn−12c_n=\frac{a_{n-1}+b_{n-1}}{2}⁠) and f(cn)f(c_n)⁠, and the new bracket is [an,bn]=[an−1,cn][a_n,b_n]=[a_{n-1},c_n] if f(an−1)f(cn)≤0f(a_{n-1})f(c_n)\le0⁠, and [cn,bn−1][c_n,b_{n-1}] otherwise; cnc_n is always an end of it. Row nn shows cnc_n⁠, f(cn)f(c_n) and the new bracket [an,bn][a_n,b_n]⁠. NN iterations means n=Nn=N⁠.
  • Every table has the columns nn⁠, the iterate, εn\varepsilon_n and δn\delta_n⁠, plus whatever the method needs (for example ana_n and bnb_n⁠).

ε in bisection

In bisection we use εn=∣cn−an−1∣\varepsilon_n=\lvert c_n-a_{n-1}\rvert⁠, with an−1a_{n-1} the left end of the bracket from which cnc_n was computed.
Since cnc_n is the midpoint of [an−1,bn−1][a_{n-1},b_{n-1}]⁠, this is half of that width, and it equals the width bn−anb_n-a_n of the new bracket.
It is also the largest possible distance from cnc_n to the root, so it is an honest bound on the error:
∣cn−r∣≤εn\lvert c_n-r\rvert\le\varepsilon_n⁠.

Since the bracket is halved at every iteration, bn−an=b−a2nb_n-a_n=\dfrac{b-a}{2^{n}} and so εn=b−a2n\varepsilon_n=\dfrac{b-a}{2^{n}}⁠.
The iteration stops at the first nn with εn≤εtol\varepsilon_n\le\varepsilon_{\text{tol}}⁠. Since n=Nn=N is the number of iterations, the condition is b−a2N≤εtol\dfrac{b-a}{2^{N}}\le\varepsilon_{\text{tol}}⁠, and NN is the smallest integer with

N≥log⁡2b−aεtol,that isN=⌈log⁡2b−aεtol⌉N\ge\log_2\frac{b-a}{\varepsilon_{\text{tol}}},\qquad\text{that is}\qquad N=\left\lceil\log_2\frac{b-a}{\varepsilon_{\text{tol}}}\right\rceil

At least one iteration is performed, so N=max⁡(1,⌈log⁡2b−aεtol⌉)N=\max\bigl(1,\lceil\log_2\frac{b-a}{\varepsilon_{\text{tol}}}\rceil\bigr) when εtol≥b−a\varepsilon_{\text{tol}}\ge b-a⁠. For [1,2][1,2] and εtol=0.1\varepsilon_{\text{tol}}=0.1 the quotient is 1010⁠, log⁡210≈3.32\log_2 10\approx3.32⁠, and N=4N=4 iterations, as in the table above.
For [0,0.05][0,0.05] and εtol=10−6\varepsilon_{\text{tol}}=10^{-6} the quotient is 5000050000⁠, log⁡250000≈15.61\log_2 50000\approx15.61⁠, so N=16N=16 iterations.
When the quotient is exactly a power of 2 no extra step is needed:
for [0,1][0,1] and εtol=18\varepsilon_{\text{tol}}=\frac18 the quotient is 88⁠, ε3=18≤18\varepsilon_3=\frac18\le\frac18⁠, so N=3=log⁡28N=3=\log_2 8 iterations are enough:
the last midpoint is at most 18\frac18 from the root, as the tolerance requires.

Absolute and relative

The absolute and relative errors of an approximation x^\hat x to a value xx are

E=∣x−x^∣,Erel=∣x−x^∣∣x∣E=\lvert x-\hat x\rvert,\qquad E_{\text{rel}}=\frac{\lvert x-\hat x\rvert}{\lvert x\rvert}

In an iteration we do not know xx⁠, so we estimate the error from the step and, when a relative version is needed, divide by an iterate in place of the true value.
Two versions are common (dividing by the newer or by the older iterate), so a question that asks for a relative step always writes the formula.
A relative error is meaningless when the denominator is close to zero; then we use the absolute one.

Norms

When the iterate is a vector, ε\varepsilon and δ\delta are norms of vectors.

  • Vectors. ∥x∥\lVert x\rVert without a subscript means the Euclidean norm ∥x∥2=x12+⋯+xn2\lVert x\rVert_2=\sqrt{x_1^2+\cdots+x_n^2}⁠.
  • Matrices. ∥A∥\lVert A\rVert without a subscript means ∥A∥2=ρ(ATA)\lVert A\rVert_2=\sqrt{\rho(A^{\mathsf T}A)}⁠, the largest factor by which AA stretches a vector in the 2-norm (ρ\rho is the largest absolute eigenvalue). It is hard to compute by hand, so a question that needs a number written by hand names an easier norm: ∥A∥1\lVert A\rVert_1 (largest column sum of absolute values), ∥A∥∞\lVert A\rVert_\infty (largest row sum), or the Frobenius norm ∑aij2\sqrt{\sum a_{ij}^2}⁠.

For A=(1234)A=\begin{pmatrix}1&2\\3&4\end{pmatrix} these are 66⁠, 77 and 30≈5.477\sqrt{30}\approx5.477⁠, and ∥A∥2≈5.465\lVert A\rVert_2\approx5.465⁠. The 2-norm never exceeds the Frobenius norm.

Rate of convergence

If en=xn−αe_n=x_n-\alpha is the error and the limit

lim⁡n→∞∣en+1∣∣en∣q=C≠0\lim_{n\to\infty}\frac{\lvert e_{n+1}\rvert}{\lvert e_n\rvert^{q}}=C\neq0

exists, the method has order qq⁠. Order 1 is linear convergence (with 0<C<10<C<1⁠), order 2 is quadratic.
Bisection and regula falsi are linear, Newton’s method is quadratic near a simple root, and the secant method has order 1+52≈1.618\tfrac{1+\sqrt5}{2}\approx1.618⁠.

Hand calculation and rounding

  • Keep every digit your calculator shows while you work; round only when you write the final answer.
  • If a question asks for kk decimal places or digits, give exactly that many. A table entry is written with enough digits to see the stopping condition clearly.
  • A rounded number can flip a stopping decision when the margin is small (for example εn=0.0501\varepsilon_n=0.0501 against a tolerance of 0.050.05⁠). When this happens, show the unrounded value.

Notation

  • Iterates are xnx_n⁠; the exact solution of the problem at hand is α\alpha⁠, or x∗x^{*} when it is a minimizer or a fixed point; f′f' is the derivative.
  • A “step” is one move of the method (one row of the table); an “iteration” is the same thing. We use them interchangeably.
  • Tolerances are written εtol\varepsilon_{\text{tol}} when it could be confused with εn\varepsilon_n⁠, and otherwise as a number in the question.
Why two measures and not one?

A step can be tiny because the method has found the root, or because it has slowed down on a flat part of ff⁠.
The residual can be tiny because the root is found, or because ff is nearly flat there, so even a distant point has ∣f∣≈0\lvert f\rvert\approx0⁠.
Checking both guards against both mistakes, and for vectors the same pair is written with norms.

Check yourself

1. Newton’s method gives x5=2.3041x_5=2.3041 and x6=2.3040x_6=2.3040 (take the digits as exact).
Compute ε6\varepsilon_6⁠. Does the method stop at n=6n=6 for a tolerance of 10−410^{-4}⁠?
And for 5⋅10−55\cdot10^{-5}⁠?

Solution 1

ε6=∣x6−x5∣=0.0001=10−4\varepsilon_6=\lvert x_6-x_5\rvert=0.0001=10^{-4}⁠. The rule is εn≤εtol\varepsilon_n\le\varepsilon_{\text{tol}} and 10−4≤10−410^{-4}\le10^{-4}⁠, so the method stops at n=6n=6 and reports x6=2.3040x_6=2.3040⁠.
For a tolerance of 5⋅10−55\cdot10^{-5} it would not stop, since 10−4>5⋅10−510^{-4}>5\cdot10^{-5}⁠.

2. For A=(2−103)A=\begin{pmatrix}2&-1\\0&3\end{pmatrix} compute ∥A∥1\lVert A\rVert_1⁠, ∥A∥∞\lVert A\rVert_\infty and the Frobenius norm.

Solution 2

Column sums of absolute values: 22 and 44⁠, so ∥A∥1=4\lVert A\rVert_1=4⁠.
Row sums: 33 and 33⁠, so ∥A∥∞=3\lVert A\rVert_\infty=3⁠. Frobenius: 4+1+0+9=14≈3.742\sqrt{4+1+0+9}=\sqrt{14}\approx3.742⁠.

Continue learning