Exact value x gets perturbed with error and becomes perturbed value x~: Absolute errorδx:=x~−x⟹x~=x+δx Relative errorε:=xx~−x=xδx⟹x~=x(1+ε)
similarly, absolute output error = f(x~)−f(x) and relative output error = f(x)f(x~)−f(x)
Two equivalent ways to view perturbation of operation a+˙b: Forward analysis: exact input a,b→ exact result a+b⇝ perturbed result (a+b)(1+ε) Backward analysis: exact input a,b⇝ perturbed input a(1+ε),b(1+ε)→ "exact" result a(1+ε)+b(1+ε) a⋅˙b=forward(a⋅b)(1+ε)=backward(a1+ε)⋅(b1+ε)
Condition: sensitivity of output according to input perturbation (>1: amplification of error) inherent to the problem, not the used algorithm abs cond:=abs input errorabs output error, rel cond:=rel input errorrel output error
Approximation with derivative: cond(f,x)=∣f(x)x⋅f′(x)∣
Chaining of compound problems: cond(f(x)):=∂x∂f(x)
Stability: an algorithm is stable, if all perturbed inputs produce acceptable results:
An approximation y~(x) is acceptable if it's the exact solution to a perturbed input: y~(x)=p(x~) (thus if the problem is ill-conditioned, δy can be large and still be acceptable)
Stability analysis with Epsilontik: ...
Cancellation: when subtracting two very similar numbers (1000−999), even very small relative input error ±10001 can lead to high relative output error (=2) which causes the relative condition number to explode (2000), even worse for complete cancellation (exact result = 0) ⟹cond=∞!
1. Floating Point Numbers
Discretization of R, without the disadvantages of fixed point (fixed range, overflow, too little precision at small numbers and wasted precision at big numbers, ...)
Normalized t-digit floating point to basis B (machine number):
FB,t,α,β={M⋅BE∣M=0∨⇒t digits, no leading 0Bt−1≤∣M∣<Bt,range for Eα≤E≤β, with M,E∈Z}
The mantissaM and exponentE are saved as integers, the basis B and digits t are ususally implicit.
The absolute distance between two neighboring floats is not constant: ∣98⋅100−99⋅100∣=100 ∣98⋅101−99⋅101∣=101
The bigger the absolute value gets, the less precision it has (logarithmic scale!)
Max relative distance = resolutionϱ:=B1−t≥∣M∣1=∣M∣⋅BE(∣M∣+1)⋅BE−∣M∣⋅BE
Min positive float = σ:=Bt−1⋅Bα
Max float = λ:=(Bt−1)⋅Bβ
Rounding function rd(x) maps every x∈R to a f∈F
they should be surjective, idempotent and monotone
if x∈F, then rd(x)=x
if x∈R∖F, then every x:=(M+δ)⋅BE, with δ∈(0;1) has a neighbor to left/right: fl(x):=max{f∈F∣f≤x}=M⋅BE fr(x):=min{f∈F∣f≥x}=(M+1)⋅BE
the weak hypothesis (see Lec.1 P.27) only allows for backward analysis, the strong allows for both
A floating point arithmetic ∗˙ is ideal if it's the rounded exact result: a∗˙b=rd(a∗b)=(a∗b)⋅(1+ε(a,b))
Most floating point operators are not associative anymore!
IEEE-Standard Floats:
32-bit:
1 bit: sign (0=+,1=−)
8 bits: E+127⟹E=8bits−127, -127 and +128 reserved
23 bits: ∣M∣=1.[23bits] (normalized with leading 1)
rounding: correct rounding + for exact middle (0.1): round towards even number
64-bit;
...
2. Interpolation
Given nsupport points(xi,yi) of function f(x), build an approximant p(x) that goes through them: ∀i:p(xi)=yi mesh widthhi:=xi+1−xi
Lagrange interpolation: Only support points are given Hermite interpolation: Each support points additionally have required derivative yi′
Interpolation using polynoms:
Simple approach: Find coefficients of general term p(x):=∑i=0nai⋅xi by solving the system of equations for each support point (xi,yi)
Lagrange polynomial: Lk(x):=∏i:i=kxk−xix−xi with property that it equals 0 for all nodes except xk, and becomes 1 at node xk
Therefore p(x):=∑i=0nyi⋅Li(x) is a valid polynomial interpolant.
Scheme of Aitken and Neville: Instead of explicitly finding the term p(x), calculate the interpolated value for a concrete x
Define auxiliary polynomials pi,k(x) which are polynomials of degree k and interpolate the support points in [i;i+k] (thus base case ∀i:pi,0(x)=yi)
Then p(x):=p0,n(x) (if instead recursive formula is evaluated, the full term p(x) can be determined)
Newton's Interpolation Formula: Another recursive formula, but incremental, i.e. when another node xn+1 is added, only one new summand has to be added!
The divided difference of pi,k is the coefficient of the highest degree term xk: [xi,...,xi+k]f=:ci,k (thus base case ∀i:ci,0=yi)
Then p(x):=c0,0+c0,1⋅(x−x0)+...+c0,n⋅∏i=0n−1(x−xi)
Error of polynomial interpolants: For a concrete intermediate point xˉ, its error ∣f(xˉ)−p(xˉ)∣ is in O(hn+1) for equidistant mesh widthh: ⇒ lower h and higher nshould decrease error in theory (but due to Runge effect, not in practice!)
Equidistant nodes not optimal! (Chebychev nodes to add more nodes at the edges is optimal)
Condition of polynomial interpolants: Sensitivity of error in p(x) regarding error in yi
derivative of y regarding yi is Li(x), but small errors in central supporting values are dramatically increased at the borders of the interpolation interval!
for large n (7+ or 8+), extremely ill-conditioned for equidistant nodes
Interpolation using Polynomial Splines: Glue together pieces of polynomials of lower degree to avoid expensive computation and the Runge effect
Spline s:[a;b]→R of order m / degree m−1:
s(x)=pi(x) on [xi;xi+1], n pieces of polynomials between each knots (n+1 knots)
Locally: Between two knots, polynomial of degree m−1 (pi∈Pm−1)
Globally: s is m−2 times continuously differentiable (s∈Cm−2([a;b])) m=1: step function (piecewise continuous, not really a spline) m=2: linear interpolation (knots are connected, not really spline either) m=3: quadratic spline (knots have no sharp bends) m=4: cubic spline (continuous 1st & 2nd derivatives)
n+m−1 degrees of freedom (of which n+1 knot contraints are given)
Cubic Splines (m=4): Each piece is a cubic polynomial with parameters yi, yi+1, yi′, yi+1′: s(x):=pi(t) where t linearly connects from (xi;0) to (xi+1;1): t:=xi+1−xix−xi
then pi(t):=yi⋅α1(t)+yi+1⋅α2(t)+(xi+1−xi)⋅(yi′⋅α3(t)+yi+1′⋅α4(t)) (see Lec.2 P.31 for αi def.)
To determine the yi′s such that the 2nd derivatives at the knots are continuous, solve pi−1′′(1)=pi′′(0) for all yis (tridiagonal system of linear equations of dim n−1)
The remaining 2 degrees of freedom y0′,yn′ are boundary conditions, either given directly, set by given 2nd derivatives, or such that it's periodic (y0′=yn′ and s′′(x0)=s′′(xn))
Cost: Tridiagonal system of equations can be solved in O(n) as opposed to O(n3) for a full system, or the O(n2) for Aitken and Neville / Newton
Error: Since we're using cubic polynomials, ∣f(x)−s(x)∣=O(h4)
Trigonometric Interpolation: Given n nodes on the unit circle zj:=e2πij/n (equally spaced on the circle edge) and their corresponding values vj, find the interpolant p(z) where z:=e2πit,t∈[0;1] such that ∀j:p(zj)=vj
General representation as a linear combination of exponential functions: p(z):=∑k=0n−1ckzk=∑k=0n−1cke2πikt (can be separated into cos and sin)
Find the coefficients ck⟹Discrete Fourier Transform:
for ω:=e2πi/n,M=(ωjk), solve v=IDFT(c):=M⋅c or c=DFT(v):=n1⋅M⋅v, which takes O(n2)
the Fast Fourier Transform can calculate v=IDFT(c) in O(nlogn) through recursion, halving n=2m, j∈[0;m−1]: vj=IDFT(c0,c2,...)+ωj⋅IDFT(c1,c3,...) vj+m=even coefficientsIDFT(c0,c2,...)−ωj⋅odd coefficientsIDFT(c1,c3,...)
Easier to visualize:
Cosine Transform?: ...
3. Numerical Quadrature
Given function f:[a;b]→R, calculate definite integral I(f):=∫abf(x)dx using approximant rules of quadratures, which are weighted sums of samples (xi,yi): I(f)≈Q(f):=∑i=0ngi⋅yi with weights gi (thus: find appropriate weights!)
We can use polynomial interpolation p(x) of f(x) to find the weights: Q(f):=∫abp(x)dx=∫ab∑yiLi(x)dx⟹gi:=∫abLi(x)dx (Lionly depends on xi; weights can be pre-calculated!) (since ∑iLi(x)=1⟹∑igi=b−a)
Condition of quadrature: For input error ∣δyi∣≤ε, its output error δQ(f) has the upper bound ∣δQ(f)∣≤ε⋅∑i∣gi∣, which depends on the weights: ∀i:gi≥0⟹∑i∣gi∣=b−a⟹well-conditioned O(ε)! ∃i:gi<0⟹∑i∣gi∣>b−a⟹ill-conditioned! (occurs at big n)
Simple rules of quadrature calculate the result of the entire [a;b] at once (H:=b−a):
The rectangle ruleQR(f):=H⋅f(2a+b)=H⋅y0 takes one sample point in the middle x0:=(a+b)/2 (exact integral of constant interpolant)
Its remainderRR(f)=−H3⋅24f(2)(ξ) for intermediate point ξ∈(a;b); thus QR is exact for f∈P0 or P1 (order 3; degree of accuracy = 1)
The trapezoidal ruleQT(f):=H⋅2f(a)+f(b)=H⋅2y0+y1 takes two sample points x0:=a and x1:=b (exact integral of linear interpolant)
Its remainderRT(f)=H3⋅12f(2)(ξ) again exact for f∈P0 or P1 (order 3; accuracy 1)
The Kepler's ruleQF(f):=H⋅6f(a)+4f((a+b)/2)+f(b)=H⋅6y0+4y1+y2 takes three sample points x0:=a, x1:=(a+b)/2, x2:=b (exact integral of quadratic interpolant) remainderRF(f)=H5⋅2880f(4)(ξ); thus order 5 and accuracy 3
The Newton-Cotes formula generalizes this increasing sample points and order: QNC(f):=I(pn) where pn polynomial interpolant of degree n to the n+1equidistant nodesx0:=a,...,xi:=a+H⋅i/n,...,xn:=b
Thus with growing n, the order and accuracy increases. But for n=8 and n≥10, negative weights occur; very ill-conditioned!
The Clenshaw-Curtis rules uses non-uniformly distributed nodes (Chebychev nodes: x component of uniformly subdivided angles on a semicircle) to completely avoid negative weights: xi:=a+H⋅(1−cos(iπ/n))/2
Thus can be used for large n without being ill-conditioned (but composite rules are more practical)
Composite rules of quadrature split the integration domain [a;b] into n subdomains of length h:=(b−a)/n, applies simple rules and sums up, just like splines!
The trapezoidal sum applies the trapezoidal rule between each nodes: QTS(f;h):=h⋅(2y0+y1+...+2yn) (therefore weights g0:=h/2=:gn, otherwise gi:=h), integral of linear splines!)
Its remainderRTS(f;h)=h2⋅H⋅12f(2)(ξ) (orderdecreased by 1 to 2; accuracy still 1), n can grow without condition problem
The Simpson sum applies the Kepler's rule to each node pairs (without overlap): QSS(f;h):=3h⋅(y0+4y1+2y2+4y3+...+yn) (alternates between 4 ↔ 2 and 1 on each ends) remainderRSS(f;h)=h4⋅H⋅180f(4)(ξ) (orderdecreased by 1 to 4; accuracy still 3), n can also grow without condition problem
Extrapolation: Express the quadrature as exact value + error (Euler-Maclaurin sum formula, if f∈C2m): QTS(f;h)=exactI(f)+errorτ1h2+...+τm−1h2m−2+τm(h)⋅h2m=:T(h)
You could linearly combine different hi values to reduce the error (first eliminate the unknown factor τ1, then τ2, etc...)
Alternative perception of the Romberg quadrature: h→0⟹T(h)→I(f) exact integral, therefore interpolate T(h) with p∈Pm−1 in the nodes (hi2,T(hi)),i∈[1;m] and use p(0) as approximation of I(f) (calculate p(0) with Neville's scheme)
The error∣I(f)−p(0)∣ is in O(h12⋅h22⋅...⋅hm2), which is significantly better than the trapezoidal rule (but f must be 2m-times continuously differentiable!)