NumProg Summary

by jws\qquad\qquad\qquad\qquad\qquad \text{\it by jws}

Overview (and Todos)

  1. Floating Points, Rounding, Condition & Stability, Cancellation

  2. Interpolation:

    • with polynomials
    • with splines
    • with trigonometric functions / DFT
  3. Numerical Quadrature (Integrals)

    • rectangle rule
    • trapezoidal rule
    • Kepler's rule
    • ...
  4. Solving Linear Systems Directly

    • Gaussian Elimination
    • LU factorization
    • Cholesky factorization
    • Pivot search
  5. Ordinary Differential Equations (ODE)

    • Separation of variables
    • One-step methods:
      • Euler method
      • Heun method
      • Runge and Kutta method
    • Local & Global discretization error
    • Multistep methods:
      • Adams-Bashforth method
    • Stiffness
    • Implicit methods:
      • Implicit Euler method
  6. Iterative Roots and Optima

    • Relaxation methods
      • ...
    • Minimization methods
      • ...
    • Non-linear methods
      • ...
    • Multigrid
  7. Symmetric Eigenvalue Problem

  8. Hardware-Aware Computing

    • Space-filling curves
    • Matrix multiplication

TODO:

0. Error Analysis:

Exact value xx gets perturbed with error and becomes perturbed value x~\tilde x:
Absolute error δx:=x~−x  ⟹  x~=x+δx\delta x := \tilde x - x \implies \tilde x = x + \delta x
Relative error ε:=x~−xx=δxx  ⟹  x~=x(1+ε)\varepsilon := \frac{\tilde x - x}{x} = \frac{\delta x}{x} \implies \tilde x = x(1 + \varepsilon)
similarly, absolute output error = f(x~)−f(x)f(\tilde x) - f(x) and relative output error = f(x~)−f(x)f(x)\frac{f(\tilde x) - f(x)} {f(x)}

Two equivalent ways to view perturbation of operation a+˙ba \dot + b:
Forward analysis: exact input a,b→a, b \rarr exact result a+b⇝a + b \rightsquigarrow perturbed result (a+b)(1+ε)(a+b)(1+\varepsilon)
Backward analysis: exact input a,b⇝a, b \rightsquigarrow perturbed input a(1+ε),b(1+ε)→a(1+\varepsilon), b(1+\varepsilon) \rarr "exact" result a(1+ε)+b(1+ε)a(1+\varepsilon) + b(1+\varepsilon)
a⋅˙b=(a⋅b)(1+ε)⏟forward=(a1+ε)⋅(b1+ε)⏟backward\qquad\qquad\qquad a \dot \cdot b = \underbrace{(a \cdot b) (1 + \varepsilon)}_\text{forward} = \underbrace{(a \sqrt{1+\varepsilon}) \cdot (b \sqrt{1+\varepsilon})}_\text{backward}

