Lesson

Formula sheet

A reference sheet for Applied Numerical Analysis: the notation, formulas, conditions, error estimates and stopping rules of the units published so far, in course order.

Last updated:


This sheet lists the notation, formulas and procedures of the published units, in course order.
It does not teach and it has no worked examples: each section links to the lessons that explain its items, and to the glossary for the concepts.

Conventions common to all units

The full text of these agreements is in the course conventions.

SymbolMeaning
xnx_nthe iterate after nn steps; x0x_0 is the starting point
α\alpha or x∗x^{*}the exact solution (a root, or a fixed point)
en=xn−αe_n=x_n-\alphathe error of the iterate
εn=∣xn−xn−1∣\varepsilon_n=\lvert x_n-x_{n-1}\rvertthe step (estimated error)
δn=∣f(xn)∣\delta_n=\lvert f(x_n)\rvertthe residual
εtol, δtol\varepsilon_{\text{tol}},\ \delta_{\text{tol}}the tolerances for the step and for the residual

In bisection the step is εn=∣cn−an−1∣\varepsilon_n=\lvert c_n-a_{n-1}\rvert⁠, with cnc_n the midpoint of [an−1,bn−1][a_{n-1},b_{n-1}] and an−1a_{n-1} its left end.

Stopping rule. Stop at the first nn for which

εn≤εtolandδn≤δtol\varepsilon_n\le\varepsilon_{\text{tol}}\quad\text{and}\quad\delta_n\le\delta_{\text{tol}}

Both inequalities are weak: the approximation must be at most the tolerance away, so equality is enough.
A question that means “either” or “strictly smaller” says so (the rule is written << explicitly).
The reported answer is xnx_n of that row, with its εn\varepsilon_n and δn\delta_n⁠.

Order of convergence. With en=xn−αe_n=x_n-\alpha⁠, the method has order qq if

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
OrderNameBehavior of the error
q=1q=1⁠, 0<C<10<C<1linearen+1≈C ene_{n+1}\approx C\,e_n
q=2q=2quadraticen+1≈C en 2e_{n+1}\approx C\,e_n^{\,2}

The number of correct digits of an approximation with error EE is −log⁡10E-\log_{10}E⁠.

Absolute and relative error of an approximation x^\hat x to a value xx⁠:

E=∣x−x^∣,Erel=∣x−x^∣∣x∣(x≠0)E=\lvert x-\hat x\rvert,\qquad E_{\text{rel}}=\frac{\lvert x-\hat x\rvert}{\lvert x\rvert}\quad(x\neq0)

Norms (norm). Without a subscript, ∥x∥\lVert x\rVert is the Euclidean norm and ∥A∥\lVert A\rVert is the 2-norm:

∥x∥2=x12+⋯+xn2,∥A∥2=ρ(ATA)\lVert x\rVert_2=\sqrt{x_1^2+\cdots+x_n^2},\qquad \lVert A\rVert_2=\sqrt{\rho(A^{\mathsf T}A)}

where ρ\rho is the largest absolute value of an eigenvalue.
Norms that can be computed by hand:

NormDefinition
∥A∥1\lVert A\rVert_1the largest column sum of absolute values
∥A∥∞\lVert A\rVert_\inftythe largest row sum of absolute values
∥A∥F\lVert A\rVert_F∑aij2\sqrt{\sum a_{ij}^2} (Frobenius)

Always ∥A∥2≤∥A∥F\lVert A\rVert_2\le\lVert A\rVert_F⁠.

Course opening

The course opening introduces no formulas.

Numbers and errors in the computer

Floating-point number (floating point), in the order the fields are stored:

x=(−1)s×2e×1.fx=(-1)^{s}\times 2^{e}\times 1.f

With the stored fields, for a normal number:

x=(−1)s×2E−bias×(1+F2p)x=(-1)^{s}\times 2^{E-\text{bias}}\times\left(1+\frac{F}{2^{p}}\right)
SymbolMeaning
ssthe sign cell: 0 for positive, 1 for negative
ee⁠, EEthe true exponent and the stored exponent field; for normal numbers e=E−biase=E-\text{bias}⁠, and the rule for every stored number is in the unified formula below
bias\text{bias}the constant added to ee before it is stored
ff⁠, FFthe fraction digits and the whole number they spell
ppthe number of fraction cells
1.f1.fthe significand: the leading 1 (not stored) and the fraction

The IEEE 754 formats:

FormatCells s / E / fs\,/\,E\,/\,fBiasεmach=2−p\varepsilon_{\text{mach}}=2^{-p}
binary161 / 5 / 10152−10≈9.77×10−42^{-10}\approx9.77\times10^{-4}
binary321 / 8 / 231272−23≈1.19×10−72^{-23}\approx1.19\times10^{-7}
binary641 / 11 / 5210232−52≈2.22×10−162^{-52}\approx2.22\times10^{-16}

One formula for every stored number, with hh the hidden cell:

x=(−1)s×2e×(h+F2p)=(−1)s×2max⁡(E,1)−bias×(min⁡(E,1)+F2p)\begin{aligned} x&=(-1)^{s}\times2^{e}\times\left(h+\frac{F}{2^{p}}\right)\\[4pt] &=(-1)^{s}\times2^{\max(E,1)-\text{bias}}\times\left(\min(E,1)+\frac{F}{2^{p}}\right) \end{aligned}
Exponent fieldFraction fieldMeaning
all zeroszerothe number zero (+0+0 and −0-0⁠)
all zerosnot zeroa subnormal number: h=0h=0⁠, e=1−biase=1-\text{bias}
all oneszeroinfinity (±∞\pm\infty⁠)
all onesnot zeroNaN (not a number)
anything elseanya normal number: h=1h=1⁠, e=E−biase=E-\text{bias}

Range of binary64:

QuantityValue
largest finite numberabout 1.8×103081.8\times10^{308}
smallest positive normal number2−1022≈2.2×10−3082^{-1022}\approx2.2\times10^{-308}
smallest positive subnormal number2−1074≈4.9×10−3242^{-1074}\approx4.9\times10^{-324}

Gaps and rounding (machine epsilon is the gap between 1 and the next stored number).
The gap between adjacent stored numbers with the same exponent ee⁠, and the relative gap of a normal number:

gap=2 e−p,gap∣x∣=2−p1.f∈[2−p−1, 2−p]\text{gap}=2^{\,e-p},\qquad \frac{\text{gap}}{\lvert x\rvert}=\frac{2^{-p}}{1.f}\in\left[2^{-p-1},\,2^{-p}\right]

Rounding to the nearest stored number, written fl(x)\mathrm{fl}(x)⁠, with the tie going to the number whose last fraction cell is 0 (ties to even), gives

∣fl(x)−x∣≤gap2≤εmach2 ∣x∣,∣fl(x)−xx∣≤εmach2=2−53≈1.1×10−16 (binary64)\lvert\mathrm{fl}(x)-x\rvert\le\frac{\text{gap}}{2}\le\frac{\varepsilon_{\text{mach}}}{2}\,\lvert x\rvert,\qquad \left\lvert\frac{\mathrm{fl}(x)-x}{x}\right\rvert\le\frac{\varepsilon_{\text{mach}}}{2}=2^{-53}\approx1.1\times10^{-16}\ \text{(binary64)}

Significant digits. Rounding to kk significant digits gives

∣x−x^∣∣x∣≤5×10−k\frac{\lvert x-\hat x\rvert}{\lvert x\rvert}\le5\times10^{-k}

Kinds of error and comparison:

TermMeaning
round-off errorthe error of keeping a finite number of digits or cells: ∣fl(x)−x∣≤12 gap\lvert\mathrm{fl}(x)-x\rvert\le\tfrac12\,\text{gap}
truncation errorthe error of replacing an infinite process (a series, a limit) by a finite one
catastrophic cancellationthe loss of leading digits when two nearly equal numbers are subtracted
comparison tolerancetwo numbers count as equal when ∣a−b∣≤max⁡(rel_tol⋅max⁡(∣a∣,∣b∣), abs_tol)\lvert a-b\rvert\le\max\bigl(\text{rel\_tol}\cdot\max(\lvert a\rvert,\lvert b\rvert),\ \text{abs\_tol}\bigr)

Lessons: binary representation and floating point, rounding and machine epsilon, errors and the Patriot failure.

Nonlinear equations in one variable