Condition: sensitivity of output according to input perturbation (>1: amplification of error) inherent to the problem, not the used algorithm
abs cond:=abs output errorabs input error\text{abs cond} := \frac{\text{abs output error}}{\text{abs input error}}, rel cond:=rel output errorrel input error\text{rel cond} := \frac{\text{rel output error}}{\text{rel input error}}
Approximation with derivative: cond(f,x)=∣x⋅f′(x)f(x)∣cond(f, x) = |\frac{x \cdot f'(x)}{f(x)}|
Chaining of compound problems: cond(f(x)):=∂f(x)∂xcond(f(x)) := \frac{\partial f(x)}{\partial x}

Stability: an algorithm is stable, if all perturbed inputs produce acceptable results:
An approximation y~(x)\tilde y(x) is acceptable if it's the exact solution to a perturbed input: y~(x)=p(x~)\tilde y(x) = p(\tilde x) (thus if the problem is ill-conditioned, δy\delta y can be large and still be acceptable)
Stability analysis with Epsilontik: ...

Cancellation: when subtracting two very similar numbers (1000−9991000 - 999), even very small relative input error ±11000\pm \frac{1}{1000} can lead to high relative output error (=2= 2) which causes the relative condition number to explode (20002000), even worse for complete cancellation (exact result = 0)   ⟹  cond=∞\implies cond = \infin!

1. Floating Point Numbers

Discretization of R\R, without the disadvantages of fixed point (fixed range, overflow, too little precision at small numbers and wasted precision at big numbers, ...)

Normalized tt-digit floating point to basis BB (machine number):

FB,t,α,β={M⋅BE∣M=0∨Bt−1≤∣M∣<Bt⏟⇒ t digits, no leading 0, α≤E≤β⏟range for E, with M,E∈Z}\mathbb{F}_{B,t,\alpha,\beta} = \{ M \cdot B^E \mid M=0 \lor \underbrace{B^{t-1} \leq |M| < B^t}_{\Rightarrow\ t \text{ digits, no leading 0}},\ \underbrace{\alpha \leq E \leq \beta}_{\text{range for E}}, \text{ with } M, E \in \Z \}

The mantissa MM and exponent EE are saved as integers, the basis BB and digits tt are ususally implicit.

The absolute distance between two neighboring floats is not constant:
∣98⋅100−99⋅100∣=100\qquad |98 \cdot 10^0 - 99 \cdot 10^0| = 10^0
∣98⋅101−99⋅101∣=101\qquad |98 \cdot 10^1 - 99 \cdot 10^1| = 10^1
The bigger the absolute value gets, the less precision it has (logarithmic scale!)
absolute distance

Max relative distance = resolution ϱ:=B1−t≥1∣M∣=(∣M∣+1)⋅BE−∣M∣⋅BE∣M∣⋅BE\varrho := B^{1-t} \geq \frac{1}{|M|} = \frac{(|M|+1) \cdot B^E - |M| \cdot B^E}{|M| \cdot B^E}
Min positive float = σ:=Bt−1⋅Bα\sigma := B^{t-1} \cdot B^\alpha
Max float = λ:=(Bt−1)⋅Bβ\lambda := (B^t - 1) \cdot B^\beta

Rounding function rd(x)rd(x) maps every x∈Rx \in \R to a f∈Ff \in \mathbb{F}

A floating point arithmetic ∗˙\dot * is ideal if it's the rounded exact result: a∗˙b=rd(a∗b)=(a∗b)⋅(1+ε(a,b))a \dot * b= rd(a * b) = (a * b) \cdot (1 + \varepsilon(a, b))
Most floating point operators are not associative anymore!

IEEE-Standard Floats:

2. Interpolation

Given nn support points (xi,yi)(x_i, y_i) of function f(x)f(x), build an approximant p(x)p(x) that goes through them: ∀i:p(xi)=yi\forall i: p(x_i) = y_i
mesh width hi:=xi+1−xih_i := x_{i+1} - x_i

Lagrange interpolation: Only support points are given
Hermite interpolation: Each support points additionally have required derivative yi′y'_i

Interpolation using polynoms:

Interpolation using Polynomial Splines: Glue together pieces of polynomials of lower degree to avoid expensive computation and the Runge effect

Cubic Splines (m=4m=4): Each piece is a cubic polynomial with parameters yiy_i, yi+1y_{i+1}, yi′y_i', yi+1′y_{i+1}':
s(x):=pi(t)s(x) := p_i(t) where tt linearly connects from (xi;0)(x_i; 0) to (xi+1;1)(x_{i+1}; 1): t:=x−xixi+1−xit := \frac{x-x_i}{x_{i+1}-x_i}
then pi(t):=yi⋅α1(t)+yi+1⋅α2(t)+(xi+1−xi)⋅(yi′⋅α3(t)+yi+1′⋅α4(t))p_i(t) := y_i \cdot \alpha_1(t) + y_{i+1} \cdot \alpha_2(t) + (x_{i+1} - x_i) \cdot (y_i' \cdot \alpha_3(t) + y_{i+1}' \cdot \alpha_4(t)) (see Lec.2 P.31 for αi\alpha_i def.)

To determine the yi′y_i's such that the 2nd derivatives at the knots are continuous, solve pi−1′′(1)=pi′′(0)p_{i-1}''(1) = p_i''(0) for all yiy_is (tridiagonal system of linear equations of dim n−1n-1)
The remaining 2 degrees of freedom y0′,yn′y_0', y_n' are boundary conditions, either given directly, set by given 2nd derivatives, or such that it's periodic (y0′=yn′y_0' = y_n' and s′′(x0)=s′′(xn)s''(x_0) = s''(x_n))

Cost: Tridiagonal system of equations can be solved in O(n)O(n) as opposed to O(n3)O(n^3) for a full system, or the O(n2)O(n^2) for Aitken and Neville / Newton

Error: Since we're using cubic polynomials, ∣f(x)−s(x)∣=O(h4)|f(x)-s(x)| = O(h^4)

Trigonometric Interpolation: Given nn nodes on the unit circle zj:=e2πij/nz_j := e^{2\pi i j / n} (equally spaced on the circle edge) and their corresponding values vjv_j, find the interpolant p(z)p(z) where z:=e2πit,t∈[0;1]z := e^{2\pi i t}, t \in [0; 1] such that ∀j:p(zj)=vj\forall j: p(z_j) = v_j
General representation as a linear combination of exponential functions:
p(z):=∑k=0n−1ckzk=∑k=0n−1cke2πiktp(z) := \sum_{k=0}^{n-1} c_k z^k = \sum_{k=0}^{n-1} c_k e^{2 \pi i k t} (can be separated into coscos and sinsin)
Find the coefficients ck  ⟹  c_k \implies Discrete Fourier Transform:

Cosine Transform?: ...

3. Numerical Quadrature

Given function f:[a;b]→Rf: [a; b] \rarr \R, calculate definite integral I(f):=∫abf(x)dxI(f) := \int_a^b f(x) dx using approximant rules of quadratures, which are weighted sums of samples (xi,yi)(x_i, y_i):
I(f)≈Q(f):=∑i=0ngi⋅yiI(f) \approx Q(f) := \sum_{i=0}^n g_i \cdot y_i with weights gig_i (thus: find appropriate weights!)
We can use polynomial interpolation p(x)p(x) of f(x)f(x) to find the weights:
Q(f):=∫abp(x)dx=∫ab∑yiLi(x)dx  ⟹  gi:=∫abLi(x)dxQ(f) := \int_a^b p(x)dx = \int_a^b \sum y_i L_i(x) dx \implies g_i := \int_a^b L_i(x)dx
\qquad(LiL_i only depends on xix_i; weights can be pre-calculated!)
\qquad(since ∑iLi(x)=1  ⟹  ∑igi=b−a\sum_i L_i(x) = 1 \implies \sum_i g_i = b - a)

Condition of quadrature: For input error ∣δyi∣≤ε|\delta y_i| \leq \varepsilon, its output error δQ(f)\delta Q(f) has the upper bound ∣δQ(f)∣≤ε⋅∑i∣gi∣|\delta Q(f)| \leq \varepsilon \cdot \sum_i |g_i|, which depends on the weights:
∀i:gi≥0  ⟹  ∑i∣gi∣=b−a  ⟹  \forall i: g_i \geq 0 \implies \sum_i |g_i| = b - a \implies well-conditioned O(ε)O(\varepsilon)!
∃i:gi<0  ⟹  ∑i∣gi∣>b−a  ⟹  \exists i: g_i < 0 \implies \sum_i |g_i| > b- a \implies ill-conditioned! (occurs at big nn)

Simple rules of quadrature calculate the result of the entire [a;b][a;b] at once (H:=b−aH := b-a):

Composite rules of quadrature split the integration domain [a;b][a;b] into nn subdomains of length h:=(b−a)/nh := (b-a) / n, applies simple rules and sums up, just like splines!

Extrapolation: Express the quadrature as exact value + error (Euler-Maclaurin sum formula, if f∈C2mf \in C^{2m}):
QTS(f;h)=I(f)⏟exact+τ1h2+...+τm−1h2m−2+τm(h)⋅h2m⏟error=:T(h)Q_{TS}(f; h) = \underbrace{I(f)}_\text{exact} + \underbrace{\tau_1 h^2 + ... + \tau_{m-1} h^{2m-2} + \tau_m(h) \cdot h^{2m}}_\text{error} =: T(h)