The problem is to find a root α\alpha of f(x)=0f(x)=0⁠.

Intermediate value theorem and bracket. If ff is continuous on [a,b][a,b] and f(a) f(b)<0f(a)\,f(b)<0⁠, then

∃ c∈[a,b]: f(c)=0\exists\,c\in[a,b]:\ f(c)=0

The sign test is sufficient and not necessary for a root to exist in [a,b][a,b]⁠.

Bisection

(Bisection, nn counts the iterations performed; row n=0n=0 is the starting bracket [a0,b0]=[a,b][a_0,b_0]=[a,b]⁠.)

cn=an−1+bn−12c_n=\frac{a_{n-1}+b_{n-1}}{2}
  • if f(an−1) f(cn)≤0f(a_{n-1})\,f(c_n)\le0⁠, then [an,bn]=[an−1,cn][a_n,b_n]=[a_{n-1},c_n]⁠;
  • otherwise [an,bn]=[cn,bn−1][a_n,b_n]=[c_n,b_{n-1}]⁠;
  • if f(cn)=0f(c_n)=0⁠, then cnc_n is a root and we stop.

cnc_n is always an end of the new bracket [an,bn][a_n,b_n]⁠. Row nn shows cnc_n⁠, f(cn)f(c_n) and [an,bn][a_n,b_n]⁠.

Needs: ff continuous on [a,b][a,b] and f(a) f(b)≤0f(a)\,f(b)\le0 (a bracket). It does not fail inside a bracket.

Error: the bracket width is bn−an=b−a2nb_n-a_n=\dfrac{b-a}{2^{n}} and the step is

εn=∣cn−an−1∣=bn−an=b−a2n\varepsilon_n=\lvert c_n-a_{n-1}\rvert=b_n-a_n=\frac{b-a}{2^{n}}

which bounds the distance from cnc_n to the root.

Number of iterations NN (n=Nn=N at the stop): the smallest integer with b−a2N≤εtol\dfrac{b-a}{2^{N}}\le\varepsilon_{\text{tol}}⁠, that is

N=⌈log⁡2b−aεtol⌉N=\left\lceil\log_2\frac{b-a}{\varepsilon_{\text{tol}}}\right\rceil

with no extra step when the quotient is exactly a power of 2.
At least one iteration is performed: 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⁠.

Order: linear (C=12C=\tfrac12 for the error bound εn\varepsilon_n⁠). Stop: the rule of the conventions.

Regula falsi

(Regula falsi: the point where the chord through (an−1,f(an−1))(a_{n-1},f(a_{n-1})) and (bn−1,f(bn−1))(b_{n-1},f(b_{n-1})) crosses zero.)

cn=an−1 f(bn−1)−bn−1 f(an−1)f(bn−1)−f(an−1)c_n=\frac{a_{n-1}\,f(b_{n-1})-b_{n-1}\,f(a_{n-1})}{f(b_{n-1})-f(a_{n-1})}

nn counts the iterations performed (row 00 is the starting bracket), and the side where the sign changes is kept, as in bisection.

Needs: a bracket. Order: linear. Risk: one end can stay fixed, so the bracket width does not tend to 0 (it still bounds the error, but it is not a useful stopping test).
Stop: the rule of the conventions.

Newton–Raphson

(Newton–Raphson method: the tangent at xnx_n crosses zero at xn+1x_{n+1}⁠.)

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

Needs: f′f'⁠, with f′(xn)≠0f'(x_n)\neq0⁠, and a start near the root. Order: quadratic near a simple root.
Risks: a nearly flat slope throws the next point far away; the iteration can cycle or diverge.
Stop: εn=∣xn−xn−1∣\varepsilon_n=\lvert x_n-x_{n-1}\rvert and δn=∣f(xn)∣\delta_n=\lvert f(x_n)\rvert by the rule of the conventions.

Secant method

(Secant method: Newton with the slope through the two latest points.)

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

Needs: two starting points x0,x1x_0,x_1 and values of ff only.
Order: 1+52≈1.618\dfrac{1+\sqrt5}{2}\approx1.618⁠. Risk: there is no bracket, so it can diverge.
Stop: as for Newton.

Fixed-point iteration

(Fixed-point iteration.) A fixed point of gg is a number with

g(x∗)=x∗,xn+1=g(xn)g(x^{*})=x^{*},\qquad x_{n+1}=g(x_n)

A root of ff becomes a fixed point of, for example, g(x)=x−f(x)g(x)=x-f(x)⁠; one equation can be written as x=g(x)x=g(x) in many ways.
Near x∗x^{*}

xn+1−x∗≈g′(x∗) (xn−x∗)x_{n+1}-x^{*}\approx g'(x^{*})\,(x_n-x^{*})
Value of g′(x∗)g'(x^{*})Behavior
∣g′(x∗)∣<1\lvert g'(x^{*})\rvert<1converges (from a close start), linearly, with factor ∣g′(x∗)∣\lvert g'(x^{*})\rvert
∣g′(x∗)∣>1\lvert g'(x^{*})\rvert>1the iterates move away from x∗x^{*}
∣g′(x∗)∣=1\lvert g'(x^{*})\rvert=1this test does not decide; the iteration can cycle
g′(x∗)=0g'(x^{*})=0faster than linear

Each step gains −log⁡10∣g′(x∗)∣-\log_{10}\lvert g'(x^{*})\rvert correct digits.

Newton as a fixed point: g(x)=x−f(x)f′(x)g(x)=x-\dfrac{f(x)}{f'(x)}⁠, with g′(x)=f(x) f′′(x)f′(x)2g'(x)=\dfrac{f(x)\,f''(x)}{f'(x)^2}⁠, which is 00 at a root where f′≠0f'\neq0⁠.

Slope frozen at mm⁠: xn+1=xn−f(xn)mx_{n+1}=x_n-\dfrac{f(x_n)}{m}⁠, a fixed-point iteration with g′(x∗)=1−f′(x∗)mg'(x^{*})=1-\dfrac{f'(x^{*})}{m}⁠.

Stop: εn=∣xn−xn−1∣\varepsilon_n=\lvert x_n-x_{n-1}\rvert and δn=∣f(xn)∣\delta_n=\lvert f(x_n)\rvert by the rule of the conventions.

Inverse quadratic interpolation

(Inverse quadratic interpolation: xx as a quadratic function of yy through three points, evaluated at y=0y=0⁠.) For the points (a,fa)(a,f_a)⁠, (b,fb)(b,f_b)⁠, (c,fc)(c,f_c) with distinct values fa,fb,fcf_a,f_b,f_c⁠:

xn+1=a fbfc(fa−fb)(fa−fc)+b fafc(fb−fa)(fb−fc)+c fafb(fc−fa)(fc−fb)\begin{aligned} x_{n+1}&=\frac{a\,f_b f_c}{(f_a-f_b)(f_a-f_c)}\\ &\quad+\frac{b\,f_a f_c}{(f_b-f_a)(f_b-f_c)}\\ &\quad+\frac{c\,f_a f_b}{(f_c-f_a)(f_c-f_b)} \end{aligned}

In the next step the oldest point is dropped and the new one is added.

Needs: three starting points and values of ff only. Order: about 1.841.84⁠, the real root of t3=t2+t+1t^3=t^2+t+1⁠.
Risks: it fails when two of the values are equal, there is no bracket, and badly spread points can send the next point far away.
Stop: the rule of the conventions.

Brent’s method

Brent’s method keeps a bracket [an,bn][a_n,b_n] with f(an) f(bn)<0f(a_n)\,f(b_n)<0 at every step.
It tries an inverse quadratic interpolation step or a secant step, and replaces a candidate that is not well inside the bracket or does not shorten the step enough by a bisection step.

The methods side by side

MethodConvergenceNeedsMain risk
Bisectionlinear, C=12C=\tfrac12 for the bound εn\varepsilon_na bracketslow
Regula falsilineara bracketan end gets stuck
Secantorder 1.6181.618two startsmay diverge
Slope fixed oncelinearone slopeslow if the slope changes
Inverse quadraticorder 1.841.84three startsequal values, a wild parabola
Newton–Raphsonorder 22f′f' and a good startflat slope, cycles, divergence
Brentguaranteed by the bracketa bracketa more complex program

Lessons: bisection, regula falsi, Newton and the secant method, fixed point and inverse quadratic interpolation, choosing a method.