Mathematical Methods Handbook

Numerical solution of differential equations

Integrators for ODEs and discretizations of PDEs.

In this chapter 9

Tick a unit to add it to your PDF basket.

  1. Ordinary differential equations
  2. Partial differential equations

Ordinary differential equations

3

Method

Integrators for ODEs

Adapted

Builds the one-step and multistep integrators for y′=f(x,y)y' = f(x,y) from the Taylor expansion they imitate, defines the local truncation error and the order, proves that a method of order pp whose increment is Lipschitz has global error at most (C/L)(eL(b−a)−1)hp(C/L)(e^{L(b-a)}-1)h^{p}, and verifies the orders 11, 22, 22 and 44 of Euler, Heun, Adams-Bashforth and classical Runge-Kutta on a nonlinear problem with a known solution.

Prerequisites: Existence and uniqueness of solutions, Taylor's theorem, Dependence on initial data and Gronwall's inequality, Linear systems and the matrix exponential

Definition(The problem, the grid, and a one-step method)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.6, Eq. (27.60), p. 1020; Hirsch, Smale & Devaney (2013), §7.5, p. 154

Throughout, the object to be solved is the initial-value problem

y′=f(x,y),y(a)=ya,y' = f(x, y), \qquad y(a) = y_a ,

on an interval [a,b][a,b], where yy may be a vector in Rm\mathbb{R}^{m} and ff is defined on a region R⊆[a,b]×RmR \subseteq [a,b]\times\mathbb{R}^{m}. By Existence and uniqueness of solutions a unique solution exists as long as ff is continuous and Lipschitz in yy, and that is the function the methods below try to produce. Nothing is lost by restricting attention to first-order systems: an equation y(R)=F(x,y,y′,…,y(R−1))y^{(R)} = F(x, y, y', \dots, y^{(R-1)}) becomes the system y′=p1, p1′=p2, …, pR−1′=Fy' = p_1,\ p_1' = p_2,\ \dots,\ p_{R-1}' = F in the RR unknowns y,p1,…,pR−1y, p_1, \dots, p_{R-1}, and every method here is applied componentwise, all components being advanced through a step before any is advanced through the next. Riley, Hobson and Bence set this reduction out in full; it is the first thing done to a high-order equation before it is handed to software, and it is the reason the units on linear systems (Linear systems and the matrix exponential) and on integrators speak the same language.

Fix a step size h>0h > 0 and the grid xn=a+nhx_n = a + nh. The methods produce numbers yny_n intended to approximate y(xn)y(x_n); yny_n is a vector when yy is.

A one-step method is a rule

yn+1  =  yn+h Φ(xn,yn;h),y_{n+1} \;=\; y_n + h\,\Phi(x_n, y_n; h) ,

in which the increment function Φ\Phi is built from evaluations of ff alone. The method is explicit when Φ\Phi can be evaluated from (xn,yn,h)(x_n, y_n, h) by a finite list of substitutions, as all the methods in this unit can; methods for which yn+1y_{n+1} appears on both sides are implicit and are the subject of Stability and stiff equations.

A linear multistep method with kk steps is a rule

yn+1  =  ∑j=0k−1αj yn−j  +  h∑j=−1k−1βj f(xn−j, yn−j),y_{n+1} \;=\; \sum_{j=0}^{k-1}\alpha_j\,y_{n-j} \;+\; h\sum_{j=-1}^{k-1}\beta_j\,f(x_{n-j},\,y_{n-j}) ,

with constant coefficients; it is explicit when β−1=0\beta_{-1} = 0. Such a method needs kk starting values, and only one of them is given by the problem.

Definition(Local truncation error, order, convergence)Original

Let yy denote the exact solution. The local truncation error of a one-step method at (x,y(x))(x, y(x)) is the amount by which the exact solution fails to satisfy the method's own recurrence over one step:

τ(x,h)  =  y(x+h)  −  y(x)  −  h Φ(x,y(x);h).\tau(x, h) \;=\; y(x+h) \;-\; y(x) \;-\; h\,\Phi\bigl(x, y(x); h\bigr) .

It is the error a single step would commit if it started from exact data. The method has order pp on [a,b][a,b] if there is a constant CC, independent of xx and hh, with

∥τ(x,h)∥  ≤  C h p+1for all x∈[a,b] and all small h,\lVert\tau(x,h)\rVert \;\le\; C\,h^{\,p+1} \qquad\text{for all } x \in [a,b] \text{ and all small } h ,

and if pp is the largest exponent for which this holds. A method of order p≥1p \ge 1 is consistent: dividing by hh, the recurrence reproduces the differential equation in the limit.

The global error is en=y(xn)−yne_n = y(x_n) - y_n, the quantity the user actually suffers. The method converges if max⁡n∥en∥→0\max_{n}\lVert e_n\rVert \to 0 as h→0h \to 0 with b−ab - a fixed. The one power of hh that separates τ\tau from the global error is the bookkeeping of the theorem below: roughly (b−a)/h(b-a)/h local errors of size hp+1h^{p+1} accumulate into a global error of size hph^{p}.

For a multistep method the local truncation error is defined by the same substitution of the exact solution into the recurrence, and the order is again the largest pp with ∥τ∥≤Chp+1\lVert\tau\rVert \le Ch^{p+1}.

Definition(The five methods used here)AdaptedAdapted from Strogatz (1994), §2.8, pp. 32-34; Hirsch, Smale & Devaney (2013), §7.5, pp. 154-155; Riley, Hobson & Bence (2006), §27.6, Eqs. (27.63), (27.73), (27.78), (27.80), pp. 1021, 1025, 1027, 1028

Write fn=f(xn,yn)f_n = f(x_n, y_n). Each rule below says which slope is used to cross the interval [xn,xn+1][x_n, x_{n+1}]; Hirsch, Smale and Devaney's way of putting it is that a method is nothing but a choice of the straight line along which the step is taken.

Euler's method uses the slope at the left endpoint:

yn+1=yn+hfn.y_{n+1} = y_n + h f_n .

Strogatz reads it off the vector field directly: travel for time hh at the velocity found where you are.

The improved Euler (Heun) method takes a trial step with Euler, evaluates the slope there, and crosses with the average of the two slopes:

y~=yn+hfn,yn+1=yn+h2(fn+f(xn+1,y~)).\tilde y = y_n + h f_n , \qquad y_{n+1} = y_n + \tfrac{h}{2}\Bigl( f_n + f(x_{n+1}, \tilde y) \Bigr) .

The midpoint method instead uses a half-step probe and crosses with the slope found there:

yn+1=yn+h f(xn+h2,  yn+h2fn).y_{n+1} = y_n + h\,f\Bigl(x_n + \tfrac{h}{2},\; y_n + \tfrac{h}{2} f_n\Bigr) .

The classical fourth-order Runge-Kutta method (RK4) uses four slopes:

k1=f(xn, yn),k2=f(xn+h2,  yn+h2k1),k3=f(xn+h2,  yn+h2k2),k4=f(xn+h,  yn+hk3),\begin{aligned} k_1 &= f(x_n,\, y_n), &\qquad k_2 &= f\bigl(x_n + \tfrac{h}{2},\; y_n + \tfrac{h}{2}k_1\bigr), \\ k_3 &= f\bigl(x_n + \tfrac{h}{2},\; y_n + \tfrac{h}{2}k_2\bigr), &\qquad k_4 &= f\bigl(x_n + h,\; y_n + h k_3\bigr), \end{aligned}yn+1=yn+h6(k1+2k2+2k3+k4).y_{n+1} = y_n + \tfrac{h}{6}\bigl(k_1 + 2k_2 + 2k_3 + k_4\bigr) .

The two-step Adams-Bashforth method (AB2) is not a one-step method: it reuses the slope already computed at the previous grid point,

yn+1=yn+h2(3fn−fn−1).y_{n+1} = y_n + \tfrac{h}{2}\bigl(3 f_n - f_{n-1}\bigr) .

Riley, Hobson and Bence derive it by fitting a straight line to ff through the two points (xn−1,fn−1)(x_{n-1}, f_{n-1}) and (xn,fn)(x_n, f_n) and integrating that line across [xn,xn+1][x_n, x_{n+1}]; the extra term h2(fn−fn−1)\tfrac{h}{2}(f_n - f_{n-1}) is a correction to the Euler step. It costs one evaluation of ff per step, against two for Heun and the midpoint rule and four for RK4, because fn−1f_{n-1} is kept from the previous step.

Method(Convergence of a one-step method, and the orders of the five methods)Original

1 (Convergence). Let R=[a,b]×UR = [a,b]\times U with U⊆RmU \subseteq \mathbb{R}^{m}, let the exact solution yy of y′=f(x,y)y' = f(x,y), y(a)=yay(a) = y_a stay in RR on [a,b][a,b], and consider a one-step method started exactly, y0=yay_0 = y_a, whose iterates yny_n also stay in RR. Suppose

  • (L) the increment function satisfies ∥Φ(x,u;h)−Φ(x,v;h)∥≤L ∥u−v∥\lVert \Phi(x, u; h) - \Phi(x, v; h)\rVert \le L\,\lVert u - v\rVert for all (x,u),(x,v)∈R(x,u), (x,v) \in R and all h∈(0,h0]h \in (0, h_0], with L>0L > 0; and
  • (T) the local truncation error obeys ∥τ(x,h)∥≤Chp+1\lVert\tau(x,h)\rVert \le C h^{p+1} on [a,b][a,b] for h∈(0,h0]h \in (0, h_0].

Then for every h∈(0,h0]h \in (0,h_0] and every grid point xn∈[a,b]x_n \in [a,b],

∥y(xn)−yn∥  ≤  CL(eL(xn−a)−1) hp.\lVert y(x_n) - y_n \rVert \;\le\; \frac{C}{L}\Bigl(e^{L(x_n - a)} - 1\Bigr)\,h^{p} .

In particular the method converges, with global error O(hp)O(h^{p}): one power of hh is lost relative to the local error.

2 (Orders). Let ff be as smooth as each statement requires on a neighbourhood of the solution. Then

  • Euler's method has order 11, with local truncation error 12h2y′′(x)+O(h3)\tfrac{1}{2}h^{2}y''(x) + O(h^{3});
  • the Heun and midpoint methods have order 22;
  • AB2 has order 22, with local truncation error 512h3y′′′(x)+O(h4)\tfrac{5}{12}h^{3}y'''(x) + O(h^{4});
  • RK4 has order 44.

3 (The second-order family). Every method of the two-stage form

yn+1=yn+h[α1fn+α2f(xn+βh, yn+βhfn)]y_{n+1} = y_n + h\Bigl[\alpha_1 f_n + \alpha_2 f\bigl(x_n + \beta h,\, y_n + \beta h f_n\bigr)\Bigr]

has order at least 22 if and only if

α1+α2=1andα2β=12,\alpha_1 + \alpha_2 = 1 \qquad\text{and}\qquad \alpha_2\beta = \tfrac12 ,

so the family has one free parameter. Heun is α1=α2=12\alpha_1 = \alpha_2 = \tfrac12, β=1\beta = 1; the midpoint method is α1=0\alpha_1 = 0, α2=1\alpha_2 = 1, β=12\beta = \tfrac12. No member of the family has order 33 for all ff.

Idea of the proofOriginal

Every method here is an attempt to imitate the Taylor expansion of the exact solution without differentiating ff. The expansion y(x+h)=y+hy′+12h2y′′+⋯y(x+h) = y + hy' + \tfrac12 h^{2}y'' + \cdots needs y′′=fx+fyfy'' = f_x + f_y f, y′′′y''', and so on; computing those by hand is exactly what Runge-Kutta methods avoid, by evaluating ff itself at cleverly placed points and combining the values so that the combination reproduces the Taylor coefficients. Matching through hph^{p} is what "order pp" means, and part 3 shows the matching conditions in the smallest nontrivial case.

The convergence statement is an accumulation argument with one twist. Over a step, the previous error is carried forward and distorted by the method, and a fresh local error τ\tau is added. Hypothesis (L) says the distortion is at worst a factor 1+hL1 + hL, so the errors obey εn+1≤(1+hL)εn+Chp+1\varepsilon_{n+1} \le (1+hL)\varepsilon_n + Ch^{p+1}. The twist is that summing this geometric recursion produces ((1+hL)n−1)/(hL)\bigl((1+hL)^{n} - 1\bigr)/(hL), and the factor hLhL in the denominator cancels one power of hh from the numerator Chp+1Ch^{p+1}; that is where the lost power goes. Finally (1+hL)n≤enhL(1+hL)^{n} \le e^{nhL} converts the discrete growth factor into the exponential that Gronwall's inequality produces for the continuous problem. The exponential is not an artefact: two exact solutions of the same equation really can separate that fast, so no method can do better.

Proof(Part 1)Original

Step 1 (one step of the recursion). Write en=y(xn)−yne_n = y(x_n) - y_n and εn=∥en∥\varepsilon_n = \lVert e_n\rVert. By the definition of the local truncation error applied at xnx_n,

y(xn+1)=y(xn)+h Φ(xn,y(xn);h)+τ(xn,h),y(x_{n+1}) = y(x_n) + h\,\Phi\bigl(x_n, y(x_n); h\bigr) + \tau(x_n, h) ,

while the method gives yn+1=yn+hΦ(xn,yn;h)y_{n+1} = y_n + h\Phi(x_n, y_n; h). Subtracting,

en+1=en+h[Φ(xn,y(xn);h)−Φ(xn,yn;h)]+τ(xn,h).e_{n+1} = e_n + h\Bigl[\Phi\bigl(x_n, y(x_n); h\bigr) - \Phi(x_n, y_n; h)\Bigr] + \tau(x_n, h) .

Step 2 (estimate it). Both (xn,y(xn))(x_n, y(x_n)) and (xn,yn)(x_n, y_n) lie in RR, by the hypothesis that the exact solution and the iterates stay there. So hypothesis (L) bounds the bracket by LεnL\varepsilon_n, and hypothesis (T) bounds τ\tau by Chp+1Ch^{p+1}. The triangle inequality gives

εn+1  ≤  (1+hL) εn  +  Chp+1.(∗)\varepsilon_{n+1} \;\le\; (1 + hL)\,\varepsilon_n \;+\; C h^{p+1} . \tag{$*$}

Step 3 (an accumulation lemma). If ε0=0\varepsilon_0 = 0 and (∗)(*) holds with A=1+hL>1A = 1+hL > 1 and B=Chp+1≥0B = Ch^{p+1} \ge 0, then εn≤B (An−1)/(A−1)\varepsilon_n \le B\,(A^{n}-1)/(A-1). Induct on nn. The case n=0n = 0 reads ε0≤0\varepsilon_0 \le 0, which is the hypothesis. If the bound holds at nn then

εn+1≤A⋅BAn−1A−1+B=B An+1−A+A−1A−1=B An+1−1A−1,\varepsilon_{n+1} \le A\cdot B\frac{A^{n}-1}{A-1} + B = B\,\frac{A^{n+1} - A + A - 1}{A-1} = B\,\frac{A^{n+1}-1}{A-1} ,

which is the bound at n+1n+1.

Step 4 (substitute and simplify). Here A−1=hLA - 1 = hL, so

εn  ≤  Chp+1hL((1+hL)n−1)=CL hp((1+hL)n−1).\varepsilon_n \;\le\; \frac{C h^{p+1}}{hL}\Bigl((1+hL)^{n} - 1\Bigr) = \frac{C}{L}\,h^{p}\Bigl((1+hL)^{n} - 1\Bigr) .

The single power of hh cancelled against hLhL is the one lost between local and global order.

Step 5 (exponential form). For t≥0t \ge 0 the convexity of the exponential gives 1+t≤et1 + t \le e^{t}, so (1+hL)n≤enhL=eL(xn−a)(1+hL)^{n} \le e^{nhL} = e^{L(x_n - a)} because nh=xn−anh = x_n - a. Substituting into Step 4 gives the claim. The starting value is exact, ε0=0\varepsilon_0 = 0, as assumed in Step 3; if instead ε0>0\varepsilon_0 > 0 the same induction yields the extra term ε0eL(xn−a)\varepsilon_0 e^{L(x_n-a)}. □\square

Proof(Part 2, except RK4)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.6, Eqs. (27.68)-(27.70) and (27.73), pp. 1023-1025

Throughout, yy is the exact solution through (x,y(x))(x, y(x)), so that y′=f(x,y(x))y' = f(x,y(x)), and all derivatives are evaluated at xx unless marked otherwise. We use the chain rule in the form Riley, Hobson and Bence record, y′′=fx+fy fy'' = f_x + f_y\,f, and Taylor's theorem (Taylor's theorem).

Euler. With Φ=f(x,y(x))=y′\Phi = f(x, y(x))= y',

τ=y(x+h)−y(x)−hy′=12h2y′′(x)+O(h3),\tau = y(x+h) - y(x) - h y' = \tfrac12 h^{2} y''(x) + O(h^{3}) ,

which is O(h2)O(h^{2}) and no better unless y′′≡0y'' \equiv 0. So p=1p = 1.

The two-stage family, and Heun and midpoint with it. Expand the second stage of the family in part 3 of the statement by Taylor's theorem in two variables, about (x,y(x))(x, y(x)):

f(x+βh,  y+βhf)=f+βh(fx+fyf)+12β2h2(fxx+2ffxy+f2fyy)+O(h3).f\bigl(x + \beta h,\; y + \beta h f\bigr) = f + \beta h\bigl(f_x + f_y f\bigr) + \tfrac12\beta^{2}h^{2}\bigl(f_{xx} + 2f f_{xy} + f^{2}f_{yy}\bigr) + O(h^{3}) .

Hence the increment is

hΦ=(α1+α2)hf+α2βh2(fx+fyf)+O(h3)=(α1+α2)hy′+α2βh2y′′+O(h3).h\Phi = (\alpha_1+\alpha_2)h f + \alpha_2\beta h^{2}\bigl(f_x + f_y f\bigr) + O(h^{3}) = (\alpha_1+\alpha_2)h y' + \alpha_2\beta h^{2} y'' + O(h^{3}) .

The exact increment is y(x+h)−y(x)=hy′+12h2y′′+16h3y′′′+O(h4)y(x+h) - y(x) = h y' + \tfrac12 h^{2}y'' + \tfrac16 h^{3}y''' + O(h^{4}). Matching the hh and h2h^{2} terms gives exactly the two conditions α1+α2=1\alpha_1 + \alpha_2 = 1 and α2β=12\alpha_2\beta = \tfrac12, and these are necessary as well as sufficient because ff and the combination fx+fyff_x + f_y f can be prescribed independently at a point. Heun and the midpoint method satisfy them, so both have order at least 22.

For the last sentence of part 3, carry the expansion one term further. The h3h^{3} coefficient produced by the family is

12α2β2(fxx+2ffxy+f2fyy),\tfrac12\alpha_2\beta^{2}\bigl(f_{xx} + 2ff_{xy} + f^{2}f_{yy}\bigr) ,

while the exact solution has 16y′′′=16(fxx+2ffxy+f2fyy)+16fy(fx+fyf)\tfrac16 y''' = \tfrac16\bigl(f_{xx} + 2ff_{xy} + f^{2}f_{yy}\bigr) + \tfrac16 f_y\bigl(f_x + f_y f\bigr). The second group, 16fy(fx+fyf)\tfrac16 f_y(f_x+f_yf), cannot be produced at all: no choice of α2,β\alpha_2, \beta puts a term containing fyf_y into the h3h^{3} coefficient. So the family never reaches order 33, and two stages are genuinely not enough. (This is where the extra stages of RK4 earn their keep.)

AB2. Substituting the exact solution, and writing y′(x−h)=y′−hy′′+12h2y′′′+O(h3)y'(x-h) = y' - hy'' + \tfrac12 h^{2}y''' + O(h^{3}),

h2(3y′(x)−y′(x−h))=hy′+12h2y′′−14h3y′′′+O(h4).\tfrac{h}{2}\bigl(3y'(x) - y'(x-h)\bigr) = h y' + \tfrac12 h^{2}y'' - \tfrac14 h^{3}y''' + O(h^{4}) .

Subtracting this from y(x+h)−y(x)=hy′+12h2y′′+16h3y′′′+O(h4)y(x+h) - y(x) = hy' + \tfrac12 h^{2}y'' + \tfrac16 h^{3}y''' + O(h^{4}), the first two terms cancel and

τ=(16+14)h3y′′′+O(h4)=512h3y′′′+O(h4),\tau = \Bigl(\tfrac16 + \tfrac14\Bigr)h^{3}y''' + O(h^{4}) = \tfrac{5}{12}h^{3}y''' + O(h^{4}) ,

so AB2 has order 22 with the error constant 5/125/12. □\square

Remark(RK4, and why its order is asserted rather than derived here)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.6, Eq. (27.80), p. 1028; Strogatz (1994), §2.8, pp. 33-34

Matching the Taylor expansion through h4h^{4} imposes the eight order conditions through order 44 on the coefficients of a four-stage Runge-Kutta method, and verifying them by hand is several pages of bookkeeping with no idea in it. Riley, Hobson and Bence print the scheme "without derivation" for the same reason, and Strogatz calls the four numbers cunningly chosen and leaves their choice to an exercise. We follow them in stating the order rather than deriving it, and verify it in two independent ways instead.

Symbolically. Expanding yn+1y_{n+1} and the exact solution in powers of hh with computer algebra, for the non-autonomous field

f(x,y)=23+57x+311y+15x2+713xy+29y2+117x3+419xy2+123y3+329x2y+131y4+137x4f(x,y) = \tfrac23 + \tfrac57 x + \tfrac{3}{11}y + \tfrac15 x^{2} + \tfrac{7}{13}xy + \tfrac29 y^{2} + \tfrac{1}{17}x^{3} + \tfrac{4}{19}xy^{2} + \tfrac{1}{23}y^{3} + \tfrac{3}{29}x^{2}y + \tfrac{1}{31}y^{4} + \tfrac{1}{37}x^{4}

at (x,y)=(12,13)(x,y) = (\tfrac12, \tfrac13), the two series agree through h4h^{4} and first differ at h5h^{5}, with coefficient 0.02508460.0250846. The same computation returns leading powers h2h^{2} for Euler, h3h^{3} for Heun and for the midpoint rule, and h4h^{4} for the third-order scheme Riley, Hobson and Bence give as their Eq. (27.79) — that is, orders 11, 22, 22 and 33, confirming the hand derivations above and showing that this particular ff is generic enough to detect the true order.

Numerically. The error table in the first example below halves the step four times and shows the RK4 error falling by factors tending to 1616, which is the signature of order 44.

Remark(Where the hypotheses are used)Original

(L), the Lipschitz condition on Φ\Phi, is what makes errors merely grow exponentially instead of arbitrarily. It is inherited from ff: for Euler, Φ=f\Phi = f, so (L) is the Lipschitz condition of Existence and uniqueness of solutions itself. For a multi-stage method each stage is a Lipschitz function of the previous one, so if ff has Lipschitz constant KK in yy on RR then Φ\Phi has a Lipschitz constant of the form L=K(1+c1hK+c2h2K2+⋯ )L = K(1 + c_1 hK + c_2 h^{2}K^{2} + \cdots), bounded by a constant multiple of KK for h≤h0h \le h_0. Without (L) the recursion in Step 2 has nothing to bound the propagated error by: the first stage of the proof fails immediately, not just the constant.

(T) must be uniform in xx. The constant CC involves derivatives of the solution, through y′′y'', y′′′y''' and so on. On an interval where the solution approaches a singularity these blow up, and the bound is true but empty. The example below is deliberately set on [0,12][0, \tfrac12] for this reason: its exact solution 1/(1−sin⁡x)1/(1-\sin x) has a pole at x=π/2x = \pi/2, and the error constants degrade badly as that point is approached.

The iterates must stay in RR. This is a hypothesis, not a conclusion, and it is the one that is usually verified after the fact. It can genuinely fail: for y′=y2y' = y^{2}, y(0)=1y(0) = 1, whose solution blows up at x=1x = 1, an Euler step from near the pole lands far outside any region on which a Lipschitz constant was computed. In practice one integrates, checks that the computed track stayed inside the region used to compute LL, and reruns with a smaller step if not.

Order is a statement about smooth ff. Each order calculation differentiates ff as many times as the expansion requires: order pp needs f∈Cpf \in C^{p} near the solution. Applied to an ff with a kink — a switch in a control law, a table lookup, a friction law that changes form at zero velocity — RK4 is not fourth order across the kink, and refining the step buys much less than the table of ratios would suggest. The standard remedy is to stop the integration at the discontinuity and restart.

The exponential factor is sharp. Taking f(x,y)=Lyf(x,y) = Ly makes Φ\Phi exactly LL-Lipschitz, and two exact solutions separate by precisely eL(x−a)e^{L(x-a)} times their initial gap. So no sharper general bound than part 1 exists, and the eL(b−a)e^{L(b-a)} is what makes long integrations of systems with positive Lyapunov exponents (Lyapunov exponents and sensitive dependence) untrustworthy trajectory by trajectory.

Round-off sets a floor that the theorem does not see. Part 1 says the error decreases like hph^{p} forever, which is false in floating-point arithmetic: each of the (b−a)/h(b-a)/h steps commits a rounding error of relative size about the unit roundoff uu (Floating-point arithmetic and error), and these accumulate roughly as u(b−a)/hu(b-a)/h, growing as hh shrinks. The total error is therefore U-shaped in hh, with a minimum near h∼u1/(p+1)h \sim u^{1/(p+1)}. Strogatz makes exactly this point when he warns against simply choosing a tiny step and leaving it there.

Method(Running an integrator on a real problem)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.6.3, p. 1025 and §27.7, Eqs. (27.82)-(27.84), pp. 1028-1029
  1. Reduce to a first-order system. Introduce pr=y(r)p_r = y^{(r)} as in the first definition, so the problem becomes Y′=F(x,Y)Y' = F(x, Y) with Y∈RmY \in \mathbb{R}^{m}. Advance all components through each step before starting the next.
  2. Non-dimensionalise. Scale xx and each component of YY so that the quantities of interest are of order one. Step-size choices, error tolerances and the convergence table all become meaningful only after this.
  3. Estimate the two constants. Compute K=sup⁡∥∂F/∂Y∥K = \sup\lVert \partial F/\partial Y\rVert over the region you expect to visit; this gives the Lipschitz constant and the factor eK(b−a)e^{K(b-a)} that no method can avoid. If eK(b−a)e^{K(b-a)} is astronomically large, no accuracy target is achievable and the question being asked of the computation should change.
  4. Choose the method by the cost of FF. Count evaluations per step: 11 for Euler and AB2, 22 for Heun and midpoint, 44 for RK4. When FF is expensive and the solution is smooth, the higher order wins easily, because reaching a tolerance η\eta needs h∼(η)1/ph \sim (\eta)^{1/p} and so ∼η−1/p\sim \eta^{-1/p} steps.
  5. Start a multistep method with a one-step method of at least the same order. AB2 needs y1y_1 as well as y0y_0; take it from one RK4 step, whose O(h5)O(h^{5}) error cannot pollute an O(h2)O(h^{2}) computation. Riley, Hobson and Bence note the same need for the central-difference and Adams schemes and suggest a Taylor expansion; a Runge-Kutta step is the modern answer and needs no derivatives of ff.
  6. Measure the order, do not assume it. Run at hh, h/2h/2, h/4h/4 and tabulate the differences of the answers. Successive differences falling by 2p2^{p} confirm the order and simultaneously confirm that the solution is smooth enough for it.
  7. Control the step by step doubling. Take one step of size hh and two of size h/2h/2 from the same point. For a method of order pp the difference Δ\Delta of the two answers is about 2p−12^{p}-1 times the error of the finer one — equivalently (2p−1)/2p(2^{p}-1)/2^{p} times the error of the coarser one — so the finer answer carries an error of about Δ/(2p−1)\Delta/(2^{p}-1), which is Δ/15\Delta/15 for RK4; that is an error estimate for free; accept the step if it is below tolerance, and set the next step to h (η/estimate)1/(p+1)h\,(\eta/\text{estimate})^{1/(p+1)} with a safety factor of about 0.90.9. Richardson extrapolation can also be used to improve the answer, at the price of losing the error estimate.
  8. Predict and correct, if the method is implicit. Riley, Hobson and Bence's pattern — predict yn+1y_{n+1} with an explicit formula, evaluate ff there, then recompute yn+1y_{n+1} with the better formula — is the cheap way to use an implicit formula without solving an equation. Iterating the correction converges only when hh times the Lipschitz constant is small, which is precisely what fails for the stiff problems of Stability and stiff equations; there the corrector must be solved properly, by Newton's method (Root finding).
  9. Check a conserved quantity if the problem has one. A drift in the energy of a mechanical system is the clearest diagnostic there is, and for long integrations it is a reason to change the class of method entirely (Symplectic integrators).
Example(Four methods on a nonlinear problem with a known solution)Original

Take

y′=y2cos⁡x,y(0)=1,y' = y^{2}\cos x , \qquad y(0) = 1 ,

whose solution is found by separation: −1/y=sin⁡x+c-1/y = \sin x + c with c=−1c = -1, so

y(x)=11−sin⁡x,y(x) = \frac{1}{1 - \sin x} ,

valid up to the pole at x=π/2x = \pi/2. We integrate to b=12b = \tfrac12, where y(12)=1/(1−sin⁡12)=1.920954780068805y(\tfrac12) = 1/(1 - \sin\tfrac12) = 1.920954780068805. All arithmetic below was done in 4040-digit precision so that nothing reported is round-off.

One step by hand, h=0.1h = 0.1. Here f(0,1)=1f(0,1) = 1, so Euler gives y1=1.1y_1 = 1.1. For RK4,

k1=1,k2=f(0.05, 1.05)=1.101122162,k3=f(0.05, 1.0550561)=1.111752252,k4=f(0.1, 1.1111752)=1.228541972,k_1 = 1, \quad k_2 = f(0.05,\, 1.05) = 1.101122162, \quad k_3 = f(0.05,\, 1.0550561) = 1.111752252, \quad k_4 = f(0.1,\, 1.1111752) = 1.228541972 ,

and y1=1+0.16(k1+2k2+2k3+k4)=1.110904846666y_1 = 1 + \tfrac{0.1}{6}(k_1 + 2k_2 + 2k_3 + k_4) = 1.110904846666. The exact value is y(0.1)=1.110905490709y(0.1) = 1.110905490709. The three errors after one step are

Euler −1.0905×10−2,Heun −7.0774×10−4,RK4 −6.4404×10−7,\text{Euler } -1.0905\times10^{-2}, \qquad \text{Heun } -7.0774\times10^{-4}, \qquad \text{RK4 } -6.4404\times10^{-7} ,

in the ratio 1:6.49×10−2:5.91×10−51 : 6.49\times10^{-2} : 5.91\times10^{-5} — already the h2h^{2}, h3h^{3}, h5h^{5} hierarchy of local errors at a single step size.

Global errors at x=12x = \tfrac12. Each column gives the error yN−y(12)y_N - y(\tfrac12) and, beneath, the factor by which it shrinks when hh is halved. AB2 was started with one RK4 step, as step 5 of the method recommends; the column depends on that choice, and a cruder start changes its leading digits.

hh Euler Heun midpoint AB2 RK4
0.10.1 −1.56455×10−1-1.56455\times10^{-1} −1.43004×10−2-1.43004\times10^{-2} −1.51474×10−2-1.51474\times10^{-2} −3.18433×10−2-3.18433\times10^{-2} −2.57489×10−5-2.57489\times10^{-5}
0.050.05 −8.88446×10−2-8.88446\times10^{-2} −3.88394×10−3-3.88394\times10^{-3} −4.24395×10−3-4.24395\times10^{-3} −1.05151×10−2-1.05151\times10^{-2} −1.70535×10−6-1.70535\times10^{-6}
0.0250.025 −4.77691×10−2-4.77691\times10^{-2} −1.00876×10−3-1.00876\times10^{-3} −1.12144×10−3-1.12144\times10^{-3} −2.97218×10−3-2.97218\times10^{-3} −1.09364×10−7-1.09364\times10^{-7}
0.01250.0125 −2.48381×10−2-2.48381\times10^{-2} −2.56773×10−4-2.56773\times10^{-4} −2.88046×10−4-2.88046\times10^{-4} −7.85310×10−4-7.85310\times10^{-4} −6.91714×10−9-6.91714\times10^{-9}
0.006250.00625 −1.26747×10−2-1.26747\times10^{-2} −6.47541×10−5-6.47541\times10^{-5} −7.29769×10−5-7.29769\times10^{-5} −2.01464×10−4-2.01464\times10^{-4} −4.34786×10−10-4.34786\times10^{-10}
0.0031250.003125 −6.40362×10−3-6.40362\times10^{-3} −1.62578×10−5-1.62578\times10^{-5} −1.83651×10−5-1.83651\times10^{-5} −5.09951×10−5-5.09951\times10^{-5} −2.72496×10−11-2.72496\times10^{-11}
ratios 1.761, 1.860, 1.923, 1.960, 1.9791.761,\,1.860,\,1.923,\,1.960,\,1.979 3.682, 3.850, 3.929, 3.965, 3.9833.682,\,3.850,\,3.929,\,3.965,\,3.983 3.569, 3.784, 3.893, 3.947, 3.9743.569,\,3.784,\,3.893,\,3.947,\,3.974 3.028, 3.538, 3.785, 3.898, 3.9513.028,\,3.538,\,3.785,\,3.898,\,3.951 15.10, 15.59, 15.81, 15.91, 15.9615.10,\,15.59,\,15.81,\,15.91,\,15.96

The five columns converge to the factors 22, 44, 44, 44 and 1616, confirming orders 11, 22, 22, 22 and 44. Heun and the midpoint rule, the two members of the family of part 3 that we singled out, cost the same and differ only in their error constants: 1.6651.665 against 1.8811.881, so on this problem Heun's error is smaller by about 11%11\% at a fixed step. Since the error goes as h2h^{2}, that buys only a 6%6\% larger step at a given tolerance, which is no reason to prefer one over the other. AB2 approaches its asymptotic factor more slowly than Heun, as a two-step method with a larger error constant should: at h=0.1h = 0.1 its error is 2.22.2 times Heun's, although both are second order.

Cost at a fixed accuracy. Read an error constant off the finest row, ∣e∣≈Chp|e| \approx C h^{p}: it is C=2.0492C = 2.0492 for Euler, 1.66481.6648 for Heun and 0.285730.28573 for RK4. Solving Chp=10−5Ch^{p} = 10^{-5} and dividing 12\tfrac12 by the result gives

method hh for 10−510^{-5} steps evaluations of ff
Euler 4.88×10−64.88\times10^{-6} 102 458102\,458 102 458102\,458
Heun 2.451×10−32.451\times10^{-3} 205205 410410
RK4 7.691×10−27.691\times10^{-2} 77 2828

So RK4 costs about 36603660 times fewer evaluations than Euler here and about 1515 times fewer than Heun, and both advantages grow without limit as the tolerance tightens: the evaluation count scales as η−1\eta^{-1} for Euler, η−1/2\eta^{-1/2} for Heun and η−1/4\eta^{-1/4} for RK4.

The convergence bound, checked. Take the region R=[0,12]×[0,2]R = [0,\tfrac12]\times[0,2], which contains both the exact solution and every Euler iterate computed above (the largest over all six runs is 1.91461.9146, at the finest step; at h=0.1h=0.1 it is 1.76451.7645). On RR, ∣∂f/∂y∣=∣2ycos⁡x∣≤4|\partial f/\partial y| = |2y\cos x| \le 4, so L=4L = 4 serves for Euler, whose Φ\Phi is ff. The local error constant is C=12max⁡∣y′′∣C = \tfrac12\max|y''|, and y′′=2y3cos⁡2x−y2sin⁡xy'' = 2y^{3}\cos^{2}x - y^{2}\sin x increases on [0,12][0,\tfrac12] from 22 to 9.1492479.149247, so C=4.574624C = 4.574624. Part 1 then predicts

∣y(12)−yN∣  ≤  CL(eL/2−1)h  =  4.5746244(e2−1)h  =  7.30688 h.|y(\tfrac12) - y_N| \;\le\; \frac{C}{L}\bigl(e^{L/2} - 1\bigr)h \;=\; \frac{4.574624}{4}\bigl(e^{2}-1\bigr)h \;=\; 7.30688\,h .

At h=0.1h = 0.1 this is 0.7306880.730688 against the measured 0.1564550.156455, at h=0.05h = 0.05 it is 0.3653440.365344 against 0.0888450.088845, and at h=0.025h = 0.025 it is 0.1826720.182672 against 0.0477690.047769. The bound holds with a factor of between 3.83.8 and 4.74.7 to spare, and the slack has the expected cause: it assumes the worst case ∣y′′∣=9.149|y''| = 9.149 at every step, whereas y′′y'' starts at 22 and only reaches 33 at x=0.1535x = 0.1535, climbing through 3.4243.424 at x=0.2x = 0.2 and 3.9683.968 at x=0.25x = 0.25 before its final 9.1499.149; and it assumes the error is amplified at the maximal rate throughout.

ApplicationOriginal

Every simulation of a continuous system is an instance of this. The equations of a spacecraft trajectory, a reaction network, a power-system transient, a population model or a climate model's physics column are first-order systems after the reduction above, and all of them are advanced by one of the methods here or a descendant.

Why RK4 and not something better. A production solver is usually an embedded Runge-Kutta pair — two methods of adjacent order sharing their stage evaluations, so that the difference of the two answers is an error estimate at almost no extra cost, which drives the step-size controller of step 7. The classical RK4 survives because it is the cheapest scheme whose order is high enough that smooth problems are limited by round-off rather than truncation at a comfortable step size, and because its four stages map cleanly onto a force routine that is called once per stage.

Where order is the wrong figure of merit. Two situations in this chapter defeat the analysis above, and each has its own unit. A system with widely separated time scales forces the step far below what accuracy needs, because an explicit method becomes unstable long before it becomes inaccurate; the diagnosis and the implicit cure are in Stability and stiff equations. A Hamiltonian system integrated over millions of periods suffers a slow drift in its energy that no increase of order removes, because the drift is a structural defect rather than a truncation error; the remedy, a method that is exactly symplectic at every step, is in Symplectic integrators.

Method of lines. Discretising a partial differential equation in space alone (Finite-difference approximations, Spectral methods) leaves a large system of ordinary differential equations in time, to which the methods here apply directly. This is how most time-dependent PDE codes are organised, and it is why the stability restrictions of Stability, the CFL condition and von Neumann analysis and the stiffness of Stability and stiff equations are two views of a single phenomenon: the eigenvalues of the spatial discretisation grow like (Δx)−2(\Delta x)^{-2} for a diffusion operator, and the explicit integrator's step must shrink to match.

Theorem

Stability and stiff equations

Adapted

Feeds the test equation y′=λyy' = \lambda y through a numerical method to get its stability function RR, defines the region of absolute stability as ∣R∣≤1|R| \le 1 and A-stability as that region containing the whole left half-plane, proves that no explicit Runge-Kutta method is A-stable while backward Euler and the trapezoidal rule are, computes the real stability intervals [−2,0][-2,0] for Euler and Heun and [−2.78529356, 0][-2.78529356,\,0] for classical Runge-Kutta, and shows on a system with eigenvalues −1-1 and −1000-1000 that the explicit step is set by stability rather than accuracy.

Prerequisites: Integrators for ODEs, Eigenvalues and eigenvectors, Linear systems and the matrix exponential, Functions of matrices and the matrix exponential

Definition(The test equation, the stability function, and absolute stability)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.6.1, Eqs. (27.61)-(27.63), p. 1021

Riley, Hobson and Bence integrate y′=−yy' = -y, y(0)=1y(0) = 1 by Euler's method and find the recurrence yi+1=(1−h)yiy_{i+1} = (1-h)y_i. They observe that it has the form yi+1=λyiy_{i+1} = \lambda y_i and that ∣λ∣<1|\lambda| < 1 is needed if the computed solution is not to diverge, which here means 0<h<20 < h < 2; and they add that this condition does nothing to make the answer accurate. Everything in this unit is the systematic version of that observation.

Take the test equation

y′=λy,λ∈C,y' = \lambda y , \qquad \lambda \in \mathbb{C} ,

whose solution y(t)=y(0)eλty(t) = y(0)e^{\lambda t} decays exactly when Re⁡λ<0\operatorname{Re}\lambda < 0. Apply a one-step method (Integrators for ODEs) to it with step hh and write

z=hλ.z = h\lambda .

For every method of this unit the step then reduces to multiplication by a number depending on zz alone,

yn+1=R(z) yn,soyn=R(z)ny0.y_{n+1} = R(z)\,y_n , \qquad\text{so}\qquad y_n = R(z)^{n}y_0 .

The function RR is the method's stability function, and R(z)R(z) is its amplification factor at step zz. The region of absolute stability is

S  =  { z∈C  :  ∣R(z)∣≤1 },S \;=\; \bigl\{\,z \in \mathbb{C} \;:\; |R(z)| \le 1 \,\bigr\} ,

the set of zz for which the computed solution of the test equation does not grow. The method is A-stable when

C−={z:Re⁡z≤0}⊆S,\mathbb{C}^{-} = \{z : \operatorname{Re} z \le 0\} \subseteq S ,

that is, when every step size reproduces the qualitative decay of every decaying test solution.

Consistency of order p≥1p \ge 1 forces R(z)=ez+O(zp+1)R(z) = e^{z} + O(z^{p+1}) as z→0z \to 0, since the exact one-step map of the test equation is multiplication by eze^{z}; in particular R(0)=1R(0) = 1 and R′(0)=1R'(0) = 1. So SS always touches the origin, and the question is how far into the left half-plane it reaches.

Definition(Stiffness)Original

Let y′=Ay+g(x)y' = Ay + g(x) with AA an m×mm\times m matrix whose eigenvalues λ1,…,λm\lambda_1,\dots,\lambda_m all have Re⁡λi<0\operatorname{Re}\lambda_i < 0. Its stiffness ratio is

σ  =  max⁡i∣Re⁡λi∣min⁡i∣Re⁡λi∣  ≥  1.\sigma \;=\; \frac{\max_i |\operatorname{Re}\lambda_i|}{\min_i |\operatorname{Re}\lambda_i|} \;\ge\; 1 .

The problem is called stiff on an interval when σ\sigma is large and the solution being computed is dominated there by the slow components — that is, when the fast modes have already decayed and are no longer part of the answer.

The operational definition, which is the one that matters, is comparative: a problem is stiff for a given explicit method when the step size permitted by stability is far smaller than the step size permitted by accuracy. Nothing about the exact solution is difficult in such a problem; what is difficult is that an explicit method keeps paying attention to modes that contribute nothing.

For a nonlinear system y′=F(y)y' = F(y) the same language is used with A=∂F/∂yA = \partial F/\partial y evaluated along the computed track, a frozen Jacobian. That is a heuristic, not a theorem: the statements below are about constant AA, and the remark on hypotheses says what survives.

Definition(Three implicit methods)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.6.3, p. 1025, step (iii)

Backward Euler replaces the slope at the left end of the step by the slope at the right end:

yn+1=yn+h f(xn+1,yn+1).y_{n+1} = y_n + h\,f(x_{n+1}, y_{n+1}) .

The trapezoidal rule averages the two:

yn+1=yn+h2(f(xn,yn)+f(xn+1,yn+1)).y_{n+1} = y_n + \tfrac{h}{2}\bigl(f(x_n,y_n) + f(x_{n+1},y_{n+1})\bigr) .

Riley, Hobson and Bence write exactly this formula as the corrector of their predict-and-correct scheme, on the ground that the average better represents the slope across the step; used on its own, with yn+1y_{n+1} solved for rather than guessed, it is a method in its own right. (Applied to a semi-discretised diffusion equation the same formula is the Crank-Nicolson scheme of Stability, the CFL condition and von Neumann analysis.)

The implicit midpoint rule evaluates at the midpoint of the step in both arguments:

yn+1=yn+h f(xn+h2, 12(yn+yn+1)).y_{n+1} = y_n + h\,f\Bigl(x_n + \tfrac{h}{2},\ \tfrac{1}{2}(y_n + y_{n+1})\Bigr) .

In each case yn+1y_{n+1} appears on both sides, so each step requires the solution of an mm-dimensional system of equations. For a linear problem f=Ayf = Ay that is one linear solve; for a nonlinear one it is a Newton iteration (Root finding) on

G(w)=w−yn−h θ f(xn+1,w)−(explicit terms)=0,G(w) = w - y_n - h\,\theta\,f(x_{n+1}, w) - (\text{explicit terms}) = 0 ,

whose Jacobian is I−hθ ∂f/∂yI - h\theta\,\partial f/\partial y and whose cost per step is the price of A-stability.

Theorem(Stability functions, stability regions, and A-stability)Original

1 (Diagonalisable linear systems reduce to the test equation). Let AA be diagonalisable, A=PΛP−1A = P\Lambda P^{-1} with Λ=diag⁡(λ1,…,λm)\Lambda = \operatorname{diag}(\lambda_1,\dots,\lambda_m), and apply to y′=Ayy' = Ay a method whose test-equation step is multiplication by RR. Then

yn=P diag⁡(R(hλ1)n,…,R(hλm)n) P−1y0,y_n = P\,\operatorname{diag}\bigl(R(h\lambda_1)^{n},\dots,R(h\lambda_m)^{n}\bigr)\,P^{-1}y_0 ,

so yn→0y_n \to 0 for every y0y_0 if and only if ∣R(hλi)∣<1|R(h\lambda_i)| < 1 for every ii, and {yn}\{y_n\} stays bounded for every y0y_0 if and only if hλi∈Sh\lambda_i \in S for every ii.

2 (The explicit methods). For a method whose stages are substituted one into the next,

method R(z)R(z) S∩RS \cap \mathbb{R} S∩iRS \cap i\mathbb{R}
Euler 1+z1 + z [−2,0][-2, 0] {0}\{0\}
Heun, explicit midpoint 1+z+z221 + z + \tfrac{z^{2}}{2} [−2,0][-2, 0] {0}\{0\}
RK4 1+z+z22+z36+z4241 + z + \tfrac{z^{2}}{2} + \tfrac{z^{3}}{6} + \tfrac{z^{4}}{24} [z∗,0][z_{*}, 0] [−22 i, 22 i][-2\sqrt{2}\,i,\ 2\sqrt{2}\,i]

where z∗z_{*} is the unique real root of z3+4z2+12z+24=0z^{3} + 4z^{2} + 12z + 24 = 0,

z∗=−2.785293563405281623529759…z_{*} = -2.785293563405281623529759\ldots

3 (No explicit Runge-Kutta method is A-stable). If a one-step method is explicit with finitely many stages, each stage being an affine combination of yny_n and of earlier stages, then RR is a polynomial; if in addition the method is consistent, RR is non-constant, so SS is bounded and cannot contain C−\mathbb{C}^{-}.

4 (Backward Euler). R(z)=(1−z)−1R(z) = (1-z)^{-1}. The method has order 11 with local truncation error −12h2y′′(x)+O(h3)-\tfrac12 h^{2}y''(x) + O(h^{3}). It is A-stable; moreover SS is the exterior of the disc of radius 11 about z=1z = 1, so SS contains far more than the left half-plane, and ∣R(z)∣→0|R(z)| \to 0 as Re⁡z→−∞\operatorname{Re}z \to -\infty.

5 (Trapezoidal rule). R(z)=(2+z)/(2−z)R(z) = (2+z)/(2-z). The method has order 22 with local truncation error −112h3y′′′(x)+O(h4)-\tfrac{1}{12}h^{3}y'''(x) + O(h^{4}). It is A-stable, with

S=C−exactly,S = \mathbb{C}^{-} \quad\text{exactly},

and ∣R(z)∣=1|R(z)| = 1 for every zz on the imaginary axis. The implicit midpoint rule has the same stability function and the same order.

Idea of the proofOriginal

Everything follows from one observation: on the test equation, a method built from additions, multiplications by hλh\lambda and one division produces a rational function RR of z=hλz = h\lambda, and iterating the method just raises that number to a power. Boundedness of R(z)nR(z)^{n} over all nn is therefore a question about a single complex number, ∣R(z)∣≤1|R(z)| \le 1, and the whole subject is the geometry of the sublevel set SS.

That geometry splits the methods in two. An explicit method never divides, so RR is a polynomial; polynomials blow up in every direction, so SS is a bounded blob and some step size is always too large, however stable the exact solution. An implicit method divides by something like 1−z1 - z, which is large exactly where the trouble was, and the same factor that costs a linear solve per step is the factor that makes SS unbounded. For backward Euler and the trapezoidal rule the A-stability test reduces to comparing ∣1−z∣|1-z| with 11, or ∣2+z∣|2+z| with ∣2−z∣|2-z|, and both comparisons are settled by expanding the squares and cancelling: the imaginary parts drop out and only the sign of Re⁡z\operatorname{Re}z remains.

The real stability intervals in part 2 come from the same squaring. For real zz the Euler and Heun amplification factors are real, so one only has to find where they cross ±1\pm1; for RK4 the truncated exponential stays positive on the negative axis, so the binding condition is R(z)=1R(z) = 1, which factors as zz times a cubic. On the imaginary axis the cancellation is more delicate and is the reason RK4 can integrate an oscillation at all while Euler and Heun cannot.

Proof(Parts 1 and 2)Original

Part 1. Substitute yn=Pwny_n = Pw_n. Every method here applies to y′=Ayy' = Ay by replacing each evaluation f(⋅)=A(⋅)f(\cdot) = A(\cdot), so the step map is a matrix polynomial (or rational function) in hAhA; call it R(hA)R(hA), defined by the same formula as R(z)R(z) with hAhA in place of zz and II in place of 11. Since A=PΛP−1A = P\Lambda P^{-1}, every power of hAhA is P(hΛ)kP−1P(h\Lambda)^{k}P^{-1}, so R(hA)=P R(hΛ) P−1R(hA) = P\,R(h\Lambda)\,P^{-1} and R(hΛ)=diag⁡(R(hλi))R(h\Lambda) = \operatorname{diag}(R(h\lambda_i)) because hΛh\Lambda is diagonal. (For an implicit method the inverse (I−hA)−1(I - hA)^{-1} exists as long as no hλih\lambda_i equals 11, and is likewise diagonalised by PP.) Then yn=R(hA)ny0=Pdiag⁡(R(hλi)n)P−1y0y_n = R(hA)^{n}y_0 = P\operatorname{diag}(R(h\lambda_i)^{n})P^{-1}y_0. Since PP is invertible, yn→0y_n \to 0 for all y0y_0 exactly when every diagonal entry tends to 00, which is ∣R(hλi)∣<1|R(h\lambda_i)| < 1; boundedness for all y0y_0 is ∣R(hλi)∣≤1|R(h\lambda_i)| \le 1.

Part 2, the stability functions. On y′=λyy' = \lambda y each stage of a Runge-Kutta method is λ\lambda times an affine combination of earlier quantities. For Euler, yn+1=yn+hλyn=(1+z)yny_{n+1} = y_n + h\lambda y_n = (1+z)y_n. For Heun, k1=λynk_1 = \lambda y_n and k2=λ(yn+hλyn)k_2 = \lambda(y_n + h\lambda y_n), so

yn+1=yn+h2λ(yn+yn+zyn)=(1+z+z22)yn;y_{n+1} = y_n + \tfrac{h}{2}\lambda\bigl(y_n + y_n + z y_n\bigr) = \Bigl(1 + z + \tfrac{z^{2}}{2}\Bigr)y_n ;

the explicit midpoint method — yn+1=yn+hf(xn+h2, yn+h2fn)y_{n+1} = y_n + h f(x_n + \tfrac h2,\, y_n + \tfrac h2 f_n), not the implicit rule of the definitions above — gives yn+1=yn+hλ(yn+z2yn)y_{n+1} = y_n + h\lambda(y_n + \tfrac{z}{2}y_n), the same function. For RK4, writing kj=λcjynk_j = \lambda c_j y_n,

c1=1,c2=1+z2,c3=1+z2c2=1+z2+z24,c4=1+zc3=1+z+z22+z34,c_1 = 1,\quad c_2 = 1 + \tfrac{z}{2},\quad c_3 = 1 + \tfrac{z}{2}c_2 = 1 + \tfrac{z}{2} + \tfrac{z^{2}}{4},\quad c_4 = 1 + z c_3 = 1 + z + \tfrac{z^{2}}{2} + \tfrac{z^{3}}{4} ,

and

R(z)=1+z6(c1+2c2+2c3+c4)=1+z6(6+3z+z2+z34)=1+z+z22+z36+z424,R(z) = 1 + \tfrac{z}{6}\bigl(c_1 + 2c_2 + 2c_3 + c_4\bigr) = 1 + \tfrac{z}{6}\Bigl(6 + 3z + z^{2} + \tfrac{z^{3}}{4}\Bigr) = 1 + z + \tfrac{z^{2}}{2} + \tfrac{z^{3}}{6} + \tfrac{z^{4}}{24} ,

the Taylor polynomial of eze^{z} of degree 44 — as it must be, since the method has order 44 and the test equation has y(k)=λkyy^{(k)} = \lambda^{k}y.

Part 2, the real intervals. For Euler, ∣1+z∣≤1|1+z| \le 1 with zz real means −2≤z≤0-2 \le z \le 0. For Heun, g(z)=1+z+z2/2=12((1+z)2+1)>0g(z) = 1 + z + z^{2}/2 = \tfrac12\bigl((1+z)^{2}+1\bigr) > 0 for all real zz, so ∣g∣≤1|g| \le 1 reduces to g(z)≤1g(z) \le 1, that is z(1+z/2)≤0z(1 + z/2) \le 0, that is −2≤z≤0-2 \le z \le 0.

For RK4 put g(z)=1+z+z2/2+z3/6+z4/24g(z) = 1 + z + z^{2}/2 + z^{3}/6 + z^{4}/24. In fact g>0g > 0 on all of R\mathbb{R}, so ∣g∣≤1|g| \le 1 is the single inequality g(z)≤1g(z) \le 1. To see the positivity, locate the minimum: g′(z)=1+z+z2/2+z3/6g'(z) = 1 + z + z^{2}/2 + z^{3}/6 is a cubic whose derivative g′′(z)=1+z+z2/2=12((1+z)2+1)g''(z) = 1 + z + z^{2}/2 = \tfrac12\bigl((1+z)^{2}+1\bigr) is everywhere positive, so g′g' is strictly increasing and has one real root, z=−1.5960716z = -1.5960716. There g=0.2703948>0g = 0.2703948 > 0, and since g→+∞g \to +\infty at both ends that value is the global minimum. (In the variable t=−zt = -z the same polynomial 1−t+t2/2−t3/6+t4/241 - t + t^{2}/2 - t^{3}/6 + t^{4}/24 is the degree-44 Taylor polynomial of e−te^{-t}, truncated just before the negative term −t5/120-t^{5}/120 that would eventually pull it down.) So the stability condition is

z+z22+z36+z424≤0⟺z24(z3+4z2+12z+24)≤0.z + \frac{z^{2}}{2} + \frac{z^{3}}{6} + \frac{z^{4}}{24} \le 0 \qquad\Longleftrightarrow\qquad \frac{z}{24}\bigl(z^{3} + 4z^{2} + 12z + 24\bigr) \le 0 .

The cubic c(z)=z3+4z2+12z+24c(z) = z^{3}+4z^{2}+12z+24 has c′(z)=3z2+8z+12c'(z) = 3z^{2}+8z+12 with discriminant 64−144<064 - 144 < 0, so c′>0c' > 0 everywhere and cc is strictly increasing: it has exactly one real root z∗z_{*}, and the two values c(−3)=−27+36−36+24=−3c(-3) = -27 + 36 - 36 + 24 = -3 and c(−2)=−8+16−24+24=8c(-2) = -8 + 16 - 24 + 24 = 8 bracket it, −3<0<8-3 < 0 < 8, so z∗∈(−3,−2)z_{*} \in (-3,-2). Solving numerically, z∗=−2.785293563405281623529759z_{*} = -2.785293563405281623529759 (to the digits shown; substituting it back leaves the residual c(z∗)=2.5×10−24c(z_{*}) = 2.5\times10^{-24}). The product z c(z)z\,c(z) is ≤0\le 0 exactly on [z∗,0][z_{*}, 0], which is the interval claimed.

Part 2, the imaginary axes. For Euler, ∣1+iy∣2=1+y2>1|1+iy|^{2} = 1 + y^{2} > 1 unless y=0y = 0. For Heun,

∣R(iy)∣2=(1−y22)2+y2=1−y2+y44+y2=1+y44>1|R(iy)|^{2} = \Bigl(1 - \tfrac{y^{2}}{2}\Bigr)^{2} + y^{2} = 1 - y^{2} + \tfrac{y^{4}}{4} + y^{2} = 1 + \tfrac{y^{4}}{4} > 1

unless y=0y = 0. For RK4, separating R(iy)R(iy) into real and imaginary parts,

Re⁡R(iy)=1−y22+y424,Im⁡R(iy)=y−y36,\operatorname{Re}R(iy) = 1 - \tfrac{y^{2}}{2} + \tfrac{y^{4}}{24}, \qquad \operatorname{Im}R(iy) = y - \tfrac{y^{3}}{6} ,

and squaring and adding,

∣R(iy)∣2=1−y672+y8576=1+y6576(y2−8).|R(iy)|^{2} = 1 - \frac{y^{6}}{72} + \frac{y^{8}}{576} = 1 + \frac{y^{6}}{576}\bigl(y^{2} - 8\bigr) .

This is ≤1\le 1 exactly when y2≤8y^{2} \le 8, that is ∣y∣≤22=2.828427124746|y| \le 2\sqrt{2} = 2.828427124746. □\square

Proof(Parts 3, 4 and 5)Original

Part 3. Let the method have stages Y1,…,YsY_1,\dots,Y_s, each an affine combination of yny_n and of ff evaluated at earlier stages, and let yn+1y_{n+1} be an affine combination of the same quantities. On the test equation every evaluation of ff is λ\lambda times a stage, so by induction each YjY_j is pj(z)ynp_j(z)y_n with pjp_j a polynomial, and yn+1=R(z)yny_{n+1} = R(z)y_n with RR a polynomial. Consistency gives R(z)=1+z+O(z2)R(z) = 1 + z + O(z^{2}), so deg⁡R≥1\deg R \ge 1.

A non-constant polynomial satisfies ∣R(z)∣→∞|R(z)| \to \infty as ∣z∣→∞|z| \to \infty: writing R(z)=adzd+⋯R(z) = a_dz^{d} + \cdots with ad≠0a_d \ne 0 and d≥1d \ge 1, ∣R(z)∣≥∣ad∣∣z∣d−∑k<d∣ak∣∣z∣k→∞|R(z)| \ge |a_d||z|^{d} - \sum_{k<d}|a_k||z|^{k} \to \infty. Hence S={∣R∣≤1}S = \{|R| \le 1\} is bounded. The left half-plane is unbounded, so it is not contained in SS, and the method is not A-stable. Concretely, along the negative real axis a method of this kind always has a finite stability limit, as the three computed intervals in part 2 show.

Part 4. On the test equation, backward Euler reads yn+1=yn+zyn+1y_{n+1} = y_n + zy_{n+1}, so (1−z)yn+1=yn(1-z)y_{n+1} = y_n and R(z)=(1−z)−1R(z) = (1-z)^{-1}, defined for z≠1z \ne 1. Now ∣R(z)∣≤1|R(z)| \le 1 is ∣1−z∣≥1|1 - z| \ge 1, that is ∣z−1∣≥1|z - 1| \ge 1: the complement of the open unit disc centred at 11. If Re⁡z=x≤0\operatorname{Re}z = x \le 0 then

∣z−1∣2=(x−1)2+y2=1−2x+x2+y2≥1,|z-1|^{2} = (x-1)^{2} + y^{2} = 1 - 2x + x^{2} + y^{2} \ge 1 ,

because −2x≥0-2x \ge 0 and x2+y2≥0x^{2}+y^{2}\ge 0. So C−⊆S\mathbb{C}^{-} \subseteq S, and the containment is strict since, for instance, z=3z = 3 lies in SS. As Re⁡z→−∞\operatorname{Re}z \to -\infty, ∣1−z∣→∞|1-z| \to \infty and ∣R(z)∣→0|R(z)| \to 0.

For the order, substitute the exact solution. Using y′(x+h)=y′+hy′′+12h2y′′′+O(h3)y'(x+h) = y' + hy'' + \tfrac12 h^{2}y''' + O(h^{3}) with everything on the right at xx,

τ=y(x+h)−y(x)−hy′(x+h)=(hy′+h22y′′+h36y′′′)−(hy′+h2y′′+h32y′′′)+O(h4)=−12h2y′′−13h3y′′′+O(h4),\tau = y(x+h) - y(x) - h y'(x+h) = \Bigl(hy' + \tfrac{h^{2}}{2}y'' + \tfrac{h^{3}}{6}y'''\Bigr) - \Bigl(hy' + h^{2}y'' + \tfrac{h^{3}}{2}y'''\Bigr) + O(h^{4}) = -\tfrac12 h^{2}y'' - \tfrac13 h^{3}y''' + O(h^{4}) ,

so the order is 11 with the stated leading term.

Part 5. On the test equation the trapezoidal rule reads yn+1=yn+z2(yn+yn+1)y_{n+1} = y_n + \tfrac{z}{2}(y_n + y_{n+1}), so (1−z2)yn+1=(1+z2)yn\bigl(1 - \tfrac{z}{2}\bigr)y_{n+1} = \bigl(1 + \tfrac{z}{2}\bigr)y_n and

R(z)=1+z/21−z/2=2+z2−z.R(z) = \frac{1 + z/2}{1 - z/2} = \frac{2+z}{2-z} .

With z=x+iyz = x+iy,

∣2+z∣2−∣2−z∣2=((2+x)2+y2)−((2−x)2+y2)=8x.|2+z|^{2} - |2-z|^{2} = \bigl((2+x)^{2}+y^{2}\bigr) - \bigl((2-x)^{2}+y^{2}\bigr) = 8x .

So ∣R(z)∣≤1|R(z)| \le 1 if and only if x≤0x \le 0: the region of absolute stability is exactly the closed left half-plane, and ∣R∣=1|R| = 1 precisely on the imaginary axis. The method is A-stable, and no more than A-stable.

For the order,

τ=y(x+h)−y(x)−h2(y′(x)+y′(x+h)).\tau = y(x+h) - y(x) - \tfrac{h}{2}\bigl(y'(x) + y'(x+h)\bigr) .

Expanding both sides to fourth order, y(x+h)−y(x)=hy′+h22y′′+h36y′′′+h424y′′′′y(x+h)-y(x) = hy' + \tfrac{h^2}{2}y'' + \tfrac{h^3}{6}y''' + \tfrac{h^4}{24}y'''', while h2(y′+y′(x+h))=hy′+h22y′′+h34y′′′+h412y′′′′\tfrac{h}{2}(y' + y'(x+h)) = hy' + \tfrac{h^{2}}{2}y'' + \tfrac{h^{3}}{4}y''' + \tfrac{h^{4}}{12}y'''', all derivatives at xx. Subtracting, the first two terms cancel and

τ=(16−14)h3y′′′+(124−112)h4y′′′′+O(h5)=−112h3y′′′−124h4y′′′′+O(h5),\tau = \Bigl(\tfrac16 - \tfrac14\Bigr)h^{3}y''' + \Bigl(\tfrac{1}{24}-\tfrac{1}{12}\Bigr)h^{4}y'''' + O(h^{5}) = -\tfrac{1}{12}h^{3}y''' - \tfrac{1}{24}h^{4}y'''' + O(h^{5}) ,

the order is 22, and the constant is −1/12-1/12. The implicit midpoint rule gives (1−z2)yn+1=(1+z2)yn\bigl(1 - \tfrac z2\bigr)y_{n+1} = \bigl(1+\tfrac z2\bigr)y_n on the test equation as well, hence the same RR; its order is also 22. □\square

Remark(Where the hypotheses are used, and what A-stability does not buy)Original

Diagonalisability, in part 1. If AA is defective the diagonal form is replaced by a Jordan form (Jordan normal form) and R(hA)nR(hA)^{n} acquires polynomial-in-nn prefactors from the nilpotent part. The strict inequality ∣R(hλi)∣<1|R(h\lambda_i)| < 1 still forces yn→0y_n \to 0, because nkρn→0n^{k}\rho^{n}\to0 for ρ<1\rho<1; but the boundary case ∣R∣=1|R| = 1 no longer gives boundedness, so the closed region SS is the right object only in the diagonalisable case. The same caveat attaches to PP: the bound on ∥yn∥\lVert y_n\rVert carries the condition number of PP (Matrix norms and condition numbers), so a stable-but-highly-non-normal AA can produce large transient growth even when every ∣R(hλi)∣<1|R(h\lambda_i)| < 1.

Constant coefficients. Parts 1 to 5 are theorems about y′=λyy' = \lambda y and y′=Ayy' = Ay. Applying them to a nonlinear problem through the frozen Jacobian is an extrapolation that usually works and sometimes does not; it has no proof here and should be treated as a design rule, confirmed by the step-doubling error estimate of Integrators for ODEs, not as a guarantee.

Being inside SS is not enough; one needs to be well inside. This is the hypothesis most often mishandled, and it is visible in the example below. At hλ=−2h\lambda = -2 exactly, Euler has ∣R∣=1|R| = 1: the corresponding mode neither grows nor decays, so a fast transient that should have vanished within a thousandth of the interval instead survives to the end, alternating in sign. Riley, Hobson and Bence's h>1h > 1 oscillation is the same effect one step earlier: R(z)<0R(z) < 0 for z<−1z < -1 means that every decaying mode is computed as an alternating sequence.

A-stability says nothing about accuracy. It is a statement about the sign of the computed decay, not its rate. Backward Euler is A-stable and first order; at z=−50z = -50 it returns R=0.0196R = 0.0196 where the exact factor is e−50=2×10−22e^{-50} = 2\times10^{-22}, which is a wild overestimate that happens to be harmless because both are negligible.

A-stability does not damp. The trapezoidal rule has ∣R∣=1|R| = 1 on the imaginary axis and R(z)→−1R(z) \to -1 as Re⁡z→−∞\operatorname{Re}z \to -\infty. So a stiff transient is not removed, it is turned into an alternating sequence that decays only as ∣(2+z)/(2−z)∣n|(2+z)/(2-z)|^{n}, which is close to 11 for very negative zz. The example shows this costing more than half the answer. The property backward Euler has and the trapezoidal rule lacks — ∣R(z)∣→0|R(z)| \to 0 as Re⁡z→−∞\operatorname{Re}z \to -\infty, so that infinitely stiff modes are annihilated in one step — is called L-stability, and it is why production stiff solvers are built from backward differentiation formulas and from implicit Runge-Kutta methods with this extra property rather than from the trapezoidal rule.

The cost is not symmetric. Part 3 forbids A-stability only for explicit methods. The price of the implicit alternative is one Newton solve per step, which for a system of dimension mm costs O(m3)O(m^{3}) once per Jacobian factorisation and O(m2)O(m^{2}) per iteration (Solving linear systems numerically). Stiffness is therefore worth exploiting only when σ\sigma is large enough that the saved steps outnumber the added linear algebra; the crossover is problem-dependent and is why every serious library ships both kinds of solver.

Method(Diagnosing and treating stiffness)Original
  1. Get the eigenvalues. For y′=Ay+gy' = Ay + g compute the spectrum of AA; for a nonlinear system, the spectrum of ∂F/∂y\partial F/\partial y at a few representative states along the track (Computing eigenvalues). Keep the most negative real part μmax⁡\mu_{\max} and the smallest μmin⁡\mu_{\min}.
  2. Form the two candidate step sizes. The stability step is hstab=∣zedge∣/μmax⁡h_{\mathrm{stab}} = |z_{\mathrm{edge}}|/\mu_{\max}, where zedgez_{\mathrm{edge}} is the left endpoint of S∩RS\cap\mathbb{R} for the method in hand (22 for Euler and Heun, 2.7852.785 for RK4). The accuracy step is the one the error estimator asks for, which is governed by the slowest active mode, so hacc∼η1/p/μmin⁡h_{\mathrm{acc}} \sim \eta^{1/p}/\mu_{\min} for a tolerance η\eta.
  3. Compare. If hacc≤hstabh_{\mathrm{acc}} \le h_{\mathrm{stab}}, the problem is not stiff for this method: keep the explicit method. If hacc≫hstabh_{\mathrm{acc}} \gg h_{\mathrm{stab}}, it is stiff. By step 2 the two scale as hacc/hstab∼σ η1/p/∣zedge∣h_{\mathrm{acc}}/h_{\mathrm{stab}} \sim \sigma\,\eta^{1/p}/|z_{\mathrm{edge}}|: the wasted effort is proportional to σ\sigma, but the tolerance factor η1/p/∣zedge∣\eta^{1/p}/|z_{\mathrm{edge}}| in front is small, so the ratio is far below σ\sigma itself. In the example below σ=1000\sigma = 1000 while the ratio is 1010.
  4. Recognise it without eigenvalues. A reliable symptom is an adaptive explicit solver whose step size settles at a value far below what the solution's smoothness suggests, with the error estimator reporting that the rejected steps failed spectacularly rather than marginally. A second symptom is a computed solution that oscillates from step to step about a smooth exact one.
  5. Switch to an implicit method, and choose it by what the transient is doing. If fast modes are still active and must be resolved, accuracy decides and A-stability is not the issue. If they must merely be suppressed, pick a method with ∣R∣→0|R| \to 0 at −∞-\infty: backward Euler if first order will do, a backward differentiation formula or an L-stable implicit Runge-Kutta method otherwise. Avoid the trapezoidal rule for a problem whose transient is not resolved.
  6. Solve the stage equations by Newton, not by iteration. Fixed-point iteration on w=yn+hf(xn+1,w)w = y_n + hf(x_{n+1},w) contracts only when h Lip(f)<1h\,\mathrm{Lip}(f) < 1, which is the very restriction being escaped; so form I−h ∂f/∂yI - h\,\partial f/\partial y, factor it, and reuse the factorisation across steps until the Newton iteration starts needing more than two or three passes.
  7. Exploit structure. If only part of the system is fast — a stiff linear term plus a mild nonlinearity — treat that part implicitly and the rest explicitly, or use the exact exponential of the linear part as in the exponential integrators of Nonhomogeneous systems and Duhamel's principle.
Example(A system with eigenvalues −1-1 and −1000-1000)Original

Take

A=(−500.5499.5499.5−500.5),y′=Ay,y(0)=(20).A = \begin{pmatrix} -500.5 & 499.5 \\ 499.5 & -500.5\end{pmatrix} , \qquad y' = Ay , \qquad y(0) = \begin{pmatrix}2\\0\end{pmatrix} .

Since A(1,1)T=−(1,1)TA(1,1)^{\mathsf T} = -(1,1)^{\mathsf T} and A(1,−1)T=−1000 (1,−1)TA(1,-1)^{\mathsf T} = -1000\,(1,-1)^{\mathsf T}, the eigenvalues are −1-1 and −1000-1000 and the stiffness ratio is σ=1000\sigma = 1000. The initial vector is (1,1)T+(1,−1)T(1,1)^{\mathsf T} + (1,-1)^{\mathsf T}, so

y(t)=e−t(11)+e−1000t(1−1),y(t) = e^{-t}\begin{pmatrix}1\\1\end{pmatrix} + e^{-1000t}\begin{pmatrix}1\\-1\end{pmatrix} ,

and by t=0.01t = 0.01 the fast part is already e−10=4.5×10−5e^{-10} = 4.5\times10^{-5}. We ask for y1(1)y_1(1), whose exact value is e−1+e−1000=0.367879441171e^{-1} + e^{-1000} = 0.367879441171 to twelve figures. All runs below were done in 3030-digit arithmetic, so nothing shown is round-off.

What accuracy alone would ask for. Both forward and backward Euler are first order, and on the surviving mode y′=−yy' = -y a step h=0.02h = 0.02 gives (1−0.02)50=0.3641697(1-0.02)^{50} = 0.3641697, a relative error of 1.008%1.008\%; backward Euler at the same step gives a relative error of 0.992%0.992\%. So hacc≈0.02h_{\mathrm{acc}} \approx 0.02 for a one-percent answer.

What stability insists on. Part 2 requires hλ∈[−2,0]h\lambda \in [-2,0] for both eigenvalues, and the binding one is λ=−1000\lambda = -1000: h≤0.002h \le 0.002. The accuracy step is ten times too large, and this is exactly the definition of stiffness.

method hh steps hλfasth\lambda_{\mathrm{fast}} RR at the fast mode computed y1(1)y_1(1) relative error
forward Euler 0.00250.0025 400400 −2.5-2.5 −1.5-1.5 2.732144×10702.732144\times10^{70} 7.4×10707.4\times10^{70}
forward Euler 0.0020.002 500500 −2-2 −1-1 1.3675112551.367511255 2.7172.717
forward Euler 0.001250.00125 800800 −1.25-1.25 −0.25-0.25 0.36764939670.3676493967 −6.253×10−4-6.253\times10^{-4}
backward Euler 0.050.05 2020 −50-50 0.0196080.019608 0.37688948290.3768894829 2.449×10−22.449\times10^{-2}
backward Euler 0.020.02 5050 −20-20 0.0476190.047619 0.37152788210.3715278821 9.917×10−39.917\times10^{-3}
trapezoidal 0.050.05 2020 −50-50 −0.923077-0.923077 0.56952691990.5695269199 5.481×10−15.481\times10^{-1}
trapezoidal 0.020.02 5050 −20-20 −0.818182-0.818182 0.36791108070.3679110807 8.601×10−58.601\times10^{-5}
trapezoidal 0.010.01 100100 −10-10 −0.666667-0.666667 0.36787637550.3678763755 −8.333×10−6-8.333\times10^{-6}

Four things in the table are worth reading carefully.

Outside SS, disaster is immediate. At h=0.0025h = 0.0025 the fast amplification factor is −1.5-1.5, and 1.5400=2.732×10701.5^{400} = 2.732\times10^{70}. The computed answer is that number; the physics has vanished entirely. The transition is not gradual: h=0.0025h = 0.0025 is only 25%25\% above the stability limit.

On the boundary of SS, the method is useless but quiet. At h=0.002h = 0.002 the fast factor is exactly −1-1, so the fast component is reproduced as (−1)500=1(-1)^{500} = 1 for ever instead of decaying to e−1000e^{-1000}. The two contributions to y1(1)y_1(1) are 0.36751130.3675113 from the slow mode, which is accurate, and 11 from an undead transient; the answer is wrong by a factor of nearly four with nothing on the screen looking unstable.

Inside SS, with room to spare, the explicit method is correct and expensive. At h=0.00125h = 0.00125 the fast factor is −0.25-0.25 and 0.258000.25^{800} is below 10−48110^{-481}; the error 6.3×10−46.3\times10^{-4} is pure first-order truncation on the slow mode. It cost 800800 steps to get three figures. Backward Euler is no more accurate per step — it is first order on the surviving mode too, and needs about 800800 steps of its own to reach the same 6×10−46\times10^{-4} — but its gain is that it may take the steps it likes: at h=0.02h = 0.02 its 5050 steps return 0.37150.3715, two correct figures, where forward Euler at that step size returns nothing usable at all.

A-stability is not L-stability. The trapezoidal rule at h=0.05h = 0.05 is inside its stability region — the region is the whole left half-plane — and still gets the answer wrong by 55%55\%. Its fast amplification factor is −0.923077-0.923077, so after 2020 steps the spurious transient still has amplitude 0.92307720=0.20170.923077^{20} = 0.2017, which is precisely the discrepancy: 0.3678028+0.2017241=0.56952690.3678028 + 0.2017241 = 0.5695269. Reducing the step to 0.020.02 shrinks 0.818182500.818182^{50} to 4.4×10−54.4\times10^{-5} and the rule's second-order accuracy then shows: at that step its relative error is 8.601×10−58.601\times10^{-5} against backward Euler's 9.917×10−39.917\times10^{-3} at the same step, smaller by a factor of 115115. Backward Euler would have to run at h=0.04h = 0.04 to be compared at half the cost, and there its relative error is 1.967×10−21.967\times10^{-2}, worse by a factor of 229229. The trapezoidal rule is the better method here once the transient is dead, and the worse one while it is alive.

Cross-check against the semi-discrete heat equation. Replacing ∂x2\partial_x^{2} by the centred second difference on a grid of spacing Δx\Delta x turns ut=uxxu_t = u_{xx} into U′=BUU' = BU, and on the unit interval with Dirichlet ends and Δx=1/(N+1)\Delta x = 1/(N+1), BB has eigenvalues

λj=−4(Δx)2 sin⁡2(jπ Δx2),j=1,…,N,\lambda_j = -\frac{4}{(\Delta x)^{2}}\,\sin^{2}\Bigl(\frac{j\pi\,\Delta x}{2}\Bigr), \qquad j = 1,\dots,N ,

which fill out [−4/(Δx)2, 0)[-4/(\Delta x)^{2},\,0) as the grid is refined — note the π\pi in the wavenumber jπj\pi, without which the smallest eigenvalue comes out wrong. Euler's condition hλ≥−2h\lambda \ge -2 is binding at j=Nj = N, where ∣λ∣→4/(Δx)2|\lambda| \to 4/(\Delta x)^{2}, and reads Δt≤(Δx)2/2\Delta t \le (\Delta x)^{2}/2, which is exactly the limit Stability, the CFL condition and von Neumann analysis obtains by Fourier analysis of the full scheme. The two calculations are the same calculation. For the stiffness ratio, the slowest mode is j=1j = 1, where sin⁡(πΔx/2)≈πΔx/2\sin(\pi\Delta x/2) \approx \pi\Delta x/2 gives ∣λ1∣≈π2|\lambda_1| \approx \pi^{2} — the decay rate of the first heat-equation mode, independent of the grid — so

σ=∣λ∣max⁡∣λ∣min⁡≈4/(Δx)2π2=4π2(Δx)2=O((Δx)−2):\sigma = \frac{|\lambda|_{\max}}{|\lambda|_{\min}} \approx \frac{4/(\Delta x)^{2}}{\pi^{2}} = \frac{4}{\pi^{2}(\Delta x)^{2}} = O\bigl((\Delta x)^{-2}\bigr) :

refining the spatial grid makes a diffusion problem more stiff, without limit. (The quantity 4/(Δx)24/(\Delta x)^{2} on its own is ∣λ∣max⁡|\lambda|_{\max}, not the ratio.)

ApplicationOriginal

Chemical kinetics is the original stiff problem. A reaction network contains rate constants spanning many orders of magnitude — radical recombination on nanoseconds, bulk conversion on hours — and the quantity of interest is almost always the slow one. Atmospheric chemistry modules inside air-quality and climate models solve tens to hundreds of coupled species equations with σ\sigma in the range 10810^{8} to 101210^{12}; an explicit method would need a step of microseconds to simulate a day. Every such module is implicit, and most use backward differentiation formulas with a reused Jacobian factorisation, exactly as in step 6 of the method above.

Circuit and control simulation. A circuit with a parasitic capacitance has a time constant thousands of times shorter than the signal it carries; a servo with a fast inner loop and a slow outer one is stiff by design. SPICE-class simulators are built on the trapezoidal rule and on backward differentiation formulas for this reason, and the trapezoidal rule's lack of damping is a known failure mode there, where it appears as point-to-point ringing on a step response.

Method of lines for parabolic equations. As the cross-check above shows, a diffusion operator discretised in space is stiff, with the stiffness growing as (Δx)−2(\Delta x)^{-2}. This is the single reason the implicit and semi-implicit schemes of Stability, the CFL condition and von Neumann analysis and The finite element method exist, and why a spectral discretisation (Spectral methods), whose second-derivative eigenvalues reach −N2/4-N^{2}/4, is treated implicitly in its linear part as a matter of course.

Singular perturbation problems. An equation ϵy′′+ay′+by=0\epsilon y'' + ay' + by = 0 with ϵ\epsilon small has one slow root and one of size a/ϵa/\epsilon: the boundary-layer problems of Singular perturbations and boundary layers are stiff problems seen analytically, and the asymptotic layer analysis is a good guide to where the implicit solver should be allowed to take long steps and where it should not.

What stiffness is not. A chaotic system is hard to integrate for a different reason — the Lipschitz constant in the global error bound of Integrators for ODEs is positive, so errors grow exponentially no matter how stable the method. An implicit method does not help with that; nothing does. Stiffness is a cheap problem with an expensive cure, and chaos is the opposite.

Method · advanced

Symplectic integrators

Adapted

Builds the Stormer-Verlet (leapfrog) step for a separable Hamiltonian as a sandwich of three shears, proves from Ψ′TJΨ′=J\Psi'^{\mathsf T}J\Psi' = J that it is symplectic for every step size, reversible and of order exactly 22, shows that for the harmonic oscillator it conserves a shifted energy exactly so that ∣H(zn)−H(z0)∣≤ω2h2H~0/(4−ω2h2)|H(z_n) - H(z_0)| \le \omega^2h^2\tilde H_0/(4 - \omega^2h^2) for all nn, and confirms the bound numerically at 0.001250.00125 over 10610^6 steps against a steady fourth-order Runge-Kutta drift.

Prerequisites: Integrators for ODEs, The canonical equations, Taylor's theorem, Existence and uniqueness of solutions

Definition(Hamiltonian systems, flow maps and symplectic maps)AdaptedAdapted from Lee (2013), Ch. 22, Hamilton's equations (22.11) and Prop. 22.16(a), pp. 575-576; Hassani (2013), §26.4, Def. 26.4.1, p. 801 and the matrix criterion $A^{t}JA = J$, p. 804

Work on the phase space R2n\mathbb{R}^{2n} with coordinates z=(q,p)z = (q, p), q,p∈Rnq, p \in \mathbb{R}^{n}, and write

J  =  (0In−In0),J \;=\; \begin{pmatrix} 0 & I_{n} \\ -I_{n} & 0 \end{pmatrix} ,

InI_{n} being the identity. For a C2C^{2} function HH on R2n\mathbb{R}^{2n}, the canonical equations of The canonical equations read

q˙  =  ∂H∂p,p˙  =  − ∂H∂q,that isz˙  =  J ∇H(z).\dot q \;=\; \frac{\partial H}{\partial p}, \qquad \dot p \;=\; -\,\frac{\partial H}{\partial q}, \qquad\text{that is}\qquad \dot z \;=\; J\,\nabla H(z) .

Lee writes the same system in Darboux coordinates on a symplectic manifold; we stay on R2n\mathbb{R}^{2n}, which is the case a program actually integrates, and leave the invariant picture to Symplectic manifolds and Hamiltonian vector fields. Write φt\varphi_{t} for the flow map: φt(z0)\varphi_{t}(z_{0}) is the solution at time tt through z0z_{0}, defined for tt in the maximal interval given by Existence and uniqueness of solutions. Two facts about φt\varphi_{t} are the ones an integrator is asked to imitate. First, HH is constant along every trajectory, because ddtH(z)=∇H⋅J∇H=0\tfrac{d}{dt}H(z) = \nabla H \cdot J \nabla H = 0 by the antisymmetry of JJ; Lee states this as the fact that a function is constant along the integral curves of its own Hamiltonian vector field. Second, φt\varphi_{t} preserves the symplectic structure: in Lee's language a Hamiltonian vector field is symplectic, so its flow leaves the 22-form ω=∑idqi∧dpi\omega = \sum_{i} dq^{i} \wedge dp_{i} invariant.

In coordinates that second property is a condition on a Jacobian matrix. Call a C1C^{1} map Ψ:U→R2n\Psi : U \to \mathbb{R}^{2n}, U⊆R2nU \subseteq \mathbb{R}^{2n} open, symplectic if

Ψ′(z)T J Ψ′(z)  =  Jfor every z∈U,\Psi'(z)^{\mathsf T}\, J\, \Psi'(z) \;=\; J \qquad\text{for every } z \in U ,

where Ψ′(z)\Psi'(z) is the 2n×2n2n \times 2n Jacobian. This is Hassani's criterion for a matrix to represent a symplectic transformation, imposed pointwise on the derivative. Hassani also records that the symplectic transformations of a fixed symplectic vector space form a group; the only part of that we use is that a product of symplectic matrices is symplectic, which is proved in one line below.

A separable Hamiltonian is one of the form

H(q,p)  =  12 pTM−1p  +  V(q),H(q, p) \;=\; \tfrac12\, p^{\mathsf T} M^{-1} p \;+\; V(q) ,

with MM a constant symmetric positive definite mass matrix and VV the potential. Its canonical equations are q˙=M−1p\dot q = M^{-1}p and p˙=F(q)\dot p = F(q), where F=−∇VF = -\nabla V is the force. Every mechanical system with a velocity-independent potential and coordinates in which the kinetic energy is a fixed quadratic form is of this type.

A one-step method with step hh for such a system is a map Ψh:R2n→R2n\Psi_{h} : \mathbb{R}^{2n} \to \mathbb{R}^{2n} with zn+1=Ψh(zn)z_{n+1} = \Psi_{h}(z_{n}), in the sense of Integrators for ODEs. It is a symplectic integrator if Ψh\Psi_{h} is a symplectic map for every admissible VV and every hh.

Definition(The Stormer-Verlet (leapfrog) step)Original

Fix h>0h > 0 and set F=−∇VF = -\nabla V. The velocity Verlet or kick-drift-kick step takes zn=(qn,pn)z_{n} = (q_{n}, p_{n}) to zn+1=(qn+1,pn+1)z_{n+1} = (q_{n+1}, p_{n+1}) by

pn+1/2  =  pn+h2 F(qn),qn+1  =  qn+h M−1pn+1/2,pn+1  =  pn+1/2+h2 F(qn+1).p_{n+1/2} \;=\; p_{n} + \tfrac{h}{2}\,F(q_{n}), \qquad q_{n+1} \;=\; q_{n} + h\,M^{-1} p_{n+1/2}, \qquad p_{n+1} \;=\; p_{n+1/2} + \tfrac{h}{2}\,F(q_{n+1}) .

Only one new force evaluation is needed per step: F(qn+1)F(q_{n+1}) closes the current step and opens the next. In terms of the two elementary maps

Ks(q,p)  =  (q,  p+s F(q)),Ds(q,p)  =  (q+s M−1p,  p),K_{s}(q, p) \;=\; \bigl(q,\; p + s\,F(q)\bigr), \qquad D_{s}(q, p) \;=\; \bigl(q + s\,M^{-1}p,\; p\bigr) ,

the step is the sandwich

Ψh  =  Kh/2∘Dh∘Kh/2.\Psi_{h} \;=\; K_{h/2} \circ D_{h} \circ K_{h/2} .

KsK_{s} is the exact time-ss flow of the Hamiltonian V(q)V(q) alone (which moves pp and leaves qq fixed), and DsD_{s} the exact time-ss flow of 12pTM−1p\tfrac12 p^{\mathsf T}M^{-1}p alone. The method is therefore a splitting: it integrates each half of HH exactly and interleaves the two.

Eliminating the momenta gives the form in which Stormer wrote the scheme, a three-term recurrence in the positions alone,

qn+1−2qn+qn−1  =  h2M−1F(qn),q_{n+1} - 2q_{n} + q_{n-1} \;=\; h^{2} M^{-1} F(q_{n}) ,

which holds exactly, not just to leading order, for the sequence (qn)(q_{n}) produced above. The name leapfrog comes from the staggered variant that stores the half-step momenta pn+1/2p_{n+1/2} and advances positions and momenta alternately; it generates the same positions.

Dropping one of the two half kicks gives the first-order symplectic Euler step pn+1=pn+hF(qn)p_{n+1} = p_{n} + hF(q_{n}), qn+1=qn+hM−1pn+1q_{n+1} = q_{n} + hM^{-1}p_{n+1}, which is also symplectic by the argument below but is only of order 11 and is not reversible.

Method(What the leapfrog step preserves)Original

Let MM be constant, symmetric and positive definite, and let V∈C2(Rn)V \in C^{2}(\mathbb{R}^{n}). Let Ψh\Psi_{h} be the velocity Verlet step.

  1. Symplecticity. Ψh′(z)TJΨh′(z)=J\Psi_{h}'(z)^{\mathsf T} J \Psi_{h}'(z) = J for every zz and every hh, with no smallness condition on hh. Consequently det⁡Ψh′(z)=1\det \Psi_{h}'(z) = 1, so Ψh\Psi_{h} preserves Lebesgue measure on phase space exactly.
  2. Reversibility. Ψ−h=Ψh−1\Psi_{-h} = \Psi_{h}^{-1}, and with the momentum flip ρ(q,p)=(q,−p)\rho(q, p) = (q, -p) also ρ∘Ψh∘ρ∘Ψh=id\rho \circ \Psi_{h} \circ \rho \circ \Psi_{h} = \mathrm{id}.
  3. Order. If in addition V∈C4V \in C^{4}, the method has order exactly 22. In one degree of freedom with M=1M = 1 the local error is
φh(z)−Ψh(z)  =  h3(−16 p V′′(q)112(p2V′′′(q)−V′(q)V′′(q)))  +  O(h4).\varphi_{h}(z) - \Psi_{h}(z) \;=\; h^{3}\begin{pmatrix} -\tfrac{1}{6}\,p\,V''(q) \\[2pt] \tfrac{1}{12}\bigl(p^{2}V'''(q) - V'(q)V''(q)\bigr) \end{pmatrix} \;+\; O(h^{4}) .

Hence, by the global-error theorem of Integrators for ODEs, the error after a fixed time is O(h2)O(h^{2}).

  1. Energy for the harmonic oscillator. Take n=1n = 1, M=1M = 1 and V(q)=12ω2q2V(q) = \tfrac12\omega^{2}q^{2}, and put κ=1−14ω2h2\kappa = 1 - \tfrac14\omega^{2}h^{2}. If 0<ωh<20 < \omega h < 2, then the shifted energy
H~(q,p)  =  12p2  +  12 ω2κ q2\tilde H(q, p) \;=\; \tfrac12 p^{2} \;+\; \tfrac12\,\omega^{2}\kappa\, q^{2}

is conserved exactly by the step, H~(zn)=H~(z0)\tilde H(z_{n}) = \tilde H(z_{0}) for all nn, and the true energy satisfies, for all n≥0n \ge 0,

∣H(zn)−H(z0)∣  ≤  ω2h24−ω2h2  H~(z0).\bigl|H(z_{n}) - H(z_{0})\bigr| \;\le\; \frac{\omega^{2}h^{2}}{4 - \omega^{2}h^{2}}\; \tilde H(z_{0}) .

The bound does not grow with nn: the energy error oscillates forever inside a band of width O(h2)O(h^{2}) and never drifts. If ωh>2\omega h > 2 the iteration is unstable and ∥zn∥→∞\lVert z_{n}\rVert \to \infty geometrically.

Idea of the proofOriginal

Everything follows from the sandwich Ψh=Kh/2∘Dh∘Kh/2\Psi_{h} = K_{h/2} \circ D_{h} \circ K_{h/2}. Each factor is a shear: it changes one half of the coordinates by a function of the other half and leaves that other half alone. The Jacobian of a shear is a triangular block matrix whose off-diagonal block is either the Hessian of VV or the matrix M−1M^{-1} — and both are symmetric. Symmetry of that block is exactly the condition for a shear to be symplectic, and symplectic matrices are closed under multiplication, so the chain rule hands us the first claim for free, at any step size.

Reversibility is the palindrome: reading Kh/2DhKh/2K_{h/2} D_{h} K_{h/2} backwards with hh replaced by −h-h inverts each factor in the right order. A method that is its own inverse under h↦−hh \mapsto -h cannot carry a leading error term of even degree in hh: replacing hh by −h-h multiplies that term by (−1)p+1(-1)^{p+1}, while inverting the two maps multiplies it by −1-1, and the two operations give the same map, so (−1)p+1=−1(-1)^{p+1} = -1 and the order pp is even. A three-line expansion then shows the h3h^{3} coefficient is not zero, pinning the order at 22. Finally, for the harmonic oscillator the step is a 2×22 \times 2 matrix with determinant 11, and one looks for a quadratic form it preserves. There is one, it differs from HH by O(h2)O(h^{2}), and when ωh<2\omega h < 2 its level sets are ellipses — compact, so the iterates are trapped and the energy cannot wander.

ProofOriginal

Step 1: a shear with a symmetric block is symplectic. Let S,TS, T be real n×nn \times n matrices and

A=(I0SI),B=(IT0I).A = \begin{pmatrix} I & 0 \\ S & I\end{pmatrix}, \qquad B = \begin{pmatrix} I & T \\ 0 & I\end{pmatrix} .

Multiplying out,

ATJA=(IST0I)(SI−I0)=(S−STI−I0),BTJB=(0I−ITT−T).A^{\mathsf T} J A = \begin{pmatrix} I & S^{\mathsf T} \\ 0 & I\end{pmatrix}\begin{pmatrix} S & I \\ -I & 0\end{pmatrix} = \begin{pmatrix} S - S^{\mathsf T} & I \\ -I & 0 \end{pmatrix}, \qquad B^{\mathsf T} J B = \begin{pmatrix} 0 & I \\ -I & T^{\mathsf T} - T\end{pmatrix} .

Each product therefore equals JJ precisely when the off-diagonal block is its own transpose: AA is symplectic exactly when S=STS = S^{\mathsf T}, and BB exactly when T=TTT = T^{\mathsf T}. Both matrices are block triangular with identity diagonal blocks, so det⁡A=det⁡B=1\det A = \det B = 1.

Step 2: products. If ATJA=JA^{\mathsf T}JA = J and BTJB=JB^{\mathsf T}JB = J then (AB)TJ(AB)=BT(ATJA)B=BTJB=J(AB)^{\mathsf T}J(AB) = B^{\mathsf T}(A^{\mathsf T}JA)B = B^{\mathsf T}JB = J. (This is the group property Hassani records for symplectic transformations; only closure is needed here.)

Step 3: the Jacobians of the three factors. The kick KsK_{s} has Jacobian

Ks′(q,p)=(I0s F′(q)I)=(I0−s ∇2V(q)I),K_{s}'(q,p) = \begin{pmatrix} I & 0 \\ s\,F'(q) & I \end{pmatrix} = \begin{pmatrix} I & 0 \\ -s\,\nabla^{2}V(q) & I \end{pmatrix} ,

and the block −s∇2V(q)-s\nabla^{2}V(q) is symmetric because it is a multiple of a Hessian and V∈C2V \in C^{2}, so mixed partials commute. The drift DsD_{s} has Jacobian (IsM−10I)\begin{pmatrix} I & sM^{-1} \\ 0 & I\end{pmatrix}, whose block sM−1sM^{-1} is symmetric because MM is symmetric and invertible. By Step 1 both Jacobians are symplectic with determinant 11.

Step 4: claim 1. By the chain rule, Ψh′(z)=Kh/2′(w2) Dh′(w1) Kh/2′(z)\Psi_{h}'(z) = K_{h/2}'(w_{2})\,D_{h}'(w_{1})\,K_{h/2}'(z), where w1=Kh/2(z)w_{1} = K_{h/2}(z) and w2=Dh(w1)w_{2} = D_{h}(w_{1}) are the intermediate points. Each factor is symplectic by Step 3, so the product is symplectic by Step 2, and det⁡Ψh′=1⋅1⋅1=1\det \Psi_{h}' = 1 \cdot 1 \cdot 1 = 1. Preservation of Lebesgue measure is then the change-of-variables formula: ∣Ψh(E)∣=∫E∣det⁡Ψh′∣ dz=∣E∣\lvert \Psi_{h}(E)\rvert = \int_{E} \lvert\det \Psi_{h}'\rvert \,dz = \lvert E \rvert for every measurable EE. No bound on hh entered.

Step 5: claim 2. KsK_{s} and DsD_{s} are one-parameter groups: KsKs′=Ks+s′K_{s}K_{s'} = K_{s+s'} because F(q)F(q) is evaluated at a qq that the kick does not move, and DsDs′=Ds+s′D_{s}D_{s'} = D_{s+s'} for the same reason with the roles exchanged. Hence K−s=Ks−1K_{-s} = K_{s}^{-1} and D−s=Ds−1D_{-s} = D_{s}^{-1}, and

Ψ−h=K−h/2∘D−h∘K−h/2=Kh/2−1∘Dh−1∘Kh/2−1=(Kh/2∘Dh∘Kh/2)−1=Ψh−1.\Psi_{-h} = K_{-h/2} \circ D_{-h} \circ K_{-h/2} = K_{h/2}^{-1} \circ D_{h}^{-1} \circ K_{h/2}^{-1} = \bigl(K_{h/2} \circ D_{h} \circ K_{h/2}\bigr)^{-1} = \Psi_{h}^{-1} .

For the second identity, note ρKsρ=K−s\rho K_{s} \rho = K_{-s} and ρDsρ=D−s\rho D_{s}\rho = D_{-s} (flipping the momentum reverses the sign of each increment), so ρΨhρ=Ψ−h=Ψh−1\rho \Psi_{h}\rho = \Psi_{-h} = \Psi_{h}^{-1}, which rearranges to ρΨhρΨh=id\rho\Psi_{h}\rho\Psi_{h} = \mathrm{id}. This is the discrete version of the time-reversal symmetry discussed in Conservative and reversible systems.

Step 6: a reversible method has even order. Suppose the method has order exactly p≥1p \ge 1, so that φh(z)−Ψh(z)=C(z)hp+1+O(hp+2)\varphi_{h}(z) - \Psi_{h}(z) = C(z)h^{p+1} + O(h^{p+2}) with CC continuous and not identically zero. First, inverting both maps negates the leading error: putting z=Ψh−1(w)z = \Psi_{h}^{-1}(w) in Ψh(z)=φh(z)−C(z)hp+1+O(hp+2)\Psi_{h}(z) = \varphi_{h}(z) - C(z)h^{p+1} + O(h^{p+2}) gives φh(z)=w+C(z)hp+1+O(hp+2)\varphi_{h}(z) = w + C(z)h^{p+1} + O(h^{p+2}), and applying φh−1\varphi_{h}^{-1}, whose derivative is I+O(h)I + O(h), yields

Ψh−1(w)  =  φh−1(w)+C(w)hp+1+O(hp+2),\Psi_{h}^{-1}(w) \;=\; \varphi_{h}^{-1}(w) + C(w)h^{p+1} + O(h^{p+2}) ,

where C(z)C(z) could be replaced by C(w)C(w) because z=w+O(h)z = w + O(h) and CC is continuous. Second, HH is autonomous, so the flow is a group and φh−1=φ−h\varphi_{h}^{-1} = \varphi_{-h}; by Step 5, Ψh−1=Ψ−h\Psi_{h}^{-1} = \Psi_{-h}. Therefore the displayed identity says φ−h−Ψ−h=−Chp+1+O(hp+2)\varphi_{-h} - \Psi_{-h} = -C h^{p+1} + O(h^{p+2}). But the definition of the local error applied with step −h-h says φ−h−Ψ−h=C (−h)p+1+O(hp+2)\varphi_{-h} - \Psi_{-h} = C\,(-h)^{p+1} + O(h^{p+2}). Comparing the two, (−1)p+1=−1(-1)^{p+1} = -1, so pp is even.

Step 7: the h3h^{3} coefficient. Take n=1n = 1, M=1M = 1, V∈C4V \in C^{4}. The scheme gives, with no truncation at all,

qn+1=qn+hpn−h22V′(qn),pn+1=pn−h2V′(qn)−h2V′(qn+1).q_{n+1} = q_{n} + hp_{n} - \tfrac{h^{2}}{2}V'(q_{n}), \qquad p_{n+1} = p_{n} - \tfrac{h}{2}V'(q_{n}) - \tfrac{h}{2}V'(q_{n+1}) .

Expanding V′(qn+1)V'(q_{n+1}) about qnq_{n} with Taylor's theorem (Taylor's theorem) and writing q,pq, p for qn,pnq_{n}, p_{n},

pn+1=p−hV′−h22 pV′′+h34(V′V′′−p2V′′′)+O(h4),p_{n+1} = p - hV' - \tfrac{h^{2}}{2}\,pV'' + \tfrac{h^{3}}{4}\bigl(V'V'' - p^{2}V'''\bigr) + O(h^{4}) ,

all derivatives at qq. The exact solution is expanded by repeated differentiation of q˙=p\dot q = p, p˙=−V′(q)\dot p = -V'(q): q...=−V′′p\dddot q = -V''p and p¨=−V′′p\ddot p = -V'' p, p...=V′V′′−p2V′′′\dddot p = V'V'' - p^{2}V''', so

q(h)=q+hp−h22V′−h36pV′′+O(h4),p(h)=p−hV′−h22pV′′+h36(V′V′′−p2V′′′)+O(h4).q(h) = q + hp - \tfrac{h^{2}}{2}V' - \tfrac{h^{3}}{6}pV'' + O(h^{4}), \qquad p(h) = p - hV' - \tfrac{h^{2}}{2}pV'' + \tfrac{h^{3}}{6}\bigl(V'V'' - p^{2}V'''\bigr) + O(h^{4}) .

Subtracting gives the local error displayed in claim 3: the h1h^{1} and h2h^{2} terms cancel, and the h3h^{3} terms are −16pV′′-\tfrac16 pV'' in the position and (16−14)(V′V′′−p2V′′′)=112(p2V′′′−V′V′′)\bigl(\tfrac16 - \tfrac14\bigr)(V'V'' - p^{2}V''') = \tfrac{1}{12}(p^{2}V''' - V'V'') in the momentum. This coefficient is not identically zero: already for V(q)=12ω2q2V(q) = \tfrac12\omega^{2}q^{2} and p≠0p \neq 0 the first component is −16pω2≠0-\tfrac16 p\omega^{2} \neq 0. A local error whose leading term is of order h3h^{3} and does not vanish is, by the definition of order in Integrators for ODEs, a method of order exactly 22. This is consistent with Step 6, which had already excluded every odd order.

Step 8: claim 4. With V=12ω2q2V = \tfrac12\omega^{2}q^{2} the step is linear. Substituting F(q)=−ω2qF(q) = -\omega^{2}q into the three substeps and writing x=ω2h2x = \omega^{2}h^{2},

(qn+1pn+1)=Rh(qnpn),Rh=(ahca),a=1−x2,c=−ω2hκ,κ=1−x4.\begin{pmatrix} q_{n+1} \\ p_{n+1}\end{pmatrix} = R_{h}\begin{pmatrix} q_{n} \\ p_{n}\end{pmatrix}, \qquad R_{h} = \begin{pmatrix} a & h \\ c & a \end{pmatrix}, \qquad a = 1 - \tfrac{x}{2}, \quad c = -\omega^{2}h\kappa, \quad \kappa = 1 - \tfrac{x}{4} .

Two identities drive everything. First,

a2+ω2κh2=(1−x2)2+x(1−x4)=1−x+x24+x−x24=1,a^{2} + \omega^{2}\kappa h^{2} = \Bigl(1 - \tfrac{x}{2}\Bigr)^{2} + x\Bigl(1 - \tfrac{x}{4}\Bigr) = 1 - x + \tfrac{x^{2}}{4} + x - \tfrac{x^{2}}{4} = 1 ,

which is also the statement det⁡Rh=a2−hc=1\det R_{h} = a^{2} - hc = 1. Second, tr⁡Rh=2a=2−x\operatorname{tr}R_{h} = 2a = 2 - x.

Now expand H~(zn+1)=12(cq+ap)2+12ω2κ(aq+hp)2\tilde H(z_{n+1}) = \tfrac12(cq + ap)^{2} + \tfrac12\omega^{2}\kappa(aq + hp)^{2} and collect:

  • the coefficient of qpqp is ca+ω2κah=a(−ω2hκ+ω2κh)=0ca + \omega^{2}\kappa a h = a\bigl(-\omega^{2}h\kappa + \omega^{2}\kappa h\bigr) = 0;
  • the coefficient of 12p2\tfrac12 p^{2} is a2+ω2κh2=1a^{2} + \omega^{2}\kappa h^{2} = 1 by the first identity;
  • the coefficient of 12q2\tfrac12 q^{2} is c2+ω2κa2=ω2κ(ω2κh2+a2)=ω2κc^{2} + \omega^{2}\kappa a^{2} = \omega^{2}\kappa\bigl(\omega^{2}\kappa h^{2} + a^{2}\bigr) = \omega^{2}\kappa, again by the first identity.

So H~(zn+1)=12pn2+12ω2κqn2=H~(zn)\tilde H(z_{n+1}) = \tfrac12 p_{n}^{2} + \tfrac12\omega^{2}\kappa q_{n}^{2} = \tilde H(z_{n}): the shifted energy is conserved exactly, for every hh.

Assume now 0<ωh<20 < \omega h < 2, i.e. x<4x < 4, i.e. κ>0\kappa > 0. Then H~\tilde H is positive definite, so the level set {H~=H~0}\{\tilde H = \tilde H_{0}\} is an ellipse and the iterates stay on it. The two energies differ by

H(z)−H~(z)  =  12ω2(1−κ)q2  =  18 ω4h2q2  ≥  0,H(z) - \tilde H(z) \;=\; \tfrac12\omega^{2}(1 - \kappa)q^{2} \;=\; \tfrac18\,\omega^{4}h^{2}q^{2} \;\ge\; 0 ,

and on the ellipse 12ω2κq2≤H~0\tfrac12\omega^{2}\kappa q^{2} \le \tilde H_{0}, so q2≤2H~0/(ω2κ)q^{2} \le 2\tilde H_{0}/(\omega^{2}\kappa) and

0  ≤  H(zn)−H~0  ≤  ω4h28⋅2H~0ω2κ  =  ω2h24κ H~0  =  ω2h24−ω2h2 H~0.0 \;\le\; H(z_{n}) - \tilde H_{0} \;\le\; \frac{\omega^{4}h^{2}}{8}\cdot\frac{2\tilde H_{0}}{\omega^{2}\kappa} \;=\; \frac{\omega^{2}h^{2}}{4\kappa}\,\tilde H_{0} \;=\; \frac{\omega^{2}h^{2}}{4 - \omega^{2}h^{2}}\,\tilde H_{0} .

Both H(zn)H(z_{n}) and H(z0)H(z_{0}) lie in that interval of length ω2h2H~0/(4−ω2h2)\omega^{2}h^{2}\tilde H_{0}/(4 - \omega^{2}h^{2}), which gives the stated bound, uniformly in nn.

If instead ωh>2\omega h > 2 then ∣tr⁡Rh∣=x−2>2\lvert\operatorname{tr}R_{h}\rvert = x - 2 > 2 while det⁡Rh=1\det R_{h} = 1, so the eigenvalues are real and reciprocal, λ\lambda and 1/λ1/\lambda with ∣λ∣>1\lvert\lambda\rvert > 1; any initial condition with a component along the λ\lambda-eigenvector grows like ∣λ∣n\lvert\lambda\rvert^{n}. □\square

Remark(Where the hypotheses are used)Original
  • V∈C2V \in C^{2} is used once, in Step 3, to make ∇2V\nabla^{2}V symmetric. That symmetry is the whole of symplecticity. If the kick uses a force field that is not a gradient — say n=2n = 2 and F(q)=(q2,0)F(q) = (q_{2}, 0), so that the Jacobian block is h2(0100)\tfrac{h}{2}\begin{pmatrix}0 & 1\\ 0 & 0\end{pmatrix} — then S−ST≠0S - S^{\mathsf T} \neq 0 and Step 1 fails at the first factor. Of course such a system is not Hamiltonian to begin with; the point is that the integrator inherits the structure from the problem rather than creating it.
  • MM symmetric is used in the same step for the drift. MM constant is what makes DsD_{s} an exact flow and makes the drift explicit. A configuration-dependent mass matrix, which is what a Lagrangian in curvilinear coordinates produces, destroys both: the kinetic term then depends on qq as well as pp, the split is no longer into two exactly solvable pieces, and velocity Verlet in the form above does not apply.
  • V∈C4V \in C^{4} is needed only for the order statement in claim 3, because the Taylor expansions in Step 7 go to third order. Symplecticity and reversibility need no extra smoothness.
  • HH autonomous is used in Step 6, where φh−1=φ−h\varphi_{h}^{-1} = \varphi_{-h} is the group property of the flow. For a time-dependent Hamiltonian the parity argument has to be run on the extended system.
  • ωh<2\omega h < 2 is the linear stability limit, and it is sharp: at ωh=2\omega h = 2 the matrix RhR_{h} has the double eigenvalue −1-1 and is not diagonalisable, so the amplitude grows linearly in nn; beyond it, geometrically. Because leapfrog is explicit it has a bounded stability region, exactly as the explicit methods of Stability and stiff equations do, and it is a poor choice for a stiff problem. In a many-body system the relevant ω\omega is the fastest vibration present, which is why a molecular-dynamics step is set by the stiffest bond.
  • Constant hh is essential to claim 4, since H~\tilde H depends on hh. Varying the step destroys the bounded energy error even though every individual step is still symplectic; the experiment is in the second example below. A periodic step pattern is harmless, because the composition over one period is again a single fixed symplectic map; what hurts is a step chosen from the current state or from an error estimate.
Remark(The shifted energy in general: backward error analysis)Original

Claim 4 is the exactly solvable case of a general phenomenon. One asks for a modified Hamiltonian H~h\tilde H_{h} whose exact flow reproduces the numerical step. For velocity Verlet in one degree of freedom with M=1M = 1 the first correction is

H~h(q,p)  =  12p2+V(q)  +  h2(112 p2V′′(q)  −  124 V′(q)2)  +  O(h4),\tilde H_{h}(q,p) \;=\; \tfrac12 p^{2} + V(q) \;+\; h^{2}\Bigl(\tfrac{1}{12}\,p^{2}V''(q) \;-\; \tfrac{1}{24}\,V'(q)^{2}\Bigr) \;+\; O(h^{4}) ,

and we verified by symbolic expansion that the time-hh flow of this H~h\tilde H_{h} agrees with Ψh\Psi_{h} through order h3h^{3}, which is one order beyond the method itself. For V=12ω2q2V = \tfrac12\omega^{2}q^{2} the correction is h2(112ω2p2−124ω4q2)h^{2}\bigl(\tfrac{1}{12}\omega^{2}p^{2} - \tfrac{1}{24}\omega^{4}q^{2}\bigr), and expanding the product shows that H~h=(1+16ω2h2)H~+O(h4)\tilde H_{h} = \bigl(1 + \tfrac16\omega^{2}h^{2}\bigr)\tilde H + O(h^{4}), where H~\tilde H is the exactly conserved form of claim 4: the two differ only by the normalisation that makes the flow run at the right speed, since the leapfrog rotation angle per step is θ=arccos⁡(1−12ω2h2)=ωh(1+124ω2h2+⋯ )\theta = \arccos\bigl(1 - \tfrac12\omega^{2}h^{2}\bigr) = \omega h\bigl(1 + \tfrac{1}{24}\omega^{2}h^{2} + \cdots\bigr) rather than ωh\omega h.

The series H+h2H2+h4H4+⋯H + h^{2}H_{2} + h^{4}H_{4} + \cdots does not converge in general. Truncating it at an hh-dependent optimal order gives the statement that for an analytic Hamiltonian and numerical trajectories confined to a compact set, a symplectic method of order pp keeps ∣H(zn)−H(z0)∣=O(hp)\lvert H(z_{n}) - H(z_{0})\rvert = O(h^{p}) over times exponentially long in 1/h1/h. That result — backward error analysis, due to Benettin and Giorgilli and developed by Hairer, Lubich and Wanner — is not in any book in this handbook's library, so we state it only for orientation and prove nothing beyond the harmonic case of claim 4. The non-symplectic alternative has no such statement available: the energy error of a general method accumulates, and the examples below show it doing so linearly in tt.

Method(Integrating a separable Hamiltonian system with leapfrog)Original
  1. Put the problem in separable form. Identify qq, pp, the constant symmetric positive definite MM, and VV with F=−∇VF = -\nabla V. If the force you have is not a gradient, stop: leapfrog buys you nothing, and Integrators for ODEs applies instead.
  2. Fix the step from the fastest frequency. Estimate the largest frequency ωmax⁡\omega_{\max} in the problem (for a potential well, ωmax⁡2\omega_{\max}^{2} is the largest eigenvalue of M−1∇2VM^{-1}\nabla^{2}V over the region visited). The hard limit is ωmax⁡h<2\omega_{\max}h < 2; for a sensible phase error take ωmax⁡h≲0.1\omega_{\max}h \lesssim 0.1, i.e. at least about sixty steps per period of the fastest mode.
  3. Initialise. Compute F0=F(q0)F_{0} = F(q_{0}) once.
  4. Step, reusing the force: p←p+h2Fp \leftarrow p + \tfrac{h}{2}F; q←q+hM−1pq \leftarrow q + hM^{-1}p; F←F(q)F \leftarrow F(q); p←p+h2Fp \leftarrow p + \tfrac{h}{2}F. The pair (q,p)(q, p) is synchronised at the end of every step, so output needs no interpolation.
  5. Do not vary hh. Keep it fixed for the whole run; if the problem demands adaptivity (a close encounter, say), accept that the long-time energy bound is gone, or switch to a method designed for it.
  6. Monitor HH as a diagnostic, not as a correction. Plot H(zn)−H(z0)H(z_{n}) - H(z_{0}). A bounded oscillation of size O(h2)O(h^{2}) is the expected signature. A steady drift means either a coding error in the force (most often a force that is not the gradient of the potential being monitored) or a step size past the stability limit. Never rescale the velocities to force HH back: that is not a symplectic map and it throws away the property you chose the method for.
  7. Check the order by halving hh on a short run with a known answer: the error should fall by a factor of 44.
Example(The harmonic oscillator: the energy band, and what the alternatives do)Original

Take n=1n = 1, M=1M = 1, ω=1\omega = 1, so H=12p2+12q2H = \tfrac12 p^{2} + \tfrac12 q^{2}, with q0=1q_{0} = 1, p0=0p_{0} = 0 and h=0.1h = 0.1. Then H(z0)=0.5H(z_{0}) = 0.5, κ=1−0.01/4=0.9975\kappa = 1 - 0.01/4 = 0.9975 and

H~(z0)=12(0)2+12(0.9975)(1)2=0.49875.\tilde H(z_{0}) = \tfrac12(0)^{2} + \tfrac12(0.9975)(1)^{2} = 0.49875 .

One step by hand. p1/2=0+0.05⋅(−1)=−0.05p_{1/2} = 0 + 0.05\cdot(-1) = -0.05; q1=1+0.1⋅(−0.05)=0.995q_{1} = 1 + 0.1\cdot(-0.05) = 0.995; p1=−0.05+0.05⋅(−0.995)=−0.09975p_{1} = -0.05 + 0.05\cdot(-0.995) = -0.09975. Then

H(z1)=12(0.09975)2+12(0.995)2=0.004975031 25+0.495012 5=0.499987 531 25,H(z_{1}) = \tfrac12(0.09975)^{2} + \tfrac12(0.995)^{2} = 0.004975031\,25 + 0.495012\,5 = 0.499987\,531\,25 ,H~(z1)=12(0.0099500625)+12(0.9975)(0.990025)=0.004975031 25+0.493774 968 75=0.49875,\tilde H(z_{1}) = \tfrac12(0.0099500625) + \tfrac12(0.9975)(0.990025) = 0.004975031\,25 + 0.493774\,968\,75 = 0.49875 ,

the shifted energy already back to its initial value to every digit, while the true energy has moved by −1.2469×10−5-1.2469 \times 10^{-5}. A second step gives q2=0.98005q_{2} = 0.98005, p2=−0.1985025p_{2} = -0.1985025, H(z2)=0.499950622503125H(z_{2}) = 0.499950622503125, H~(z2)=0.49875\tilde H(z_{2}) = 0.49875.

The predicted band. Claim 4 gives

∣H(zn)−H(z0)∣  ≤  0.014−0.01×0.49875  =  0.00498753.99  =  0.00125\bigl|H(z_{n}) - H(z_{0})\bigr| \;\le\; \frac{0.01}{4 - 0.01}\times 0.49875 \;=\; \frac{0.0049875}{3.99} \;=\; 0.00125

for every nn. Running 10610^{6} steps, to t=105t = 10^{5} (about 1.6×1041.6 \times 10^{4} periods), the computed energy error stayed in [−1.2499999999×10−3, 9.83×10−14][-1.2499999999 \times 10^{-3},\, 9.83 \times 10^{-14}] — the lower end is the bound −h2/8=−0.00125-h^{2}/8 = -0.00125 attained to ten digits, reached whenever the orbit passes q≈0q \approx 0 — and H~\tilde H drifted by at most 1.14×10−131.14 \times 10^{-13}, which is accumulated rounding and not method error.

Order. Integrating to t=10t = 10 and comparing qNq_{N} with cos⁡10=−0.839071529…\cos 10 = -0.839071529\ldots:

hh ∣qN−cos⁡10∣\lvert q_{N} - \cos 10\rvert ratio
0.20.2 9.225232×10−39.225232\times10^{-3}
0.10.1 2.276602×10−32.276602\times10^{-3} 4.0524.052
0.050.05 5.673035×10−45.673035\times10^{-4} 4.0134.013
0.0250.025 1.417106×10−41.417106\times10^{-4} 4.0034.003
0.01250.0125 3.542044×10−53.542044\times10^{-5} 4.0014.001

The ratios converge to 44, confirming order 22.

What the non-symplectic methods do. For a linear system each classical method is multiplication by a fixed matrix, and claim 1 says the determinant measures how fast phase area is created or destroyed. With A=(01−ω20)A = \begin{pmatrix}0 & 1\\ -\omega^{2} & 0\end{pmatrix}:

  • Explicit Euler, I+hAI + hA, has det⁡=1+ω2h2=1.01\det = 1 + \omega^{2}h^{2} = 1.01. For ω=1\omega = 1 this matrix is exactly 1.01\sqrt{1.01} times a rotation, so H(zn)=(1.01)nH(z0)H(z_{n}) = (1.01)^{n}H(z_{0}) identically. At n=104n = 10^{4} that predicts a factor 1.01104=1.6358287111890×10431.01^{10^{4}} = 1.6358287111890 \times 10^{43}; the computed run gave H(zn)/H(z0)=1.6358287111889×1043H(z_{n})/H(z_{0}) = 1.6358287111889\times10^{43}, agreeing to thirteen digits.
  • Heun's method, I+hA+h22A2I + hA + \tfrac{h^{2}}{2}A^{2}, has det⁡=1+14ω4h4=1.000025\det = 1 + \tfrac14\omega^{4}h^{4} = 1.000025: still expanding, if far more slowly.
  • Classical fourth-order Runge-Kutta has det⁡=1−172ω6h6+1576ω8h8=0.9999999861284722\det = 1 - \tfrac{1}{72}\omega^{6}h^{6} + \tfrac{1}{576}\omega^{8}h^{8} = 0.9999999861284722, just below 11, so it contracts phase area by a factor 0.986220.98622 over 10610^{6} steps. The energy follows: the computed error was −6.935×10−5-6.935\times10^{-5}, −6.931×10−4-6.931\times10^{-4} and −6.888×10−3-6.888\times10^{-3} after 10410^{4}, 10510^{5} and 10610^{6} steps — a clean linear drift in tt, ten times larger for each factor of ten in the run length, against leapfrog's fixed band of 1.25×10−31.25\times10^{-3} at the same step size.

Varying the step. Repeating the 10610^{6}-step leapfrog run but drawing each step independently and uniformly from {0.05,0.1}\{0.05, 0.1\}, the energy error grew to 1.84×10−41.84\times10^{-4}, 2.77×10−32.77\times10^{-3} and 5.41×10−25.41\times10^{-2} after 10410^{4}, 10510^{5} and 10610^{6} steps (one realisation), a maximum of 5.6×10−25.6\times10^{-2} over the run, against the fixed-step 1.25×10−31.25\times10^{-3} that never moved. Alternating the two step sizes deterministically, by contrast, kept the error at 9.4×10−49.4\times10^{-4}: the two-step composition is itself one fixed symplectic map, and the argument of claim 4 applies to it.

Example(Kepler: a bounded energy error over two thousand orbits)Original

Take the planar two-body problem in relative coordinates with GM=1GM = 1 and unit reduced mass: M=I2M = I_{2} and V(q)=−1/∥q∥V(q) = -1/\lVert q\rVert, so F(q)=−q/∥q∥3F(q) = -q/\lVert q\rVert^{3}. Start at perihelion of the orbit with semi-major axis a=1a = 1 and eccentricity e=1/2e = 1/2:

q0=(0.5, 0),p0=(0, 1+e1−e)=(0, 1.7320508075688772).q_{0} = (0.5,\, 0), \qquad p_{0} = \Bigl(0,\, \sqrt{\tfrac{1+e}{1-e}}\Bigr) = (0,\, 1.7320508075688772) .

Then H(z0)=12(3)−1/0.5=−0.5=−1/(2a)H(z_{0}) = \tfrac12(3) - 1/0.5 = -0.5 = -1/(2a), the angular momentum is L0=q1p2−q2p1=0.8660254037844386L_{0} = q_{1}p_{2} - q_{2}p_{1} = 0.8660254037844386, and the period is 2πa3/2=6.2831853071795862\pi a^{3/2} = 6.283185307179586. Take h=0.01h = 0.01, about 628628 steps per orbit, and run 20002000 orbits, that is 1 256 6371\,256\,637 steps.

Leapfrog. The energy error stayed in [−1.86×10−13,  1.359193×10−4][-1.86\times10^{-13},\; 1.359193\times10^{-4}]. The maximum 1.359193×10−41.359193\times10^{-4} was already reached inside the first 250250 orbits and was still exactly that value at 500500, 10001000 and 20002000 orbits: the error oscillates with the orbital phase (largest near perihelion, where the potential is steepest) and does not accumulate. The angular momentum was conserved to 7.18×10−147.18\times10^{-14}, which is rounding. That last fact is exact, not accidental: in a central field F(q)=−g(∥q∥) qF(q) = -g(\lVert q\rVert)\,q is parallel to qq, so a kick changes LL by h2(q1F2−q2F1)=0\tfrac{h}{2}(q_{1}F_{2} - q_{2}F_{1}) = 0, and a drift changes it by h(p1p2−p2p1)=0h(p_{1}p_{2} - p_{2}p_{1}) = 0. Each of the three substeps conserves LL identically, so leapfrog does.

Fourth-order Runge-Kutta at the same step. The energy error was −3.790447×10−7-3.790447\times10^{-7}, −7.580583×10−7-7.580583\times10^{-7}, −1.516216×10−6-1.516216\times10^{-6} and −3.032789×10−6-3.032789\times10^{-6} at 250250, 500500, 10001000 and 20002000 orbits: it doubles every time the orbit count doubles, to four digits. At 20002000 orbits it is still about forty-five times smaller than leapfrog's oscillation, which is what one expects from a fourth-order method at h=0.01h = 0.01. But it is a drift, not a band: extrapolating the straight line, it reaches 1.359×10−41.359\times10^{-4} at about

2000×1.359193×10−43.032789×10−6  ≈  9.0×104orbits,2000 \times \frac{1.359193\times10^{-4}}{3.032789\times10^{-6}} \;\approx\; 9.0\times10^{4} \quad\text{orbits},

and keeps going, while the leapfrog figure is the same at 10410^{4} orbits as at 10910^{9}. Since the semi-major axis is a=−1/(2H)a = -1/(2H), a secular energy error is a secular error in the orbital period, which is the error that matters over long integrations; leapfrog does not make it.

ApplicationAdaptedAdapted from Lee (2013), Ch. 22, Example 22.18, pp. 576-577

Lee sets out the nn-body problem as a Hamiltonian system: point masses q1,…,qnq_{1}, \dots, q_{n} in R3\mathbb{R}^{3}, conservative forces derived from a potential energy VV, and the resulting Hamiltonian the sum of kinetic and potential energies. That is exactly the separable form above, with MM the diagonal matrix of masses, and it is the reason velocity Verlet is the integrator of molecular dynamics. A simulation of a protein in water runs 10810^{8} to 10910^{9} steps of 11 or 22 femtoseconds; the physical quantities wanted from it are thermodynamic averages, and these are wrong if the integrator heats or cools the system. A bounded energy error is therefore not an aesthetic preference but the condition under which the sampled ensemble means anything, and a thermostat can only be trusted on top of an integrator that is not itself pumping energy.

The same argument runs in three other places.

  • Solar system integration. Long-term studies of planetary orbits over 10810^{8} to 10910^{9} years use symplectic maps that split the Hamiltonian into Keplerian and interaction parts in the spirit of the splitting above. The question asked — is the system stable, do the eccentricities wander — is precisely a question about secular behaviour, so an integrator with a drifting energy and hence a drifting semi-major axis answers it wrongly, as the Kepler example shows in miniature.
  • Hybrid Monte Carlo in lattice field theory. A trajectory is generated by a leapfrog integration of a fictitious Hamiltonian system and then accepted with probability min⁡{1,e−ΔH}\min\{1, e^{-\Delta H}\}. Exact reversibility and exact volume preservation (claims 1 and 2, which hold at any hh) are what make this acceptance test unbiased; the O(h2)O(h^{2}) bound on ΔH\Delta H is what keeps the acceptance rate high and lets the step size be chosen on cost grounds alone.
  • Accelerator physics. Tracking a particle for 10810^{8} turns of a storage ring to decide whether its motion stays bounded is a question about an invariant torus. A non-symplectic tracker slowly contracts or expands phase-space area, manufacturing damping or blow-up that the magnets do not produce.

The limits are as sharp as the virtues. Symplectic methods are for conservative, autonomous, non-stiff problems integrated at a fixed step. Add dissipation and there is no symplectic structure to preserve; add stiffness and the explicit step limit ωmax⁡h<2\omega_{\max}h < 2 bites, so the implicit methods of Stability and stiff equations are the right tool; add adaptivity and the long-time energy bound goes, as the first example shows.

Partial differential equations

6

Method

Finite-difference approximations

Adapted

Replaces derivatives by difference quotients on a uniform grid, gives each quotient's error as an exact mean-value remainder, defines the local truncation error and the order of a scheme, and applies the recipe to the explicit schemes for the heat and wave equations, whose truncation errors are computed here term by term.

Prerequisites: Taylor's theorem, Classification of second-order equations, The one-dimensional wave equation

Definition(Grid, grid functions, difference quotients)AdaptedAdapted from Strauss (2008), §8.1, pp. 199-201, Eqs. (1)-(6)

Fix a step h=Δx>0h = \Delta x > 0 and sample a function of one variable at the points xj=j Δxx_j = j\,\Delta x, j∈Zj \in \mathbb{Z}. A grid function is a doubly infinite list of numbers uju_j, thought of as approximating u(xj)u(x_j). For a problem in space and time we also fix Δt>0\Delta t > 0, write tn=n Δtt_n = n\,\Delta t, and use ujnu_j^n for the approximation to u(xj,tn)u(x_j, t_n); here nn is an index, not an exponent.

The four difference quotients used below are the forward, backward and centred first differences and the centred second difference,

D+uj=uj+1−ujΔx,D−uj=uj−uj−1Δx,D^{+}u_j = \frac{u_{j+1} - u_j}{\Delta x}, \qquad D^{-}u_j = \frac{u_j - u_{j-1}}{\Delta x},D0uj=uj+1−uj−12 Δx,δ2uj=uj+1−2uj+uj−1(Δx)2.D^{0}u_j = \frac{u_{j+1} - u_{j-1}}{2\,\Delta x}, \qquad \delta^{2}u_j = \frac{u_{j+1} - 2u_j + u_{j-1}}{(\Delta x)^{2}} .

The same four symbols are used in the time index when needed, so that for instance (ujn+1−ujn)/Δt(u_j^{n+1} - u_j^{n})/\Delta t is the forward difference in tt.

Method(Each quotient's error, with an exact remainder)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.5, Eqs. (27.57)-(27.59), p. 1019; Strauss (2008), §8.1, p. 200

Let h>0h > 0 and let ff be real-valued on an interval containing [x−h,x+h][x-h, x+h].

  1. If f∈C2([x,x+h])f \in C^{2}([x, x+h]) there is a ξ∈(x,x+h)\xi \in (x, x+h) with
f(x+h)−f(x)h=f′(x)+h2 f′′(ξ).\frac{f(x+h) - f(x)}{h} = f'(x) + \frac{h}{2}\,f''(\xi) .

If f∈C2([x−h,x])f \in C^{2}([x-h,x]) there is a ξ∈(x−h,x)\xi \in (x-h,x) with (f(x)−f(x−h))/h=f′(x)−h2f′′(ξ)\bigl(f(x) - f(x-h)\bigr)/h = f'(x) - \tfrac{h}{2}f''(\xi).

  1. If f∈C3([x−h,x+h])f \in C^{3}([x-h, x+h]) there is a ξ∈(x−h,x+h)\xi \in (x-h, x+h) with
f(x+h)−f(x−h)2h=f′(x)+h26 f′′′(ξ).\frac{f(x+h) - f(x-h)}{2h} = f'(x) + \frac{h^{2}}{6}\,f'''(\xi) .
  1. If f∈C4([x−h,x+h])f \in C^{4}([x-h, x+h]) there is a ξ∈(x−h,x+h)\xi \in (x-h, x+h) with
f(x+h)−2f(x)+f(x−h)h2=f′′(x)+h212 f(4)(ξ).\frac{f(x+h) - 2f(x) + f(x-h)}{h^{2}} = f''(x) + \frac{h^{2}}{12}\,f^{(4)}(\xi) .

In particular the one-sided quotients are first order in hh and the two centred ones are second order, with the leading error constants h/2h/2, h2/6h^2/6 and h2/12h^2/12 reported by Riley, Hobson and Bence.

Idea of the proofOriginal

Everything comes from the two Taylor expansions of ff about xx, one stepping forward by hh and one stepping back. Subtracting them cancels the even-order terms, so the odd-order derivative f′f' survives at leading order and the first surviving error is f′′′f'''; adding them cancels the odd-order terms, so f′′f'' survives and the first error is f(4)f^{(4)}. That is the whole reason the centred quotients gain an order over the one-sided ones. The only extra care needed is that each expansion leaves its own remainder point, and the two must be merged into one: continuity of the top derivative lets the intermediate value theorem replace the average of two of its values by a single value.

ProofAdaptedAdapted from Strauss (2008), §8.1, p. 200; Riley, Hobson & Bence (2006), §27.5, Eq. (27.56), p. 1019

Step 1 (the one-sided quotients). Taylor's theorem with Lagrange remainder, applied at order one to f∈C2f \in C^{2}, gives a point ξ∈(x,x+h)\xi \in (x, x+h) with f(x+h)=f(x)+hf′(x)+12h2f′′(ξ)f(x+h) = f(x) + h f'(x) + \tfrac{1}{2}h^{2} f''(\xi). Subtract f(x)f(x) and divide by hh: this is claim 1. Applying the same expansion with −h-h in place of hh gives the backward statement, the sign of the remainder flipping because dividing 12(−h)2f′′(ξ)\tfrac12(-h)^2 f''(\xi) by −h-h produces −h2f′′(ξ)-\tfrac{h}{2}f''(\xi).

Step 2 (two expansions to third order). Let f∈C3f \in C^{3}. Taylor's theorem at order two gives points ξ+∈(x,x+h)\xi_{+} \in (x, x+h) and ξ−∈(x−h,x)\xi_{-} \in (x-h, x) with

f(x±h)=f(x)±hf′(x)+12h2f′′(x)±16h3f′′′(ξ±).f(x \pm h) = f(x) \pm h f'(x) + \tfrac{1}{2}h^{2} f''(x) \pm \tfrac{1}{6}h^{3} f'''(\xi_{\pm}) .

Step 3 (subtract). Subtracting the two displays in Step 2 cancels f(x)f(x) and the f′′f'' term, leaving

f(x+h)−f(x−h)=2hf′(x)+16h3(f′′′(ξ+)+f′′′(ξ−)).f(x+h) - f(x-h) = 2h f'(x) + \tfrac{1}{6}h^{3}\bigl(f'''(\xi_{+}) + f'''(\xi_{-})\bigr) .

Since f′′′f''' is continuous on [ξ−,ξ+][\xi_{-}, \xi_{+}], the number 12(f′′′(ξ+)+f′′′(ξ−))\tfrac12\bigl(f'''(\xi_{+}) + f'''(\xi_{-})\bigr) lies between f′′′(ξ−)f'''(\xi_-) and f′′′(ξ+)f'''(\xi_+), so by the intermediate value theorem it equals f′′′(ξ)f'''(\xi) for some ξ\xi in that interval, hence in (x−h,x+h)(x-h,x+h). The bracket is therefore 2f′′′(ξ)2f'''(\xi), and dividing by 2h2h gives claim 2.

Step 4 (add, one order higher). Let f∈C4f \in C^{4}. Taylor's theorem at order three gives η±\eta_{\pm} with

f(x±h)=f(x)±hf′(x)+12h2f′′(x)±16h3f′′′(x)+124h4f(4)(η±).f(x \pm h) = f(x) \pm h f'(x) + \tfrac{1}{2}h^{2}f''(x) \pm \tfrac{1}{6}h^{3}f'''(x) + \tfrac{1}{24}h^{4}f^{(4)}(\eta_{\pm}) .

Adding these cancels the two odd-order terms:

f(x+h)−2f(x)+f(x−h)=h2f′′(x)+124h4(f(4)(η+)+f(4)(η−)).f(x+h) - 2f(x) + f(x-h) = h^{2}f''(x) + \tfrac{1}{24}h^{4}\bigl(f^{(4)}(\eta_{+}) + f^{(4)}(\eta_{-})\bigr) .

The continuity of f(4)f^{(4)} and the same intermediate-value step turn the bracket into 2f(4)(ξ)2f^{(4)}(\xi), and dividing by h2h^{2} gives claim 3, the constant being 2/24=1/122/24 = 1/12. □\square

Remark(Where the hypotheses are used)Original

Smoothness buys the order, and nothing else does. Each claim uses exactly the differentiability that appears in its remainder term, and the stated order fails as soon as that is dropped.

  • One degree short of C2C^2. Let f(x)=∣x∣3/2f(x) = |x|^{3/2}, which is C1C^{1} on R\mathbb{R} with f′(x)=32∣x∣1/2sgn⁡xf'(x) = \tfrac32 |x|^{1/2}\operatorname{sgn} x and f′(0)=0f'(0) = 0, but has no second derivative at 00. The forward quotient at x=0x = 0 is h3/2/h=h1/2h^{3/2}/h = h^{1/2}, so its error is h\sqrt{h}: it still tends to 00, but not at rate hh. Claim 1 is unavailable because there is no f′′f'' to evaluate at ξ\xi.
  • One degree short of C4C^4. Let f(x)=∣x∣7/2f(x) = |x|^{7/2}, which is C3C^{3} on R\mathbb{R}: here f′′(x)=354∣x∣3/2f''(x) = \tfrac{35}{4}|x|^{3/2} and f′′′(x)=1058∣x∣1/2sgn⁡xf'''(x) = \tfrac{105}{8}|x|^{1/2}\operatorname{sgn} x are continuous with f′′(0)=f′′′(0)=0f''(0) = f'''(0) = 0, while f(4)(x)=10516∣x∣−1/2f^{(4)}(x) = \tfrac{105}{16}|x|^{-1/2} blows up at the origin. The centred second difference at x=0x = 0 is (h7/2+h7/2)/h2=2h3/2(h^{7/2} + h^{7/2})/h^{2} = 2h^{3/2}, an error of order h3/2h^{3/2}, not h2h^{2}. Dropping one more degree makes it worse still: for f(x)=∣x∣3f(x) = |x|^{3}, which is C2C^{2} but not C3C^{3}, the same quotient gives 2h2h. So the second-order rate of claim 3 is genuinely bought by the fourth derivative.
  • Continuity, not mere existence, of the top derivative. Steps 3 and 4 merge two remainder points into one by the intermediate value theorem, which needs f′′′f''' (respectively f(4)f^{(4)}) to be continuous on the closed interval. Without continuity one can still bound the error by the supremum of the top derivative, but the clean mean-value identity is lost.
  • The identities are exact. Because the remainders are Lagrange remainders and not O(⋅)O(\cdot) symbols, the three displays are equalities, not asymptotic statements. That is what makes the error constants testable at a single finite hh, as in the first example below.
Definition(Local truncation error, consistency, order)AdaptedAdapted from Strauss (2008), §8.1, p. 201

Write a linear evolution problem as Lu=0\mathcal{L}u = 0 (for example L=∂t−∂x2\mathcal{L} = \partial_t - \partial_x^2), and let LΔ\mathcal{L}_\Delta be the difference operator obtained by replacing every derivative in L\mathcal{L} by a difference quotient on the grid. The local truncation error of the scheme at a grid point is

τjn  =  (LΔu)(xj,tn),\tau_j^{n} \;=\; \bigl(\mathcal{L}_\Delta u\bigr)(x_j, t_n),

the residual left when the exact solution uu of Lu=0\mathcal{L}u = 0 is substituted into the difference equation. The scheme is consistent if τjn→0\tau_j^n \to 0 as Δx,Δt→0\Delta x, \Delta t \to 0, and has order (p,q)(p, q) if τjn=O((Δt)p+(Δx)q)\tau_j^n = O\bigl((\Delta t)^{p} + (\Delta x)^{q}\bigr) uniformly on the region of interest.

Strauss separates three distinct errors, and so do we. The local truncation error above is the error made in the equation at one point. The global truncation error is the error u(xj,tn)−ujnu(x_j,t_n) - u_j^n actually present in the computed solution, built up from all the local ones; he observes that following that accumulation in detail is usually out of reach, and the two can behave quite differently. Roundoff error is a separate effect, caused by the finite number of digits the machine keeps at each step, and is treated in Floating-point arithmetic and error.

Consistency alone says nothing about whether the computed solution is anywhere near the true one; what has to be added is stability, which is the subject of Stability, the CFL condition and von Neumann analysis.

Definition(The explicit scheme for the heat equation)AdaptedAdapted from Strauss (2008), §8.1, Eq. (7), p. 201; Strauss (2008), §8.2, Eqs. (1)-(2), p. 203; Strauss (2008), §8.2, Eq. (14), p. 208

For ut=uxxu_t = u_{xx}, take the forward difference in tt and the centred second difference in xx:

ujn+1−ujnΔt  =  uj+1n−2ujn+uj−1n(Δx)2.(H)\frac{u_j^{n+1} - u_j^{n}}{\Delta t} \;=\; \frac{u_{j+1}^{n} - 2u_j^{n} + u_{j-1}^{n}}{(\Delta x)^{2}} . \tag{H}

With the mesh ratio

s  =  Δt(Δx)2s \;=\; \frac{\Delta t}{(\Delta x)^{2}}

this solves for the new row in terms of the old one,

ujn+1  =  s (uj+1n+uj−1n)+(1−2s) ujn,u_j^{n+1} \;=\; s\,\bigl(u_{j+1}^{n} + u_{j-1}^{n}\bigr) + (1 - 2s)\,u_j^{n} ,

so the computation marches forward in time with no linear system to solve. A scheme with this property is called explicit. Scheme (H) is often labelled FTCS, for forward in time and centred in space.

On a bounded interval with Dirichlet data the end values u0nu_0^n and uJnu_J^n are prescribed. For a Neumann condition ux=gu_x = g at an end, Strauss recommends a ghost point just outside the interval and a centred difference across the boundary, so that the boundary is treated to the same second-order accuracy as the interior; a one-sided quotient there would contaminate the computation with an O(Δx)O(\Delta x) error by claim 1 above.

Definition(The explicit scheme for the wave equation)AdaptedAdapted from Strauss (2008), §8.3, Eqs. (1)-(2), p. 211 and Eqs. (5)-(6), p. 212; Strauss (2008), §8.4, Eqs. (1)-(2), pp. 218-219

For utt=c2uxxu_{tt} = c^{2}u_{xx} with c>0c > 0, use the centred second difference in both variables:

ujn+1−2ujn+ujn−1(Δt)2  =  c2 uj+1n−2ujn+uj−1n(Δx)2.(W)\frac{u_j^{n+1} - 2u_j^{n} + u_j^{n-1}}{(\Delta t)^{2}} \;=\; c^{2}\,\frac{u_{j+1}^{n} - 2u_j^{n} + u_{j-1}^{n}}{(\Delta x)^{2}} . \tag{W}

Writing λ=c Δt/Δx\lambda = c\,\Delta t/\Delta x (so that Strauss's parameter is s=λ2s = \lambda^{2}) and solving for the new row,

ujn+1  =  λ2(uj+1n+uj−1n)+2(1−λ2)ujn−ujn−1.u_j^{n+1} \;=\; \lambda^{2}\bigl(u_{j+1}^{n} + u_{j-1}^{n}\bigr) + 2\bigl(1 - \lambda^{2}\bigr)u_j^{n} - u_j^{n-1} .

This is again explicit, but it reaches back two rows, so two starting rows are needed. Given u(x,0)=φ(x)u(x,0) = \varphi(x) and ut(x,0)=ψ(x)u_t(x,0) = \psi(x), Strauss builds them by imposing the centred difference (uj1−uj−1)/(2Δt)=ψj(u_j^{1} - u_j^{-1})/(2\Delta t) = \psi_j and eliminating the fictitious row uj−1u_j^{-1} with (W) at n=0n = 0, which gives

uj0=φj,uj1=12λ2(φj+1+φj−1)+(1−λ2)φj+ψj Δt.u_j^{0} = \varphi_j , \qquad u_j^{1} = \tfrac{1}{2}\lambda^{2}\bigl(\varphi_{j+1} + \varphi_{j-1}\bigr) + \bigl(1 - \lambda^{2}\bigr)\varphi_j + \psi_j\,\Delta t .

A one-sided start uj1=φj+ψjΔtu_j^1 = \varphi_j + \psi_j \Delta t would be only first order and would spoil the second-order accuracy of (W).

The corresponding elliptic discretisation, the five-point formula that makes uj,ku_{j,k} the average 14(uj+1,k+uj−1,k+uj,k+1+uj,k−1)\tfrac14(u_{j+1,k} + u_{j-1,k} + u_{j,k+1} + u_{j,k-1}) of its four neighbours, is treated in Relaxation methods for elliptic problems. Which of the three prototypes one is discretising is decided by the classification of Classification of second-order equations, and it controls whether a marching method exists at all: for the elliptic case there is no time direction to march in, and a large linear system must be solved instead.

Method(Writing down a scheme and finding its order)Original
  1. Classify the equation and decide what kind of problem it is. For a hyperbolic or parabolic equation in time, the grid marches; for an elliptic equation there is no marching direction.
  2. Choose the grid xj=j Δxx_j = j\,\Delta x, tn=n Δtt_n = n\,\Delta t, and name the mesh ratio that will appear (s=Δt/(Δx)2s = \Delta t/(\Delta x)^2 for diffusion, λ=c Δt/Δx\lambda = c\,\Delta t/\Delta x for waves).
  3. Replace each derivative by a quotient from the definition above. Use centred quotients wherever the equation's symmetry allows; a one-sided quotient in time is what makes a scheme explicit.
  4. Substitute the exact solution into the resulting difference equation and expand every term by Taylor's theorem about the same grid point (xj,tn)(x_j, t_n), keeping two orders beyond the one you expect to survive.
  5. Use the differential equation itself to convert time derivatives into space derivatives (for ut=uxxu_t = u_{xx}: utt=uxxxxu_{tt} = u_{xxxx}, uttt=uxxxxxxu_{ttt} = u_{xxxxxx}). Without this step the leading terms will not combine.
  6. Collect powers of Δx\Delta x after substituting Δt\Delta t in terms of Δx\Delta x through the mesh ratio. The lowest surviving power is the order; a mesh ratio that annihilates the leading coefficient raises the order.
  7. Match the boundary and starting formulas to the interior order, using ghost points for derivative conditions and a centred start for a second-order-in-time scheme.
  8. Check the order numerically: evaluate the residual on a known exact solution at several step sizes and confirm that halving Δx\Delta x divides it by 2q2^{q}.
Example(The error constants are real numbers, and they are right)Original

Take f(x)=exf(x) = e^{x} at x=1x = 1 with h=0.1h = 0.1, so that every derivative at the point equals e=2.718281828459…e = 2.718281828459\ldots All values below were computed in 2525-digit arithmetic and are quoted to the digits shown.

Centred second difference.

e1.1−2e1+e0.90.01=2.720547818529.\frac{e^{1.1} - 2e^{1} + e^{0.9}}{0.01} = 2.720547818529 .

Its error is 2.720547818529−2.718281828459=2.265990×10−32.720547818529 - 2.718281828459 = 2.265990\times10^{-3}. Claim 3 predicts a leading error h212f(4)(ξ)\tfrac{h^2}{12}f^{(4)}(\xi), which for ξ≈1\xi \approx 1 is 0.0112 e=2.265235×10−3\tfrac{0.01}{12}\,e = 2.265235\times10^{-3}. The next term of the expansion is h4360e=7.5508×10−7\tfrac{h^{4}}{360}e = 7.5508\times10^{-7}, and

2.265235×10−3+7.5508×10−7=2.265990×10−3,2.265235\times10^{-3} + 7.5508\times10^{-7} = 2.265990\times10^{-3},

which reproduces the measured error in all seven figures shown.

Centred first difference. (e1.1−e0.9)/0.2=2.722814563947(e^{1.1} - e^{0.9})/0.2 = 2.722814563947, an error of 4.532735×10−34.532735\times10^{-3}. Claim 2 predicts h26e=4.530470×10−3\tfrac{h^{2}}{6}e = 4.530470\times10^{-3}, and adding the next term h4120e=2.2652×10−6\tfrac{h^{4}}{120}e = 2.2652\times10^{-6} gives 4.532735×10−34.532735\times10^{-3}: again all seven figures.

Forward difference. (e1.1−e1)/0.1=2.858841954874(e^{1.1} - e^{1})/0.1 = 2.858841954874, an error of 1.405601×10−11.405601\times10^{-1} against the predicted h2e=1.359141×10−1\tfrac{h}{2}e = 1.359141\times10^{-1}. The agreement is only to two figures here, and that is as it should be: the remainder h2f′′(ξ)\tfrac{h}{2}f''(\xi) is evaluated not at 11 but at some ξ∈(1,1.1)\xi \in (1, 1.1), where f′′f'' is larger by up to the factor eh=1.1052e^{h} = 1.1052. The measured ratio of error to prediction is 1.405601/1.359141=1.03421.405601/1.359141 = 1.0342, so f′′(ξ)=eξf''(\xi) = e^{\xi} with ξ=1.0336\xi = 1.0336, comfortably inside the interval the theorem allows. At this step size the one-sided quotient is worse than the centred one by a factor of 3131.

Example(Truncation error of the heat scheme, and a mesh ratio that gains two orders)Original

Let uu solve ut=uxxu_t = u_{xx} and let τ\tau be the local truncation error of (H),

τ  =  u(x,t+Δt)−u(x,t)Δt  −  u(x+Δx,t)−2u(x,t)+u(x−Δx,t)(Δx)2.\tau \;=\; \frac{u(x, t+\Delta t) - u(x,t)}{\Delta t} \;-\; \frac{u(x+\Delta x, t) - 2u(x,t) + u(x-\Delta x, t)}{(\Delta x)^{2}} .

Step 1 (expand). By Taylor's theorem in tt, and by the expansion behind claim 3 carried one term further in xx,

u(x,t+Δt)−u(x,t)Δt=ut+Δt2utt+(Δt)26uttt+O((Δt)3),\frac{u(x,t+\Delta t) - u(x,t)}{\Delta t} = u_t + \frac{\Delta t}{2}u_{tt} + \frac{(\Delta t)^{2}}{6}u_{ttt} + O\bigl((\Delta t)^{3}\bigr),u(x+Δx,t)−2u(x,t)+u(x−Δx,t)(Δx)2=uxx+(Δx)212uxxxx+(Δx)4360uxxxxxx+O((Δx)6),\frac{u(x+\Delta x,t) - 2u(x,t) + u(x-\Delta x,t)}{(\Delta x)^{2}} = u_{xx} + \frac{(\Delta x)^{2}}{12}u_{xxxx} + \frac{(\Delta x)^{4}}{360}u_{xxxxxx} + O\bigl((\Delta x)^{6}\bigr),

all derivatives being taken at (x,t)(x,t). Written with that explicit O((Δx)6)O\bigl((\Delta x)^{6}\bigr) remainder, the second line needs uu to be C8C^{8} in xx (the expansion is carried to order seven with a Lagrange remainder); C6C^{6} would give the (Δx)4(\Delta x)^{4} term only with an o((Δx)4)o\bigl((\Delta x)^{4}\bigr) error. Solutions of the heat equation are C∞C^{\infty} in xx, so neither requirement bites here.

Step 2 (use the equation). The terms utu_t and uxxu_{xx} cancel. Differentiating ut=uxxu_t = u_{xx} in tt gives utt=uxxxxu_{tt} = u_{xxxx}, and once more uttt=uxxxxxxu_{ttt} = u_{xxxxxx}.

Step 3 (collect in Δx\Delta x). Put Δt=s(Δx)2\Delta t = s(\Delta x)^{2}:

τ  =  (Δx)2(s2−112)uxxxx  +  (Δx)4(s26−1360)uxxxxxx  +  O((Δx)6).\tau \;=\; (\Delta x)^{2}\Bigl(\frac{s}{2} - \frac{1}{12}\Bigr)u_{xxxx} \;+\;(\Delta x)^{4}\Bigl(\frac{s^{2}}{6} - \frac{1}{360}\Bigr)u_{xxxxxx} \;+\;O\bigl((\Delta x)^{6}\bigr).

So (H) is consistent, of order one in Δt\Delta t and two in Δx\Delta x, hence of order two in Δx\Delta x at fixed ss — except at s=1/6s = 1/6, where the bracket s/2−1/12s/2 - 1/12 vanishes and the scheme becomes fourth order in Δx\Delta x.

Step 4 (check it). Take the exact solution u(x,t)=e−tsin⁡xu(x,t) = e^{-t}\sin x, for which uxxxx=uu_{xxxx} = u and uxxxxxx=−uu_{xxxxxx} = -u, and evaluate τ\tau at x=1x = 1, t=0t = 0, where u=sin⁡1=0.8414710u = \sin 1 = 0.8414710.

Δx\Delta x τ\tau at s=1/4s = 1/4 ratio τ\tau at s=1/6s = 1/6 ratio
0.10.1 3.499706×10−43.499706\times10^{-4} −1.557074×10−7-1.557074\times10^{-7}
0.050.05 8.761306×10−58.761306\times10^{-5} 3.99453.9945 −9.737364×10−9-9.737364\times10^{-9} 15.99115.991
0.0250.025 2.191080×10−52.191080\times10^{-5} 3.99863.9986 −6.086735×10−10-6.086735\times10^{-10} 15.99815.998
0.01250.0125 5.478170×10−65.478170\times10^{-6} 3.99973.9997 −3.804348×10−11-3.804348\times10^{-11} 15.99915.999

The ratios tend to 44 and to 1616, confirming orders 22 and 44. The predicted leading values agree as well. At s=1/4s = 1/4 and Δx=0.1\Delta x = 0.1 the formula gives (0.01)(18−112)(0.8414710)=3.506129×10−4(0.01)\bigl(\tfrac18 - \tfrac1{12}\bigr)(0.8414710) = 3.506129\times10^{-4} against the measured 3.499706×10−43.499706\times10^{-4}. At s=1/6s = 1/6 the surviving coefficient is

(s26−1360)uxxxxxx=(1216−1360)(−u)=−u540,\Bigl(\frac{s^{2}}{6} - \frac{1}{360}\Bigr)u_{xxxxxx} = \Bigl(\frac{1}{216} - \frac{1}{360}\Bigr)(-u) = -\frac{u}{540},

so τ≈−(Δx)4(0.8414710)/540=−1.5583×10−7\tau \approx -(\Delta x)^{4}(0.8414710)/540 = -1.5583\times10^{-7} at Δx=0.1\Delta x = 0.1, against the measured −1.5571×10−7-1.5571\times10^{-7}.

A warning the next unit makes precise: s=1/6s = 1/6 is a consistency bonus only. It happens to lie inside the stability range of (H), but nothing in this calculation says so.

Example(Truncation error of the wave scheme, and the step that is exact)Original

The same procedure applied to (W) is shorter. For a solution of utt=c2uxxu_{tt} = c^{2}u_{xx},

τ=utt+(Δt)212utttt−c2uxx−c2(Δx)212uxxxx+O((Δx)4),\tau = u_{tt} + \frac{(\Delta t)^{2}}{12}u_{tttt} - c^{2}u_{xx} - \frac{c^{2}(\Delta x)^{2}}{12}u_{xxxx} + O\bigl((\Delta x)^{4}\bigr),

the first and third terms cancelling. Differentiating the equation twice in tt gives utttt=c4uxxxxu_{tttt} = c^{4}u_{xxxx}, and with Δt=λ Δx/c\Delta t = \lambda\,\Delta x/c,

τ  =  c2(Δx)212(λ2−1)uxxxx  +  O((Δx)4).\tau \;=\; \frac{c^{2}(\Delta x)^{2}}{12}\bigl(\lambda^{2} - 1\bigr)u_{xxxx} \;+\; O\bigl((\Delta x)^{4}\bigr).

Taking c=2c = 2 and the exact solution u=sin⁡x cos⁡2tu = \sin x\,\cos 2t, at x=1x = 1, t=0.3t = 0.3 and λ=1/2\lambda = 1/2 the computed residuals are −1.735517×10−3-1.735517\times10^{-3}, −4.340148×10−4-4.340148\times10^{-4}, −1.085122×10−4-1.085122\times10^{-4} and −2.712857×10−5-2.712857\times10^{-5} for Δx=0.1,0.05,0.025,0.0125\Delta x = 0.1, 0.05, 0.025, 0.0125, with ratios 3.99883.9988, 3.99973.9997 and 3.99993.9999. At this point uxxxx=sin⁡1 cos⁡0.6=0.6944960u_{xxxx} = \sin 1\,\cos 0.6 = 0.6944960 (not sin⁡1\sin 1: the example is evaluated at t=0.3t = 0.3, not at t=0t = 0), so the predicted leading value at Δx=0.1\Delta x = 0.1 is 4(0.01)12(−34)(0.6944960)=−1.736240×10−3\tfrac{4(0.01)}{12}\bigl(-\tfrac34\bigr)(0.6944960) = -1.736240\times10^{-3}, against the measured −1.735517×10−3-1.735517\times10^{-3}.

At λ=1\lambda = 1 the coefficient vanishes, and the computed residual drops to 5×10−395\times10^{-39} in 4040-digit arithmetic, that is, to zero. This is not an accident of the leading term. With c Δt=Δxc\,\Delta t = \Delta x the scheme reads ujn+1=uj+1n+uj−1n−ujn−1u_j^{n+1} = u_{j+1}^{n} + u_{j-1}^{n} - u_j^{n-1}; substituting a travelling wave u=f(x−ct)u = f(x - ct) and writing z=xj−ctnz = x_j - ct_n, the three terms on the right are f(z+Δx)f(z + \Delta x), f(z−Δx)f(z - \Delta x) and f(z+Δx)f(z + \Delta x), whose combination is f(z−Δx)f(z - \Delta x), and that is exactly ujn+1u_j^{n+1}. The same holds for g(x+ct)g(x+ct), so by d'Alembert's formula (The one-dimensional wave equation) the scheme reproduces every solution of the one-dimensional wave equation exactly when λ=1\lambda = 1. Strauss observes numerically that λ=1\lambda = 1 gives an excellent approximation while λ2=2\lambda^2 = 2 gives a useless one; the first half of that is explained here, the second half in Stability, the CFL condition and von Neumann analysis.

ApplicationOriginal

Finite differences are how most of the partial differential equations of geophysics and engineering are actually solved, and the error constants above are what set the cost of a run.

In an atmospheric or ocean model the horizontal grid spacing is chosen first, from the features that must be resolved, and the vertical diffusion of heat and momentum is then discretised by a scheme of the form (H). Because the order in Δx\Delta x is two, dividing the grid spacing by two to cut the discretisation error by four multiplies the number of columns by four in two horizontal dimensions; the companion stability constraint on Δt\Delta t, derived in Stability, the CFL condition and von Neumann analysis, multiplies the number of time steps as well, so the total cost grows by a factor of at least sixteen. That single arithmetic fact is why operational forecasting centres buy resolution in small increments, and why higher-order and spectral discretisations (Spectral methods) remain attractive even though each step of them costs more.

In seismic modelling the scheme (W) is the standard tool, and the exactness at λ=1\lambda = 1 in one dimension is the reason practitioners speak of a magic time step. In more than one space dimension no such step exists, but λ\lambda is still pushed as close to its stability limit as the geometry allows, both for speed and because, as the formula for τ\tau shows, the truncation error shrinks as λ→1\lambda \to 1.

Theorem

Stability, the CFL condition and von Neumann analysis

Adapted

Feeds a single discrete Fourier mode through a constant-coefficient difference scheme to read off its amplification factor, proves that this gives the limits Δt≤(Δx)2/2\Delta t \le (\Delta x)^2/2 for the explicit heat scheme and c Δt≤Δxc\,\Delta t \le \Delta x for the explicit wave scheme, derives the Courant-Friedrichs-Lewy condition from the domains of dependence, and records the Lax equivalence theorem that converts stability plus consistency into convergence.

Prerequisites: Finite-difference approximations, The discrete Fourier transform and the FFT

Definition(Discrete modes and the amplification factor)AdaptedAdapted from Strauss (2008), §8.2, Eqs. (4)-(6) and (13), pp. 205-207; Strauss (2008), §8.3, p. 213

Work on the whole line, or on a periodic grid, with a constant-coefficient one-step scheme: there are finitely many real or complex numbers ama_m, independent of jj and nn, with

ujn+1  =  ∑mam uj+m n.u_j^{n+1} \;=\; \sum_{m} a_m\, u_{j+m}^{\,n} .

Substitute a single discrete mode

ujn  =  ξ n eikjΔx,u_j^{n} \;=\; \xi^{\,n}\,e^{i k j \Delta x},

a geometric sequence in time times a grid plane wave in space. The spatial factor comes out of the sum, and what is left is a number,

  ξ(θ)  =  ∑mam eimθ  θ=k Δx,\boxed{\;\xi(\theta) \;=\; \sum_m a_m\,e^{i m \theta}\;} \qquad \theta = k\,\Delta x ,

the amplification factor of the scheme. The mode is then reproduced exactly at the next time level, multiplied by ξ\xi; after nn steps its size is ∣ξ∣n|\xi|^{n} times its initial size.

Only θ=k Δx\theta = k\,\Delta x enters, and eikjΔxe^{ikj\Delta x} is unchanged when θ\theta moves by 2π2\pi: two wavenumbers whose θ\theta differ by a multiple of 2π2\pi give literally the same grid function. This is aliasing, exactly as in The discrete Fourier transform and the FFT, and it means that θ\theta ranges over [−π,π][-\pi, \pi] and no further. The shortest wave the grid can carry is θ=π\theta = \pi, the sawtooth (−1)j(-1)^{j} with two grid points per wavelength.

The scheme satisfies the von Neumann condition if there is a constant CC, independent of kk and of the step sizes, with

∣ξ(θ)∣  ≤  1+C Δtfor all θ∈[−π,π]|\xi(\theta)| \;\le\; 1 + C\,\Delta t \qquad\text{for all } \theta \in [-\pi,\pi]

and all sufficiently small Δt\Delta t. Strauss states the condition in this form, citing Richtmyer and Morton, and notes that the slack C ΔtC\,\Delta t is what is needed for problems whose exact solutions grow in time; when the exact solution does not grow, the sharper requirement ∣ξ∣≤1|\xi| \le 1 is the one to use, and it is the one tested below. The slack is harmless because (1+CΔt)n≤eCT(1 + C\Delta t)^{n} \le e^{CT} whenever n Δt≤Tn\,\Delta t \le T, so a mode can grow by at most a fixed factor over a fixed time interval, whereas a violation of the condition by a fixed amount compounds without limit as the grid is refined.

Theorem(Stability limits of the two explicit model schemes)AdaptedAdapted from Strauss (2008), §8.2, Eqs. (9)-(10), pp. 206-207; Strauss (2008), §8.3, Eqs. (7)-(9), pp. 213-214

Let θ=k Δx∈[−π,π]\theta = k\,\Delta x \in [-\pi,\pi].

(a) The explicit heat scheme. For scheme (H) of Finite-difference approximations, with mesh ratio s=Δt/(Δx)2s = \Delta t/(\Delta x)^{2}, the amplification factor is

ξ(θ)  =  1−2s(1−cos⁡θ)  =  1−4s sin⁡2 ⁣θ2,\xi(\theta) \;=\; 1 - 2s\bigl(1 - \cos\theta\bigr) \;=\; 1 - 4s\,\sin^{2}\!\frac{\theta}{2},

which is real. Then

∣ξ(θ)∣≤1  for every θ∈[−π,π]⟺s≤12,that isΔt≤12(Δx)2.|\xi(\theta)| \le 1 \ \text{ for every } \theta \in [-\pi,\pi] \qquad\Longleftrightarrow\qquad s \le \tfrac12, \quad\text{that is}\quad \Delta t \le \tfrac12 (\Delta x)^{2} .

If s>1/2s > 1/2 then ξ(π)=1−4s<−1\xi(\pi) = 1 - 4s < -1, and the sawtooth mode is multiplied by the fixed factor 4s−1>14s - 1 > 1 at every step, so the von Neumann condition fails for every CC.

(b) The explicit wave scheme. For scheme (W) of Finite-difference approximations, with λ=c Δt/Δx\lambda = c\,\Delta t/\Delta x, the mode ujn=ξneikjΔxu_j^n = \xi^n e^{ikj\Delta x} satisfies the quadratic

ξ2−2(1+p) ξ+1=0,p  =  λ2(cos⁡θ−1)  ≤  0.\xi^{2} - 2(1+p)\,\xi + 1 = 0, \qquad p \;=\; \lambda^{2}\bigl(\cos\theta - 1\bigr) \;\le\; 0 .

Both roots satisfy ∣ξ∣≤1|\xi| \le 1 for every θ∈[−π,π]\theta \in [-\pi,\pi] if and only if

λ≤1,that isc Δt≤Δx.\lambda \le 1, \quad\text{that is}\quad c\,\Delta t \le \Delta x .

Whenever −2<p<0-2 < p < 0 the two roots form a complex-conjugate pair of modulus exactly 11, so those modes neither grow nor decay, which is what the wave equation itself does; the endpoint p=−2p = -2, reached only when λ=1\lambda = 1 and θ=π\theta = \pi, gives the double root ξ=−1\xi = -1. When λ>1\lambda > 1 there are wavenumbers for which one root is real and less than −1-1.

Idea of the proofOriginal

A constant-coefficient difference scheme treats every grid point alike, so shifting the grid by one point commutes with one step of the scheme. The grid plane waves eikjΔxe^{ikj\Delta x} are the eigenvectors of that shift, hence eigenvectors of the scheme, and the scheme acts on each of them by a single number ξ\xi. Stability is then the question of whether any of those numbers exceeds 11 in modulus, and since the whole dependence is through θ=kΔx\theta = k\Delta x in a bounded interval, it is a question about a function of one real variable on [−π,π][-\pi,\pi]. For the heat scheme that function is a real cosine and the worst case is the shortest wave the grid supports; for the wave scheme each θ\theta gives a quadratic with constant term 11, so its roots multiply to 11 and the only two possibilities are a conjugate pair on the unit circle or a real pair straddling it.

ProofAdaptedAdapted from Strauss (2008), §8.2, Eqs. (9)-(10), pp. 206-207; Strauss (2008), §8.3, Eqs. (7)-(8), p. 213

(a) Step 1 (substitute). The solved form of (H) is ujn+1=s(uj+1n+uj−1n)+(1−2s)ujnu_j^{n+1} = s(u_{j+1}^n + u_{j-1}^n) + (1-2s)u_j^n, so the coefficients are a±1=sa_{\pm1} = s and a0=1−2sa_0 = 1-2s. By the boxed formula,

ξ(θ)=s eiθ+s e−iθ+1−2s=1−2s(1−cos⁡θ),\xi(\theta) = s\,e^{i\theta} + s\,e^{-i\theta} + 1 - 2s = 1 - 2s(1 - \cos\theta),

and the half-angle identity 1−cos⁡θ=2sin⁡2(θ/2)1 - \cos\theta = 2\sin^{2}(\theta/2) gives the second form. In particular ξ\xi is real because the stencil is symmetric.

Step 2 (one inequality is free). Since s>0s > 0 and sin⁡2(θ/2)≥0\sin^{2}(\theta/2) \ge 0, we have ξ(θ)≤1\xi(\theta) \le 1 for every θ\theta. So the condition ∣ξ∣≤1|\xi| \le 1 reduces to ξ(θ)≥−1\xi(\theta) \ge -1.

Step 3 (find the worst mode). ξ(θ)≥−1\xi(\theta) \ge -1 says 4ssin⁡2(θ/2)≤24s\sin^{2}(\theta/2) \le 2. As θ\theta runs over [−π,π][-\pi,\pi], sin⁡2(θ/2)\sin^{2}(\theta/2) attains its largest value 11 at θ=±π\theta = \pm\pi and no larger value is available, this being exactly where aliasing cuts the range off. The inequality therefore holds across the whole range of θ\theta exactly when 4s≤24s \le 2, which is the stated bound s≤1/2s \le 1/2.

Step 4 (failure is genuine). If s>1/2s > 1/2, take θ=π\theta = \pi. Then ξ=1−4s\xi = 1 - 4s and ∣ξ∣=4s−1>1|\xi| = 4s - 1 > 1 is a constant that does not shrink with Δt\Delta t, so no bound of the form 1+CΔt1 + C\Delta t can hold for small Δt\Delta t. Over a fixed time TT the number of steps is n=T/Δt=T/(s(Δx)2)n = T/\Delta t = T/(s(\Delta x)^2), so the sawtooth is amplified by (4s−1)T/(s(Δx)2)(4s-1)^{T/(s(\Delta x)^2)}, which tends to infinity as the grid is refined.

(b) Step 5 (substitute into the three-level scheme). Insert ujn=ξneikjΔxu_j^n = \xi^{n}e^{ikj\Delta x} into

ujn+1−2ujn+ujn−1(Δt)2=c2 uj+1n−2ujn+uj−1n(Δx)2\frac{u_j^{n+1} - 2u_j^n + u_j^{n-1}}{(\Delta t)^2} = c^2\,\frac{u_{j+1}^n - 2u_j^n + u_{j-1}^n}{(\Delta x)^2}

and divide by ξneikjΔx/(Δt)2\xi^{n}e^{ikj\Delta x}/(\Delta t)^{2}, which is non-zero. Using λ2=c2(Δt)2/(Δx)2\lambda^2 = c^2(\Delta t)^2/(\Delta x)^2 and eiθ+e−iθ=2cos⁡θe^{i\theta} + e^{-i\theta} = 2\cos\theta,

ξ−2+ξ−1  =  λ2(2cos⁡θ−2)  =  2p.\xi - 2 + \xi^{-1} \;=\; \lambda^{2}\bigl(2\cos\theta - 2\bigr) \;=\; 2p .

Multiplying by ξ\xi and rearranging gives ξ2−2(1+p)ξ+1=0\xi^2 - 2(1+p)\xi + 1 = 0. Note p≤0p \le 0 always, and p≥−2λ2p \ge -2\lambda^2 with equality at θ=π\theta = \pi.

Step 6 (the roots multiply to one). The product of the two roots is the constant term, 11. The discriminant of the quadratic is 4(1+p)2−4=4p(p+2)4(1+p)^2 - 4 = 4p(p+2).

Step 7 (case −2≤p≤0-2 \le p \le 0). Then p(p+2)≤0p(p+2) \le 0, so the discriminant is ≤0\le 0 and the roots are a complex-conjugate pair (or the double root ξ=−1\xi = -1 when p=−2p = -2, and ξ=1\xi = 1 when p=0p=0). A conjugate pair whose product is 11 consists of two numbers of modulus 11, since ξ ξ‾=∣ξ∣2=1\xi\,\overline{\xi} = |\xi|^2 = 1. So ∣ξ∣=1|\xi| = 1 for both roots.

Step 8 (case p<−2p < -2). Then p(p+2)>0p(p+2) > 0, so the roots are real and distinct. Their product is 11 and their sum is 2(1+p)<−22(1+p) < -2, so both are negative and they are reciprocals of each other; two distinct reciprocal numbers cannot both have modulus 11, so one has modulus strictly greater than 11. The scheme is unstable.

Step 9 (translate into λ\lambda). Over θ∈[−π,π]\theta \in [-\pi,\pi] the quantity pp is smallest at θ=π\theta = \pi, where it equals −2λ2-2\lambda^{2}. Step 7 therefore covers every θ\theta exactly when −2λ2≥−2-2\lambda^{2} \ge -2, which is the condition λ≤1\lambda \le 1. Should instead λ\lambda exceed 11, the sawtooth θ=π\theta = \pi has p=−2λ2<−2p = -2\lambda^{2} < -2, and Step 8 produces a root outside the unit circle. □\square

Definition(The Courant-Friedrichs-Lewy condition)AdaptedAdapted from Strauss (2008), §8.3, p. 214 and Figure 4

The domain of dependence of the exact solution of utt=c2uxxu_{tt} = c^2u_{xx} at a point (x,t)(x,t) is the interval [x−ct, x+ct][x - ct,\, x+ct] on the initial line: by d'Alembert's formula (The one-dimensional wave equation) the value there is determined by the data on that interval and by nothing outside it. The numerical domain of dependence of ujnu_j^{n} under an explicit scheme whose stencil reaches one point to each side is the set of initial grid points within nn steps, namely [xj−nΔx, xj+nΔx][x_j - n\Delta x,\, x_j + n\Delta x].

The CFL condition, named for Courant, Friedrichs and Lewy, is the requirement that the numerical domain of dependence contain the exact one. For scheme (W) at tn=nΔtt_n = n\Delta t it reads c n Δt≤n Δxc\,n\,\Delta t \le n\,\Delta x, that is

λ=c ΔtΔx≤1.\lambda = \frac{c\,\Delta t}{\Delta x} \le 1 .

Strauss puts the same thing as a comparison of speeds: Δx/Δt\Delta x/\Delta t is the speed at which the scheme propagates information, and it must be at least the physical speed cc.

Theorem(CFL is necessary for convergence)AdaptedAdapted from Strauss (2008), §8.3, p. 214

Let an explicit scheme for utt=c2uxxu_{tt} = c^2u_{xx} on the whole line compute ujn+1u_j^{n+1} from grid values at the two previous levels lying within one grid point of xjx_j, and refine the grid with λ=c Δt/Δx\lambda = c\,\Delta t/\Delta x held fixed. If λ>1\lambda > 1, there is a pair of initial data for which the computed values at a fixed point (x∗,t∗)(x_\ast, t_\ast), t∗>0t_\ast > 0, do not both converge to the corresponding exact solutions. Hence no such scheme can converge for all data unless λ≤1\lambda \le 1, whatever its truncation error.

ProofAdaptedAdapted from Strauss (2008), §8.3, p. 214

Step 1 (the numerical domain of dependence is too small). Suppose λ>1\lambda > 1. Fix t∗>0t_\ast > 0 and take the point x∗=0x_\ast = 0. Let nn be the number of steps to reach t∗t_\ast, so n Δt=t∗n\,\Delta t = t_\ast. Each of the nn steps widens the stencil by one grid point, and the second starting row widens it by one more, so the computed value at (0,t∗)(0, t_\ast) depends only on the initial data at the grid points of [−(n+1)Δx, (n+1)Δx][-(n+1)\Delta x,\, (n+1)\Delta x]. Now

n Δx=n c Δtλ=c t∗λ  =:  r  <  c t∗,n\,\Delta x = n\,\frac{c\,\Delta t}{\lambda} = \frac{c\,t_\ast}{\lambda} \;=:\; r \;<\; c\,t_\ast ,

so that interval is contained in [−(r+Δx), r+Δx][-(r+\Delta x),\, r+\Delta x], which shrinks to the fixed interval [−r,r][-r,r] as the grid is refined with λ\lambda held fixed. It is therefore eventually contained in any fixed neighbourhood of [−r,r][-r,r] inside the exact domain of dependence [−ct∗,ct∗][-ct_\ast, ct_\ast].

Step 2 (choose the data). Pick r′r' with r<r′<ct∗r < r' < ct_\ast. Take initial velocity ψ≡0\psi \equiv 0 in both cases, initial displacement φ1≡0\varphi_1 \equiv 0, and for φ2\varphi_2 a continuous bump supported in (r′,∞)(r', \infty) with φ2(ct∗)=2\varphi_2(ct_\ast) = 2. Since ψ≡0\psi \equiv 0, d'Alembert's formula gives u(0,t∗)=12(φ(ct∗)+φ(−ct∗))u(0,t_\ast) = \tfrac12\bigl(\varphi(ct_\ast) + \varphi(-ct_\ast)\bigr), so the exact values are u1(0,t∗)=0u_1(0,t_\ast) = 0 and u2(0,t∗)=12(2+0)=1u_2(0,t_\ast) = \tfrac12(2 + 0) = 1.

Step 3 (compare). Take any grid fine enough that r+Δx<r′r + \Delta x < r'. On it, φ1\varphi_1 and φ2\varphi_2 agree (both vanish) at every grid point of [−(r+Δx),r+Δx][-(r+\Delta x), r+\Delta x], and ψ\psi is the same for both; by Step 1 the computed value at (0,t∗)(0,t_\ast) uses nothing else, so the two computations produce the same number. Their exact counterparts differ by 11. Hence at most one of the two numerical sequences can converge to its own exact value as the grid is refined, and convergence for all data fails. □\square

Remark(Where the hypotheses are used)Original

Constant coefficients. The entire method rests on the grid plane waves being eigenvectors of the scheme, which needs the coefficients ama_m to be independent of jj. For a variable-coefficient problem the usual practice is to freeze the coefficients at each point, apply the analysis there, and impose the worst of the resulting limits; that is a heuristic, not a theorem.

No boundaries. The modes eikjΔxe^{ikj\Delta x} live on the whole line or on a periodic grid. Strauss gets the same answer on the interval [0,π][0,\pi] with Dirichlet data because the discrete sine functions sin⁡(jkΔx)\sin(jk\Delta x) happen also to be eigenvectors of the scheme there; for a general boundary condition they are not, and a scheme that is von Neumann stable in the interior can still be destroyed by its boundary treatment.

Scalar, one step. For a scalar one-step scheme, ∣ξ(θ)∣≤1|\xi(\theta)| \le 1 for all θ\theta is both necessary and sufficient for the scheme to be a contraction in the grid ℓ2\ell^2 norm, by the discrete Parseval relation of The discrete Fourier transform and the FFT. For a system, the amplification is a matrix G(θ)G(\theta), and the spectral radius condition ρ(G)≤1\rho(G) \le 1 is still necessary but no longer sufficient: powers of a non-normal matrix with spectral radius 11 can grow polynomially, or transiently by a large factor. The multi-level scheme (W) was handled above by passing to the scalar quadratic, which is legitimate only because the two roots were examined individually. The same caution applies at the endpoint λ=1\lambda = 1: there the sawtooth θ=π\theta = \pi has the double root ξ=−1\xi = -1, so the general solution of the recurrence for that mode is (A+Bn)(−1)n(A + Bn)(-1)^{n} and grows linearly in nn, even though both roots have modulus 11. Starting rows built exactly from a d'Alembert solution have B=0B = 0, which is why the scheme is exact at λ=1\lambda = 1 (Finite-difference approximations); rounding error is not so obliging, and practice therefore keeps λ\lambda strictly below 11.

Where the aliasing cut-off is used. Steps 3 and 9 both take the supremum of the relevant quantity over θ∈[−π,π]\theta \in [-\pi,\pi] and over nothing larger. A continuum stability analysis, which would let kk run to infinity, would give no condition at all for the heat equation and the wrong one for the wave equation. The limits s≤1/2s \le 1/2 and λ≤1\lambda \le 1 are properties of the grid, and they come from the shortest wave the grid can represent.

The slack C ΔtC\,\Delta t. For ut=uxxu_t = u_{xx} the exact solution decays, so ∣ξ∣≤1|\xi| \le 1 is the right test. For an equation such as ut=auxx+buu_t = a u_{xx} + bu with b>0b > 0 the exact solution grows like ebte^{bt}, and a scheme that reproduced it would have ∣ξ∣≈1+bΔt>1|\xi| \approx 1 + b\Delta t > 1; insisting on ∣ξ∣≤1|\xi| \le 1 would reject a perfectly good scheme. That is why Strauss states the condition with the O(Δt)O(\Delta t) allowance.

Implicit schemes escape the limit. Strauss's θ\theta scheme weights the second difference between the two time levels; writing the weight as μ∈[0,1]\mu \in [0,1] to keep θ\theta for the phase, its amplification factor is

ξ(θ)=1−2(1−μ)s(1−cos⁡θ)1+2μs(1−cos⁡θ),\xi(\theta) = \frac{1 - 2(1-\mu)s(1-\cos\theta)}{1 + 2\mu s(1-\cos\theta)} ,

and he shows that for 12≤μ≤1\tfrac12 \le \mu \le 1 no restriction on ss is needed: the scheme is unconditionally stable, the case μ=12\mu = \tfrac12 being Crank-Nicolson. The price is that each step now requires the solution of a tridiagonal linear system. Whether that price is worth paying is the stiffness question of Stability and stiff equations.

Theorem (stated without proof)(Lax equivalence theorem)Original

Let a linear initial-value problem be well posed on a Banach space BB: for data u0u_0 in a dense subspace there is a unique solution u(t)=E(t)u0u(t) = E(t)u_0 for 0≤t≤T0 \le t \le T, and the solution operators E(t)E(t) are uniformly bounded on [0,T][0,T]. Let a difference scheme be written as un+1=C(Δt) unu^{n+1} = C(\Delta t)\,u^{n} with C(Δt)C(\Delta t) a bounded operator on BB, and suppose the scheme is consistent with the problem. Call the scheme stable if the family

{ C(Δt)n  :  0≤n Δt≤T, 0<Δt≤τ }\bigl\{\,C(\Delta t)^{n} \;:\; 0 \le n\,\Delta t \le T,\ 0 < \Delta t \le \tau \,\bigr\}

is uniformly bounded in operator norm for some τ>0\tau > 0. Then the scheme is convergent — C(Δt)nu0→E(t)u0C(\Delta t)^{n}u_0 \to E(t)u_0 for every u0∈Bu_0 \in B as Δt→0\Delta t \to 0 with n Δt→tn\,\Delta t \to t — if and only if it is stable.

This is the theorem of Lax and Richtmyer. No book in this handbook's library proves it, and none is cited for it; it is stated here because it is what licenses the whole practice above, and it is the reason the von Neumann computation is worth doing at all. Strauss refers the reader to Richtmyer and Morton for the same circle of ideas when he states the von Neumann condition, and explicitly omits the convergence proof for the heat scheme.

NoteOriginal

How the three notions fit together, for a constant-coefficient scheme on a periodic grid. Consistency is checked by Taylor expansion (Finite-difference approximations) and says the scheme solves the right equation. Stability is checked by the amplification factor and says the scheme does not amplify anything without limit. Convergence — the thing one actually wants — follows from the two together, by Lax equivalence, and from neither alone. The mesh ratio s=1/6s = 1/6 found in the previous unit raises the order of consistency and says nothing about stability; the condition s≤1/2s \le 1/2 found here constrains stability and says nothing about accuracy.

Method(Von Neumann analysis of a scheme)Original
  1. Check the scheme is constant-coefficient and write it with all time levels on the left. Drop the boundaries: work on the whole line or a periodic grid.
  2. Substitute ujn=ξneiθju_j^{n} = \xi^{n}e^{i\theta j} and divide out the common factor ξneiθj\xi^{n}e^{i\theta j} (and a power of ξ\xi if the scheme is multi-level). What remains is a polynomial equation in ξ\xi whose coefficients depend on θ\theta and on the mesh ratios.
  3. Solve for ξ\xi. A one-step scheme gives ξ\xi directly; an rr-level scheme gives a polynomial of degree r−1r-1 in ξ\xi with that many roots, every one of which must be tested.
  4. Simplify with half angles. Replace 1−cos⁡θ1 - \cos\theta by 2sin⁡2(θ/2)2\sin^{2}(\theta/2) and sin⁡θ\sin\theta by 2sin⁡(θ/2)cos⁡(θ/2)2\sin(\theta/2)\cos(\theta/2); the modulus is usually a quadratic in σ=sin⁡2(θ/2)∈[0,1]\sigma = \sin^{2}(\theta/2) \in [0,1].
  5. Maximise ∣ξ∣|\xi| over σ∈[0,1]\sigma \in [0,1], not over all real kk. The maximum is usually at an endpoint: σ=1\sigma = 1 is the sawtooth θ=π\theta = \pi and σ=0\sigma = 0 is the constant mode.
  6. Impose ∣ξ∣≤1|\xi| \le 1 (or ≤1+CΔt\le 1 + C\Delta t if the exact solution grows) and solve the resulting inequality for the mesh ratio. If it holds for every mesh ratio, the scheme is unconditionally stable.
  7. Confirm numerically. Run the scheme on the offending mode for a few dozen steps and check the measured growth against ∣ξ∣n|\xi|^{n}.
Example(Three schemes for the advection equation)Original

Take ut+aux=0u_t + a u_x = 0 with a>0a > 0, whose exact solution translates the initial profile rigidly to the right at speed aa (First-order equations and characteristics). Put ν=a Δt/Δx\nu = a\,\Delta t/\Delta x, the Courant number, and θ=k Δx\theta = k\,\Delta x.

Scheme 1: forward in time, centred in space. ujn+1=ujn−ν2(uj+1n−uj−1n)u_j^{n+1} = u_j^{n} - \tfrac{\nu}{2}\bigl(u_{j+1}^n - u_{j-1}^n\bigr). The coefficients are a0=1a_0 = 1, a±1=∓ν/2a_{\pm 1} = \mp \nu/2, so

ξ(θ)=1−ν2(eiθ−e−iθ)=1−iνsin⁡θ,∣ξ∣2=1+ν2sin⁡2θ.\xi(\theta) = 1 - \frac{\nu}{2}\bigl(e^{i\theta} - e^{-i\theta}\bigr) = 1 - i\nu\sin\theta, \qquad |\xi|^{2} = 1 + \nu^{2}\sin^{2}\theta .

This exceeds 11 for every θ\theta that is not a multiple of π\pi, and the excess does not shrink with Δt\Delta t at fixed ν\nu. The scheme is unstable for every choice of steps, even though its truncation error is O(Δt)+O((Δx)2)O(\Delta t) + O((\Delta x)^2) and it looks like the natural thing to write down.

Scheme 2: Lax-Friedrichs. Replace the ujnu_j^n on the right by the average of its neighbours: ujn+1=12(uj+1n+uj−1n)−ν2(uj+1n−uj−1n)u_j^{n+1} = \tfrac12(u_{j+1}^n + u_{j-1}^n) - \tfrac{\nu}{2}(u_{j+1}^n - u_{j-1}^n). Now a±1=12∓ν2a_{\pm1} = \tfrac12 \mp \tfrac{\nu}{2}, a0=0a_0 = 0, so

ξ(θ)=cos⁡θ−iνsin⁡θ,∣ξ∣2=cos⁡2θ+ν2sin⁡2θ=1−(1−ν2)sin⁡2θ.\xi(\theta) = \cos\theta - i\nu\sin\theta, \qquad |\xi|^{2} = \cos^{2}\theta + \nu^{2}\sin^{2}\theta = 1 - (1-\nu^{2})\sin^{2}\theta .

So ∣ξ∣≤1|\xi| \le 1 for all θ\theta if and only if ν2≤1\nu^{2} \le 1: the CFL condition again.

Scheme 3: upwind. Difference into the wind, ujn+1=ujn−ν(ujn−uj−1n)u_j^{n+1} = u_j^n - \nu\bigl(u_j^n - u_{j-1}^n\bigr). Then ξ=1−ν+νe−iθ\xi = 1 - \nu + \nu e^{-i\theta} and

∣ξ∣2=(1−ν+νcos⁡θ)2+ν2sin⁡2θ=1−2ν(1−ν)(1−cos⁡θ),|\xi|^{2} = (1-\nu+\nu\cos\theta)^{2} + \nu^{2}\sin^{2}\theta = 1 - 2\nu(1-\nu)(1-\cos\theta),

after expanding and using cos⁡2+sin⁡2=1\cos^2 + \sin^2 = 1. Since 1−cos⁡θ≥01 - \cos\theta \ge 0, this is at most 11 precisely when ν(1−ν)≥0\nu(1-\nu) \ge 0, that is 0≤ν≤10 \le \nu \le 1. (For a<0a < 0 the mirror-image scheme, differencing forward in xx, is the stable one.)

The numbers. Take ν=12\nu = \tfrac12 and the mode with θ=π/2\theta = \pi/2, that is four grid points per wavelength. On a periodic grid of 6464 points with Δx=2π/64\Delta x = 2\pi/64 this is the mode e16ixje^{16 i x_j}.

  • Scheme 1: ∣ξ∣=1+14=1.11803399|\xi| = \sqrt{1 + \tfrac14} = 1.11803399, so after 100100 steps the mode should be multiplied by (5/4)50=7.00649232×104(5/4)^{50} = 7.00649232\times10^{4}. Marching the scheme 100100 steps in double precision and dividing by the initial mode gives 7.00649232×1047.00649232\times10^{4}, agreeing in all nine figures.
  • Scheme 2: ∣ξ∣2=0+14|\xi|^2 = 0 + \tfrac14, so ∣ξ∣=12|\xi| = \tfrac12 and after 2020 steps the factor should be 2−20=9.5367431640625×10−72^{-20} = 9.5367431640625\times10^{-7}. The computed factor is 9.5367431640625×10−79.5367431640625\times10^{-7}, exact to the last bit, since 2−202^{-20} is a machine number.
  • Scheme 3: ∣ξ∣2=1−2(12)(12)(1−0)=12|\xi|^{2} = 1 - 2(\tfrac12)(\tfrac12)(1 - 0) = \tfrac12, so after 2020 steps the factor should be 2−10=9.765625×10−42^{-10} = 9.765625\times10^{-4}. The computed factor is 9.76562500×10−49.76562500\times10^{-4}.

Schemes 2 and 3 are stable here but heavily damped at this wavenumber, which is the other half of the story: stability prevents disaster, it does not deliver accuracy. Over the 2020 steps the exact solution merely translates the wave, losing no amplitude at all, while the computed one has lost three orders of magnitude of it. This numerical dissipation is the price of the averaging in Scheme 2 and of the one-sided difference in Scheme 3, and it is the reason schemes of higher order are used in practice.

And the heat scheme. The same experiment on (H) with θ=π\theta = \pi: at s=0.55s = 0.55, just past the limit, ξ=1−4(0.55)=−1.2\xi = 1 - 4(0.55) = -1.2, and after 100100 steps the sawtooth is multiplied by 1.2100=8.28×1071.2^{100} = 8.28\times10^{7} — a complete loss of the solution, from a mesh ratio only ten per cent too large. At s=0.5s = 0.5 exactly, ξ=−1\xi = -1 and the sawtooth survives forever with alternating sign; at s=0.25s = 0.25, ξ=0\xi = 0 and it is annihilated in one step. Strauss reports exactly this behaviour in two runs with mesh ratios straddling 1/21/2: one on target, one oscillating wildly.

ApplicationOriginal

The CFL condition is the single hardest constraint on large-scale geophysical simulation, and it is a budget item rather than a mathematical curiosity.

A global atmospheric model that treats the full compressible equations explicitly must resolve sound waves, which travel at roughly 340 m s−1340\ \mathrm{m\,s^{-1}}. At a horizontal grid spacing of 10 km10\ \mathrm{km} the CFL limit is about Δt≤104/340≈29 s\Delta t \le 10^{4}/340 \approx 29\ \mathrm{s}, so a one-year integration needs of the order of 10610^{6} time steps. The meteorologically interesting signals travel at a tenth of that speed, so almost all of the work is spent keeping the acoustic modes stable. This is precisely the stiffness of Stability and stiff equations, and the standard answer is the one the θ\theta scheme illustrates: treat the fast terms implicitly, pay for a linear solve each step, and choose Δt\Delta t from accuracy rather than from stability. Semi-implicit and split-explicit dynamical cores exist for exactly this reason.

The parabolic limit bites even harder. A vertical diffusion scheme of the form (H) with a diffusivity κ\kappa requires Δt≤(Δz)2/(2κ)\Delta t \le (\Delta z)^2/(2\kappa), which is quadratic in the spacing: refining the vertical grid by a factor of ten costs a hundred times as many steps. Boundary-layer schemes in operational models are therefore implicit almost without exception.

The same arithmetic governs explicit finite-difference codes for seismic wave propagation, for electromagnetic simulation by the finite-difference time-domain method, and for the diffusion step of a reactor or heat-exchanger calculation. In each case the engineering question is not whether the scheme is stable but how much the stability limit costs, which is why unconditionally stable implicit schemes and the iterative solvers of Relaxation methods for elliptic problems are so central to practice.

Method

Relaxation methods for elliptic problems

Adapted

Sets up the five-point discrete Poisson problem, writes the Jacobi, Gauss-Seidel and successive over-relaxation sweeps for it, computes the spectral radius of each error propagator exactly on the unit square (cos⁡πh\cos \pi h, cos⁡2πh\cos^2 \pi h and (1−sin⁡πh)/(1+sin⁡πh)(1-\sin\pi h)/(1+\sin\pi h)), and turns those into iteration counts and operation counts that are checked against a run.

Prerequisites: Finite-difference approximations, Solving linear systems numerically

Definition(The discrete Poisson problem)AdaptedAdapted from Strauss (2008), §8.4, Eqs. (1)-(2), pp. 218-219

Let Ω=(0,1)2\Omega = (0,1)^{2}, let h=1/(m+1)h = 1/(m+1), and place the grid points (xj,yk)=(jh,kh)(x_j, y_k) = (jh, kh) for 0≤j,k≤m+10 \le j,k \le m+1. The N=m2N = m^{2} points with 1≤j,k≤m1 \le j,k \le m are interior; the rest lie on the boundary. We solve

− uxx−uyy=f  in Ω,u=0  on ∂Ω-\,u_{xx} - u_{yy} = f \ \text{ in } \Omega, \qquad u = 0 \ \text{ on } \partial\Omega

by replacing each second derivative with the centred second difference of Finite-difference approximations. Writing Uj,kU_{j,k} for the approximation to u(xj,yk)u(x_j,y_k) and taking equal steps in both directions, the five-point scheme is

4Uj,k−Uj+1,k−Uj−1,k−Uj,k+1−Uj,k−1h2  =  fj,k,1≤j,k≤m,(P)\frac{4U_{j,k} - U_{j+1,k} - U_{j-1,k} - U_{j,k+1} - U_{j,k-1}}{h^{2}} \;=\; f_{j,k}, \qquad 1 \le j,k \le m, \tag{P}

with Uj,k=0U_{j,k} = 0 whenever (j,k)(j,k) is a boundary index. Collecting one equation per interior node turns (P) into the matrix problem A U=FA\,U = F, in which AA holds the left-hand coefficients, FF holds the values fj,kf_{j,k}, and both have size NN.

For f≡0f \equiv 0, dividing (P) by 4/h24/h^2 puts it in the form Strauss uses,

Uj,k  =  14(Uj+1,k+Uj−1,k+Uj,k+1+Uj,k−1),U_{j,k} \;=\; \tfrac14\bigl(U_{j+1,k} + U_{j-1,k} + U_{j,k+1} + U_{j,k-1}\bigr),

the statement that each value is the average of its four neighbours. This is the exact discrete counterpart of the mean value property of harmonic functions (Harmonic functions), and it forces a discrete maximum principle: a non-constant solution cannot attain its largest or smallest value at an interior point, since such a point could not be the average of its neighbours. Strauss derives the uniqueness of the solution of (P) from that principle, and then nonsingularity of AA from uniqueness.

The decisive structural point is that there is no marching direction. For the heat and wave equations the new row was computed from the old; an elliptic problem couples all NN unknowns at once, and NN is large — a grid of 100100 intervals in each direction already gives N≈104N \approx 10^{4}. Direct elimination is possible (Solving linear systems numerically) but its cost grows faster than linearly in NN, which is what motivates the iterations below.

Definition(Splitting, and the three sweeps)AdaptedAdapted from Stakgold & Holst (2011), §10.6, Eqs. (10.6.28)-(10.6.30), p. 799; Strauss (2008), §8.4, Eqs. (3)-(5), pp. 220-221

Split A=D−L−UA = D - L - U, with DD the diagonal part, −L-L the strictly lower triangular part and −U-U the strictly upper triangular part, the ordering of the unknowns being fixed once and for all. For the five-point matrix, D=(4/h2)ID = (4/h^{2})I. An iteration of the form

U(n+1)  =  U(n)+B(F−A U(n))U^{(n+1)} \;=\; U^{(n)} + B\bigl(F - A\,U^{(n)}\bigr)

for an approximate inverse BB of AA has error propagation matrix E=I−BAE = I - BA: subtracting the identity U∗=U∗+B(F−AU∗)U^{\ast} = U^{\ast} + B(F - AU^{\ast}) satisfied by the exact discrete solution gives U(n+1)−U∗=E (U(n)−U∗)U^{(n+1)} - U^{\ast} = E\,(U^{(n)} - U^{\ast}), so the error after nn sweeps is EnE^{n} applied to the initial error. The three classical choices, in Stakgold and Holst's notation, are

BJ=D−1,BGS=(D−L)−1,Bω=ω (D−ωL)−1,B_{\mathrm{J}} = D^{-1}, \qquad B_{\mathrm{GS}} = (D-L)^{-1}, \qquad B_{\omega} = \omega\,(D - \omega L)^{-1} ,

giving Jacobi, Gauss-Seidel and successive over-relaxation (SOR) with relaxation factor ω\omega. On the grid, with gj,k=h2fj,kg_{j,k} = h^{2}f_{j,k}, these read

  • Jacobi. Uj,k(n+1)=14(Uj+1,k(n)+Uj−1,k(n)+Uj,k+1(n)+Uj,k−1(n)+gj,k)\displaystyle U^{(n+1)}_{j,k} = \tfrac14\bigl(U^{(n)}_{j+1,k} + U^{(n)}_{j-1,k} + U^{(n)}_{j,k+1} + U^{(n)}_{j,k-1} + g_{j,k}\bigr): every value on the right is taken from the previous sweep, so the order of the nodes does not matter and the whole old array must be kept.
  • Gauss-Seidel. The same formula, but sweeping the nodes in a fixed order (say row by row from the bottom, left to right within a row) and using each new value the moment it is available. With the lexicographic order this uses the updated Uj−1,kU_{j-1,k} and Uj,k−1U_{j,k-1} and the old Uj+1,kU_{j+1,k} and Uj,k+1U_{j,k+1}. No second array is needed.
  • SOR. Compute the Gauss-Seidel value U~j,k\widetilde U_{j,k} and then move past it:
Uj,k(n+1)  =  Uj,k(n)+ω(U~j,k−Uj,k(n)).U^{(n+1)}_{j,k} \;=\; U^{(n)}_{j,k} + \omega\bigl(\widetilde U_{j,k} - U^{(n)}_{j,k}\bigr) .

ω=1\omega = 1 is Gauss-Seidel; ω>1\omega > 1 is over-relaxation.

A convention to watch. Strauss writes the SOR step as Uj,k(n+1)=Uj,k(n)+ω(sum of the four neighbours−4Uj,k(n))U^{(n+1)}_{j,k} = U^{(n)}_{j,k} + \omega\bigl(\text{sum of the four neighbours} - 4U^{(n)}_{j,k}\bigr), in which Gauss-Seidel is the case ω=1/4\omega = 1/4. His ω\omega is therefore one quarter of the ω\omega used here and by Stakgold and Holst. Everything below uses the convention in which Gauss-Seidel is ω=1\omega = 1; a factor quoted from Strauss must be multiplied by four before it is substituted into any formula here.

Method(Convergence, and the rates for the model problem)AdaptedAdapted from Stakgold & Holst (2011), §10.6, Thm 10.6.4 and the spectral radii, pp. 799-800

Let EE be the error propagation matrix of one of the three iterations above, applied to the five-point matrix AA of (P) on the unit square with h=1/(m+1)h = 1/(m+1).

  1. Convergence. U(n)→U∗U^{(n)} \to U^{\ast} for every starting vector if and only if the spectral radius satisfies ρ(E)<1\rho(E) < 1, and then the error is reduced asymptotically by the factor ρ(E)\rho(E) per sweep. Stakgold and Holst record that for an M-matrix AA the splitting obtained by setting the off-diagonal entries to zero is regular and the resulting iteration converges, and that Jacobi and Gauss-Seidel both arise from regular splittings of such a matrix.

  2. Jacobi. The eigenvalues of EJ=I−D−1AE_{\mathrm{J}} = I - D^{-1}A are

μp,q=12(cos⁡pπh+cos⁡qπh),1≤p,q≤m,\mu_{p,q} = \tfrac12\bigl(\cos p\pi h + \cos q\pi h\bigr), \qquad 1 \le p,q \le m,

so ρ(EJ)=cos⁡πh\rho(E_{\mathrm{J}}) = \cos \pi h.

  1. Gauss-Seidel. For a consistently ordered matrix with Property A — which the five-point matrix with the lexicographic ordering is — the Gauss-Seidel spectral radius is the square of the Jacobi one, so ρ(EGS)=cos⁡2πh\rho(E_{\mathrm{GS}}) = \cos^{2}\pi h.

  2. SOR. ρ(Eω)≥∣1−ω∣\rho(E_{\omega}) \ge |1-\omega| for every matrix with non-zero diagonal, so convergence requires 0<ω<20 < \omega < 2. For this model problem the optimal factor and the rate it achieves are

ωopt=21+sin⁡πh,ρ(Eωopt)=ωopt−1=1−sin⁡πh1+sin⁡πh.\omega_{\mathrm{opt}} = \frac{2}{1 + \sin\pi h}, \qquad \rho\bigl(E_{\omega_{\mathrm{opt}}}\bigr) = \omega_{\mathrm{opt}} - 1 = \frac{1 - \sin \pi h}{1 + \sin\pi h} .
  1. Rates as h→0h \to 0. Expanding the logarithms,
−ln⁡ρ(EJ)∼12π2h2,−ln⁡ρ(EGS)∼π2h2,−ln⁡ρ(Eωopt)∼2πh.-\ln\rho(E_{\mathrm{J}}) \sim \tfrac12\pi^{2}h^{2}, \qquad -\ln\rho(E_{\mathrm{GS}}) \sim \pi^{2}h^{2}, \qquad -\ln\rho(E_{\omega_{\mathrm{opt}}}) \sim 2\pi h .

Gauss-Seidel is asymptotically twice as fast as Jacobi; optimal SOR is faster than Gauss-Seidel by the factor 2/(πh)2/(\pi h), which grows without bound as the grid is refined. All three rates tend to zero with hh: Stakgold and Holst emphasise that ρ(E)→1\rho(E) \to 1 in every case, so every classical method slows down as the problem is refined.

Idea of the proofOriginal

Two observations do all the work. First, the five-point matrix on a rectangle has explicitly known eigenvectors — the products of discrete sines, the same ones that separation of variables produces for the continuous problem — so the Jacobi error propagator, which is a polynomial in AA, is diagonalised at once and its spectral radius can simply be read off. The slowest mode is the smoothest one, p=q=1p = q = 1, whose eigenvalue is only O(h2)O(h^{2}) below 11: Jacobi averages neighbours, and averaging barely changes a function that is already nearly constant over a few grid spacings. Second, Gauss-Seidel and SOR are not polynomials in AA and cannot be diagonalised this way, but SOR's determinant can be computed from triangularity alone, and that single determinant already forces ω\omega into (0,2)(0,2) and sets a floor ∣1−ω∣|1-\omega| under the spectral radius. Over-relaxation works by pushing ω\omega up until the floor ∣1−ω∣|1-\omega| rises to meet the falling spectral radius, and the two meet at ωopt\omega_{\mathrm{opt}}.

ProofAdaptedAdapted from Stakgold & Holst (2011), §10.6, p. 800

Part 1 (convergence criterion). The error satisfies e(n)=Ene(0)e^{(n)} = E^{n}e^{(0)}. A standard fact about matrix powers is that En→0E^{n} \to 0 for every starting vector if and only if ρ(E)<1\rho(E) < 1, and that ∥En∥1/n→ρ(E)\|E^{n}\|^{1/n} \to \rho(E); see Eigenvalues and eigenvectors and Solving linear systems numerically. The M-matrix statement is Stakgold and Holst's Theorem 10.6.4, reported here as they give it.

Part 2 (Jacobi eigenvalues). For 1≤p,q≤m1 \le p,q \le m define the grid function

vj,k(p,q)  =  sin⁡(pπjh) sin⁡(qπkh).v^{(p,q)}_{j,k} \;=\; \sin(p\pi j h)\,\sin(q\pi k h) .

It vanishes at j=0j = 0 and at j=m+1j = m+1, because sin⁡(pπ(m+1)h)=sin⁡(pπ)=0\sin\bigl(p\pi(m+1)h\bigr) = \sin(p\pi) = 0, and likewise in kk; so it respects the homogeneous boundary condition built into (P). Using sin⁡((j±1)α)=sin⁡jαcos⁡α±cos⁡jαsin⁡α\sin\bigl((j\pm1)\alpha\bigr) = \sin j\alpha\cos\alpha \pm \cos j\alpha\sin\alpha, the two terms with cos⁡jα\cos j\alpha cancel on addition and

vj+1,k(p,q)+vj−1,k(p,q)=2cos⁡(pπh) vj,k(p,q),v^{(p,q)}_{j+1,k} + v^{(p,q)}_{j-1,k} = 2\cos(p\pi h)\, v^{(p,q)}_{j,k},

with the same identity in kk. Hence

A v(p,q)=λp,q v(p,q),λp,q=4−2cos⁡pπh−2cos⁡qπhh2.A\,v^{(p,q)} = \lambda_{p,q}\,v^{(p,q)}, \qquad \lambda_{p,q} = \frac{4 - 2\cos p\pi h - 2\cos q\pi h}{h^{2}} .

These m2=Nm^{2} = N grid functions are linearly independent (they are the columns of a tensor product of two discrete sine transforms), so they are a full eigenbasis. Since D=(4/h2)ID = (4/h^{2})I, the Jacobi propagator is EJ=I−(h2/4)AE_{\mathrm{J}} = I - (h^{2}/4)A, a polynomial in AA with the same eigenvectors, and its eigenvalues are

1−h24λp,q=1−4−2cos⁡pπh−2cos⁡qπh4=12(cos⁡pπh+cos⁡qπh),1 - \frac{h^{2}}{4}\lambda_{p,q} = 1 - \frac{4 - 2\cos p\pi h - 2\cos q\pi h}{4} = \tfrac12\bigl(\cos p\pi h + \cos q\pi h\bigr),

which is claim 2. The largest in modulus occurs at p=q=1p = q = 1, giving cos⁡πh\cos\pi h, and at p=q=mp = q = m, giving cos⁡(π−πh)=−cos⁡πh\cos(\pi - \pi h) = -\cos\pi h; both have modulus cos⁡πh\cos \pi h, and every other pair gives something smaller. So ρ(EJ)=cos⁡πh<1\rho(E_{\mathrm{J}}) = \cos\pi h < 1, and the iteration converges.

Part 4a (the floor under the SOR spectral radius). From Bω=ω(D−ωL)−1B_\omega = \omega(D-\omega L)^{-1} and A=D−L−UA = D - L - U,

Eω=I−ω(D−ωL)−1A=(D−ωL)−1[(D−ωL)−ω(D−L−U)]=(D−ωL)−1[(1−ω)D+ωU].E_{\omega} = I - \omega(D-\omega L)^{-1}A = (D-\omega L)^{-1}\bigl[(D - \omega L) - \omega(D - L - U)\bigr] = (D-\omega L)^{-1}\bigl[(1-\omega)D + \omega U\bigr].

The matrix D−ωLD - \omega L is lower triangular with diagonal DD, and (1−ω)D+ωU(1-\omega)D + \omega U is upper triangular with diagonal (1−ω)D(1-\omega)D. The determinant of a triangular matrix is the product of its diagonal entries, so

det⁡Eω=(1−ω)Ndet⁡Ddet⁡D=(1−ω)N.\det E_{\omega} = \frac{(1-\omega)^{N}\det D}{\det D} = (1-\omega)^{N} .

The determinant is also the product of the NN eigenvalues, each of modulus at most ρ(Eω)\rho(E_\omega), so ρ(Eω)N≥∣1−ω∣N\rho(E_{\omega})^{N} \ge |1-\omega|^{N}, that is ρ(Eω)≥∣1−ω∣\rho(E_{\omega}) \ge |1-\omega|. Convergence needs ρ<1\rho < 1, hence ∣1−ω∣<1|1-\omega| < 1, hence 0<ω<20 < \omega < 2.

Part 5 (the rates). For small hh, cos⁡πh=1−12π2h2+O(h4)\cos\pi h = 1 - \tfrac12\pi^{2}h^{2} + O(h^{4}), so −ln⁡cos⁡πh=12π2h2+O(h4)-\ln\cos\pi h = \tfrac12\pi^{2}h^{2} + O(h^{4}) and the Gauss-Seidel rate is twice that, since the logarithm of a square is twice the logarithm. For SOR write σ=sin⁡πh\sigma = \sin\pi h; then

−ln⁡1−σ1+σ=ln⁡1+σ1−σ=2(σ+σ33+⋯ )=2πh+O(h3).□-\ln\frac{1-\sigma}{1+\sigma} = \ln\frac{1+\sigma}{1-\sigma} = 2\Bigl(\sigma + \frac{\sigma^{3}}{3} + \cdots\Bigr) = 2\pi h + O(h^{3}) . \qquad\square
Remark(Where the hypotheses are used, and what is not proved here)Original

The eigenvector computation needs the rectangle and the uniform grid. Part 2 is exact only because the domain is a product of intervals, the grid is uniform, the stencil is the same at every interior node, and the boundary condition is homogeneous Dirichlet. On an L-shaped domain, or with a variable coefficient, the sines are no longer eigenvectors and the spectral radius has to be estimated rather than computed. The qualitative conclusion ρ=1−O(h2)\rho = 1 - O(h^2) survives, because it is driven by the smallest eigenvalue of AA, which is O(1)O(1) while the largest is O(h−2)O(h^{-2}): the condition number of the discrete Laplacian is O(h−2)O(h^{-2}) whatever the domain, and that is the real culprit.

Gauss-Seidel depends on the ordering, Jacobi does not. Permuting the unknowns changes LL and UU and so changes EGSE_{\mathrm{GS}}; it leaves EJ=I−D−1AE_{\mathrm{J}} = I - D^{-1}A similar to itself. Claim 3 is stated for a consistently ordered matrix with Property A, which is the hypothesis Stakgold and Holst attach to it; with a red-black ordering of the grid the identity still holds, but with an arbitrary permutation it need not. This is also why Strauss is careful to prescribe the sweep order when he writes the Gauss-Seidel formula.

Claim 4 is only half proved here. The floor ρ(Eω)≥∣1−ω∣\rho(E_\omega) \ge |1-\omega|, and hence the necessity of 0<ω<20 < \omega < 2, is proved above from the determinant alone and holds for any matrix with non-zero diagonal. The value of ωopt\omega_{\mathrm{opt}} is a separate classical result of Young's, which requires the consistent-ordering hypothesis and relates the SOR eigenvalues ξ\xi to the Jacobi eigenvalues μ\mu through (ξ+ω−1)2=ξ ω2μ2(\xi + \omega - 1)^{2} = \xi\,\omega^{2}\mu^{2}. No book in this handbook's library proves it; Stakgold and Holst state only that ρ(ESOR)≈1−O(h)\rho(E_{\mathrm{SOR}}) \approx 1 - O(h), and Strauss says explicitly that he leaves the choice of relaxation factor to specialist texts. The formula is quoted here because it is what practitioners use, and it is verified numerically in the example below rather than taken on trust.

Spectral radius is an asymptotic statement. ρ(E)\rho(E) governs the error reduction per sweep eventually. EJE_{\mathrm{J}} is symmetric for this problem, so for Jacobi the bound bites immediately; EGSE_{\mathrm{GS}} and EωE_{\omega} are not symmetric, and for SOR near ωopt\omega_{\mathrm{opt}} the eigenvalues are nearly defective, so there is a transient during which the error falls more slowly than ρn\rho^{n}. The example below shows exactly that: Jacobi and Gauss-Seidel take the predicted number of sweeps, SOR takes about a quarter more.

Jacobi is a disguised heat-equation solve. Strauss points out that one Jacobi sweep is one step of the explicit scheme for vt=vxx+vyyv_t = v_{xx} + v_{yy} with Δx=Δy=h\Delta x = \Delta y = h and Δt=h2/4\Delta t = h^{2}/4, so that relaxing to a steady state is integrating the heat equation to t=∞t = \infty. The two-dimensional von Neumann analysis of Stability, the CFL condition and von Neumann analysis gives the amplification factor 1−4s1sin⁡2(θ1/2)−4s2sin⁡2(θ2/2)1 - 4s_1\sin^{2}(\theta_1/2) - 4s_2\sin^{2}(\theta_2/2) with s1=s2=1/4s_1 = s_2 = 1/4, and on the Dirichlet grid the admissible phases are θi=pπh\theta_i = p\pi h with 1≤p≤m1 \le p \le m. At p=q=1p = q = 1 this is 1−2sin⁡2(πh/2)=cos⁡πh1 - 2\sin^{2}(\pi h/2) = \cos\pi h, which is exactly ρ(EJ)\rho(E_{\mathrm{J}}) from Part 2 — the two calculations are the same calculation. It also shows that the Jacobi sweep sits precisely at the two-dimensional stability limit s1+s2=1/2s_1 + s_2 = 1/2, so it is the largest explicit step available: Jacobi is slow not because the step is timid but because the heat equation itself takes a time of order 11 to reach equilibrium, needing O(h−2)O(h^{-2}) steps of size h2/4h^2/4.

Why the classical methods stall, and what replaces them. Stakgold and Holst show that a Gauss-Seidel sweep damps the high-frequency components of the error quickly while the smooth components barely move — which is just the statement that μp,q\mu_{p,q} is near 11 for small p,qp,q. Representing the smooth error on a coarser grid, where it is no longer smooth, and correcting there, is the multigrid idea, and it removes the hh-dependence of the rate altogether.

Method(Solving a discrete elliptic problem by relaxation)Original
  1. Discretise on a uniform grid with the five-point stencil, and fold the boundary values into the right-hand side, so that the unknowns are the interior values only.
  2. Scale the equation so that the diagonal is 11 after dividing: each node's update is the average of its four neighbours plus h2fj,k/4h^{2}f_{j,k}/4.
  3. Pick the sweep. Gauss-Seidel dominates Jacobi in both speed and storage and should be preferred unless the sweeps are to be run in parallel, where Jacobi (or a red-black Gauss-Seidel) is the natural choice because all nodes of one colour are independent.
  4. Choose ω\omega. For a rectangle use ωopt=2/(1+sin⁡πh)\omega_{\mathrm{opt}} = 2/(1+\sin\pi h). Otherwise estimate ρ(EJ)\rho(E_{\mathrm{J}}) by monitoring the ratio of successive Jacobi residual norms, then set ω=2/(1+1−ρ(EJ)2)\omega = 2/\bigl(1 + \sqrt{1 - \rho(E_{\mathrm{J}})^{2}}\bigr). Erring on the high side of ωopt\omega_{\mathrm{opt}} is far safer than erring low: above the optimum the spectral radius is exactly ω−1\omega - 1, so it rises with unit slope, while below it the rise is much steeper. On the grid of the example, ω=1.50\omega = 1.50 gives ρ=0.500\rho = 0.500 and ω=1.60\omega = 1.60 gives ρ=0.600\rho = 0.600, but dropping only to ω=1.44\omega = 1.44 already gives ρ=0.511\rho = 0.511 and ω=1.40\omega = 1.40 gives ρ=0.611\rho = 0.611.
  5. Stop on the residual, not on the step: iterate until ∥F−AU(n)∥∞\|F - AU^{(n)}\|_\infty falls below a tolerance set by the discretisation error, which for the five-point scheme is O(h2)O(h^{2}). Iterating far past that is wasted work, since the discrete solution is not the one wanted anyway.
  6. Predict the cost before running. Sweeps needed ≈∣ln⁡ε∣/(−ln⁡ρ(E))\approx |\ln\varepsilon| / \bigl(-\ln\rho(E)\bigr); work per sweep ≈5N\approx 5N floating-point operations for Jacobi or Gauss-Seidel and ≈8N\approx 8N for SOR, with NN the number of interior nodes.
  7. Check the answer against the grid refinement, not against the iteration count: halve hh and confirm the solution changes by a factor of four less than the previous change, which is the second-order convergence of the discretisation.
Example(A problem with an exactly known discrete solution)Original

Solve −uxx−uyy=f-u_{xx}-u_{yy} = f on (0,1)2(0,1)^{2} with u=0u = 0 on the boundary and

f(x,y)=2π2sin⁡πx sin⁡πy,f(x,y) = 2\pi^{2}\sin\pi x\,\sin\pi y ,

whose exact solution is u(x,y)=sin⁡πx sin⁡πyu(x,y) = \sin\pi x\,\sin\pi y, with u(12,12)=1u(\tfrac12,\tfrac12) = 1.

Step 1 (the discrete solution in closed form). The grid values of ff are 2π2vj,k(1,1)2\pi^{2}v^{(1,1)}_{j,k}, a multiple of the first eigenvector of Part 2 of the proof. So the discrete solution is the same multiple of that eigenvector divided by the eigenvalue:

U∗=2π2λ1,1 v(1,1),λ1,1=4(1−cos⁡πh)h2.U^{\ast} = \frac{2\pi^{2}}{\lambda_{1,1}}\,v^{(1,1)}, \qquad \lambda_{1,1} = \frac{4\bigl(1 - \cos\pi h\bigr)}{h^{2}} .

At the centre, where v(1,1)=1v^{(1,1)} = 1, this gives

mm hh λ1,1\lambda_{1,1} Ucentre∗U^{\ast}_{\text{centre}} error ratio
33 1/41/4 18.745166018.7451660 1.053029291.05302929 5.302929×10−25.302929\times10^{-2}
77 1/81/8 19.486839719.4868397 1.012950751.01295075 1.295075×10−21.295075\times10^{-2} 4.09474.0947
1515 1/161/16 19.675872919.6758729 1.003218961.00321896 3.218964×10−33.218964\times10^{-3} 4.02334.0233

The ratios tend to 44: the discretisation is second order, as Finite-difference approximations says it should be. Note that λ1,1→2π2=19.7392088\lambda_{1,1} \to 2\pi^{2} = 19.7392088, the eigenvalue of the continuous operator.

Step 2 (relax on the h=1/8h = 1/8 grid). There are N=49N = 49 unknowns. The predicted rates are

ρ(EJ)=cos⁡π8=0.92387953,ρ(EGS)=0.85355339,ωopt=21+sin⁡(π/8)=1.44646269,\rho(E_{\mathrm{J}}) = \cos\tfrac{\pi}{8} = 0.92387953, \qquad \rho(E_{\mathrm{GS}}) = 0.85355339, \qquad \omega_{\mathrm{opt}} = \frac{2}{1+\sin(\pi/8)} = 1.44646269 ,

the last giving ρ(Eωopt)=ωopt−1=0.44646269\rho(E_{\omega_{\mathrm{opt}}}) = \omega_{\mathrm{opt}} - 1 = 0.44646269. Forming the three propagators explicitly and computing their eigenvalues confirms all three to ten figures, and scanning ω\omega over [1,1.99][1, 1.99] in steps of 0.0010.001 puts the numerical minimum of ρ(Eω)\rho(E_{\omega}) at ω=1.447\omega = 1.447 with value 0.44700.4470, which is Young's formula to the resolution of the scan.

Step 3 (count the sweeps). Starting from U(0)=0U^{(0)} = 0 and iterating until the maximum-norm error ∥U(n)−U∗∥∞\|U^{(n)} - U^{\ast}\|_{\infty} has fallen by a factor 10−1010^{-10}:

method predicted ln⁡(10−10)/ln⁡ρ\ln(10^{-10})/\ln\rho sweeps actually taken
Jacobi 290.8290.8 291291
Gauss-Seidel 145.4145.4 146146
SOR at ωopt\omega_{\mathrm{opt}} 28.628.6 3535

Jacobi and Gauss-Seidel land within one sweep of the asymptotic prediction, and Gauss-Seidel takes almost exactly half as many as Jacobi, as claim 5 says. SOR takes about a quarter more than the asymptotic count, the transient predicted in the remark above; it is still better than Gauss-Seidel by a factor of 4.24.2, against the asymptotic 2/(πh)=5.092/(\pi h) = 5.09.

Step 4 (the cost, in operations). At 55 operations per node per sweep, Gauss-Seidel used about 5×49×146≈3.6×1045 \times 49 \times 146 \approx 3.6\times10^{4} operations and SOR about 8×49×35≈1.4×1048 \times 49 \times 35 \approx 1.4\times10^{4}. Extrapolating with claim 5: on a grid with h=1/1000h = 1/1000, so N≈106N \approx 10^{6}, Gauss-Seidel would need ∣ln⁡ε∣/(π2h2)≈2.3×106|\ln\varepsilon|/(\pi^{2}h^{2}) \approx 2.3\times10^{6} sweeps for the same tolerance and SOR about 3.7×1033.7\times10^{3}. In two dimensions h≍N−1/2h \asymp N^{-1/2}, so the sweep counts are O(N)O(N) and O(N1/2)O(N^{1/2}) and the total costs O(N2)O(N^{2}) and O(N3/2)O(N^{3/2}); the two-dimensional column of Stakgold and Holst's complexity table gives O(N2ln⁡N)O(N^{2}\ln N) and O(N3/2ln⁡N)O(N^{3/2}\ln N), the extra logarithm coming from taking the tolerance down to discretisation-error level, ε=O(h2)=O(N−1)\varepsilon = O(h^{2}) = O(N^{-1}), as the grid is refined. The same table puts multilevel methods at O(Nln⁡N)O(N\ln N) and nested multilevel and domain decomposition at O(N)O(N).

ApplicationOriginal

Every problem whose steady state is governed by a potential leads to the system (P): electrostatics with a prescribed charge density, steady heat conduction in a slab, Darcy flow in an aquifer, the stream function of a two-dimensional incompressible flow, and the gravitational potential of a mass distribution (Fundamental solution of Laplace's equation).

The place where these solvers are run hardest is the pressure projection of an incompressible flow solver. Enforcing ∇⋅u=0\nabla\cdot\mathbf{u} = 0 at each time step requires the solution of a Poisson equation for the pressure on the whole grid, and because this happens every time step, the relaxation cost, not the physics, dominates the run. The numbers in the example are the reason: at h=1/1000h = 1/1000, plain Gauss-Seidel would need millions of sweeps per time step, which is simply not available, while optimally relaxed SOR needs thousands and a multigrid solver tens. The progression Jacobi →\to Gauss-Seidel →\to SOR →\to multigrid is a progression in the exponent of NN, and in a production code only the last two are usable.

Relaxation also has a long pre-computer history: Southwell's hand-relaxation of structural and fluid problems in the 1930s and 1940s is literally the Gauss-Seidel sweep, performed with a pencil on a drawing of the grid, with the residual at each node written down and the largest one "relaxed" first. The over-relaxation trick, of overshooting the local correction, was discovered in that practice before it was analysed.

Finally, the smoothing property noted in the remark — that a sweep kills rough error and leaves smooth error — is used on its own, outside any solver, as an image-processing operation and as a pre-conditioner inside Krylov methods, where a few sweeps are applied not to solve the system but to make it easier for something else to solve.

Method

Spectral methods

Adapted

Represents the unknown by its values on a Fourier or Chebyshev grid rather than by a difference stencil, so that differentiation becomes multiplication by in\mathrm{i}n or a dense differentiation matrix; proves that the interpolation error is at most twice the tail of the coefficient series, so the error falls like N−kN^{-k} for a CkC^{k} function and geometrically for an analytic one; and identifies aliasing as the single mechanism behind both the error bound and the dealiasing rule for nonlinear terms.

Prerequisites: The discrete Fourier transform and the FFT, Chebyshev polynomials, Smoothness and decay of Fourier coefficients, Cauchy's theorem

Definition(Collocation: the two standard grids)AdaptedAdapted from Stakgold & Holst (2011), §2.3, Eqs. (2.3.30)–(2.3.32), pp. 140–142; Riley, Hobson & Bence (2006), §18.4, Eq. (18.55), p. 595; Riley, Hobson & Bence (2006), §27.4.3, Eq. (27.45), p. 1009; Arfken, Weber & Harris (2013), §18.4, Eqs. (18.104)–(18.106), p. 904

A collocation method (or pseudo-spectral method) stores the unknown as its values at NN chosen points, interprets those values as the values of a single global interpolant drawn from a fixed NN-dimensional space of smooth functions, and differentiates by differentiating the interpolant exactly. Two choices of space and grid cover almost all practice.

The Fourier grid (periodic problems). Take N=2M+1N = 2M+1 odd and the equally spaced nodes

xj  =  2πjN,j=0,1,…,N−1,x_j \;=\; \frac{2\pi j}{N},\qquad j = 0,1,\dots,N-1 ,

on the circle, and let TM\mathcal{T}_M be the NN-dimensional space of trigonometric polynomials ∑∣n∣≤Mcneinx\sum_{\lvert n\rvert\le M} c_n \mathrm{e}^{\mathrm{i}nx}. Stakgold and Holst prove that for any data (fj)(f_j) there is exactly one p∈TMp\in\mathcal{T}_M with p(xj)=fjp(x_j)=f_j for every jj, and that its coefficients are the discrete Fourier coefficients of the data. Writing INfI_N f for the interpolant of the samples of a function ff, this says

INf(x)  =  ∑∣n∣≤MF^(n) einx,F^(n)  =  1N∑j=0N−1f(xj) e−2πinj/N,I_N f(x) \;=\; \sum_{\lvert n\rvert\le M}\hat F(n)\,\mathrm{e}^{\mathrm{i}nx}, \qquad \hat F(n) \;=\; \frac{1}{N}\sum_{j=0}^{N-1} f(x_j)\,\mathrm{e}^{-2\pi\mathrm{i}nj/N},

with F^\hat F the transform of The discrete Fourier transform and the FFT. The Fourier differentiation operator is

DNf  =  (INf)′,soDNf^(n)=in F^(n)  (∣n∣≤M).\mathcal{D}_N f \;=\; \bigl(I_N f\bigr)' , \qquad\text{so}\qquad \widehat{\mathcal{D}_N f}(n) = \mathrm{i}n\,\hat F(n)\ \ (\lvert n\rvert \le M) .

In words: transform, multiply by in\mathrm{i}n, transform back. An odd NN is taken so that the retained frequencies −M,…,M-M,\dots,M are symmetric and no lone mode sits at n=N/2n=N/2; this is Stakgold and Holst's reason for writing the node count as 2N+12N+1. With NN even one must decide what to do with the Nyquist mode n=N/2n=N/2, and the usual choice is to set its derivative to zero, which keeps DN\mathcal{D}_N real and skew-symmetric.

The Chebyshev grid (non-periodic problems on an interval). On [−1,1][-1,1] replace trigonometric polynomials by algebraic ones, PN=span⁡{1,x,…,xN}\mathcal{P}_N = \operatorname{span}\{1,x,\dots,x^{N}\}, and take the Chebyshev–Gauss–Lobatto (CGL) nodes

xj  =  cos⁡πjN,j=0,1,…,N,x_j \;=\; \cos\frac{\pi j}{N},\qquad j=0,1,\dots,N ,

which include both endpoints x0=1x_0=1 and xN=−1x_N=-1. These are the images under x=cos⁡θx=\cos\theta of the equally spaced angles θj=πj/N\theta_j = \pi j/N. Because Tk(cos⁡θ)=cos⁡kθT_k(\cos\theta)=\cos k\theta (Chebyshev polynomials), a polynomial ∑k≤NakTk(x)\sum_{k\le N} a_k T_k(x) is a cosine polynomial in θ\theta evaluated at equally spaced angles: Chebyshev collocation on [−1,1][-1,1] is Fourier collocation on the circle, restricted to even data. The Chebyshev differentiation matrix DN∈R(N+1)×(N+1)D_N\in\mathbb{R}^{(N+1)\times(N+1)} is defined by differentiating the Lagrange interpolant,

(DN)jk  =  ℓk′(xj),ℓk(x)=∏m≠kx−xmxk−xm,(D_N)_{jk} \;=\; \ell_k'(x_j), \qquad \ell_k(x)=\prod_{m\neq k}\frac{x-x_m}{x_k-x_m} ,

so that (DNu)j(D_N u)_j is the derivative at xjx_j of the unique polynomial of degree ≤N\le N through the data. Unlike its Fourier counterpart, DND_N is a full matrix.

A warning about "Chebyshev points". Two different node sets carry that name. The CGL nodes above are the extrema of TNT_N together with the endpoints. The Chebyshev–Gauss nodes are the zeros of TnT_n, xi=cos⁡((i−12)π/n)x_i=\cos\bigl((i-\tfrac12)\pi/n\bigr), i=1,…,ni=1,\dots,n; Riley, Hobson and Bence give them, with the equal weights wi=π/nw_i=\pi/n, as the points of the Gauss–Chebyshev quadrature rule for the weight (1−x2)−1/2(1-x^{2})^{-1/2} (see Numerical quadrature). Both sets cluster near the endpoints with spacing O(N−2)O(N^{-2}), and both are used; only the Lobatto set contains the endpoints, which is what makes it the convenient one for boundary conditions.

Method(Aliasing and spectral accuracy)Original

Let ff be 2π2\pi-periodic and continuous with an absolutely convergent Fourier series, ∑n∣f^(n)∣<∞\sum_{n}\lvert\hat f(n)\rvert<\infty, and let N=2M+1N=2M+1.

1. Aliasing. The interpolation coefficients are the exact coefficients with every congruent frequency folded in:

F^(n)  =  ∑m ≡ n (mod N)f^(m),∣n∣≤M.\hat F(n) \;=\; \sum_{m \,\equiv\, n \ (\mathrm{mod}\ N)} \hat f(m), \qquad \lvert n\rvert\le M .

2. The interpolation error is at most twice the tail.

∥f−INf∥∞  ≤  2 ⁣ ⁣∑∣m∣>M ⁣ ⁣∣f^(m)∣.\bigl\lVert f - I_N f\bigr\rVert_{\infty} \;\le\; 2\!\!\sum_{\lvert m\rvert > M}\!\!\bigl\lvert \hat f(m)\bigr\rvert .

3. Smoothness buys algebraic order. If f∈Ckf\in C^{k} with f(k)f^{(k)} of bounded variation, so that ∣f^(m)∣≤C∣m∣−k−1\lvert\hat f(m)\rvert\le C\lvert m\rvert^{-k-1}, then

∥f−INf∥∞  ≤  4Ck M−k  =  O ⁣(N−k).\bigl\lVert f - I_N f\bigr\rVert_{\infty} \;\le\; \frac{4C}{k}\,M^{-k} \;=\; O\!\left(N^{-k}\right) .

The order of the method is not fixed in advance by a stencil: it is whatever the smoothness of the solution allows. This is what is meant by spectral accuracy.

4. Analyticity buys geometric convergence. If ff extends holomorphically to the strip ∣Im⁡z∣<b\lvert\operatorname{Im}z\rvert<b and satisfies ∣f∣≤A\lvert f\rvert\le A on ∣Im⁡z∣≤a\lvert \operatorname{Im}z\rvert\le a for some a<ba<b, then ∣f^(m)∣≤Ae−a∣m∣\lvert\hat f(m)\rvert\le A\mathrm{e}^{-a\lvert m\rvert} and

∥f−INf∥∞  ≤  4A e−aM1−e−a.\bigl\lVert f - I_N f\bigr\rVert_{\infty} \;\le\; \frac{4A\,\mathrm{e}^{-aM}}{1-\mathrm{e}^{-a}} .

5. The Chebyshev grid aliases in the same way. On the CGL nodes xj=cos⁡(πj/N)x_j=\cos(\pi j/N),

T2N−k(xj)=T2N+k(xj)=Tk(xj)for all j and all k≥0,T_{2N-k}(x_j) = T_{2N+k}(x_j) = T_k(x_j)\qquad\text{for all } j \text{ and all } k\ge 0 ,

so the Chebyshev interpolant of ff on those nodes has coefficients a~k=∑am\tilde a_k=\sum a_m summed over the mm that fold onto kk, and parts 2–4 hold verbatim for the Chebyshev coefficients aka_k of ff in place of f^(n)\hat f(n), with ∥⋅∥∞\lVert\cdot\rVert_\infty taken on [−1,1][-1,1].

Idea of the proofOriginal

A finite grid cannot tell two frequencies apart when they differ by a multiple of NN: the exponentials einx\mathrm{e}^{\mathrm{i}nx} and ei(n+N)x\mathrm{e}^{\mathrm{i}(n+N)x} agree at every node. So the interpolant carries each true coefficient plus the coefficients of all its impostors. That is part 1, and it is already proved in The discrete Fourier transform and the FFT.

Part 2 follows by splitting the error into two pieces that are each controlled by the same tail: the coefficients that were thrown away because their frequency was too high, and the pollution that those discarded coefficients left behind in the retained ones. No coefficient appears in both piles, so the two sums together are at most twice ∑∣m∣>M∣f^(m)∣\sum_{\lvert m\rvert>M}\lvert\hat f(m)\rvert.

Parts 3 and 4 are then nothing but the decay rate of Fourier coefficients, already established in Smoothness and decay of Fourier coefficients for the smooth case and obtained here by moving the contour of the coefficient integral into the complex strip for the analytic case. The whole content of spectral accuracy is that the error of the method is the tail of a series, not a fixed power of the mesh. Part 5 is part 1 read through the substitution x=cos⁡θx=\cos\theta, which carries the CGL grid to an equally spaced grid in θ\theta and the Chebyshev polynomials to cosines.

Proof(Parts 1–5)Original

1. This is the aliasing formula of The discrete Fourier transform and the FFT: substituting f(xj)=∑mf^(m)eimxjf(x_j)=\sum_m\hat f(m)\mathrm{e}^{\mathrm{i}mx_j} into the definition of F^(n)\hat F(n) and exchanging the two sums, which the hypothesis ∑m∣f^(m)∣<∞\sum_m\lvert\hat f(m)\rvert<\infty permits, leaves ∑mf^(m) δ\sum_m \hat f(m)\,\delta, where δ\delta is 11 when m≡nm\equiv n modulo NN and 00 otherwise, by the discrete orthogonality relation.

2. Absolute convergence of the coefficient series makes the Fourier expansion of ff uniformly convergent, so for every xx we may write

f(x)−INf(x)=∑∣m∣>Mf^(m) eimx⏟(T) truncation  −  ∑∣n∣≤M(F^(n)−f^(n))einx⏟(A) aliasing.f(x)-I_Nf(x) =\underbrace{\sum_{\lvert m\rvert>M}\hat f(m)\,\mathrm{e}^{\mathrm{i}mx}}_{\text{(T) truncation}} \;-\;\underbrace{\sum_{\lvert n\rvert\le M}\bigl(\hat F(n)-\hat f(n)\bigr)\mathrm{e}^{\mathrm{i}nx}}_{\text{(A) aliasing}} .

Bounding each exponential by 11 gives ∣(T)∣≤∑∣m∣>M∣f^(m)∣\lvert (\mathrm{T})\rvert\le\sum_{\lvert m\rvert>M}\lvert\hat f(m)\rvert, which is the first copy of the tail.

For (A), part 1 gives F^(n)−f^(n)=∑f^(m)\hat F(n)-\hat f(n)=\sum \hat f(m), the sum taken over those m≡nm\equiv n modulo NN with m≠nm\ne n. Every such mm satisfies ∣m∣≥N−M=M+1\lvert m\rvert\ge N-M=M+1, because the nearest congruent frequency to an nn with ∣n∣≤M\lvert n\rvert\le M is n±Nn\pm N and ∣n±N∣≥N−M\lvert n\pm N\rvert\ge N-M. Moreover, as nn runs over −M,…,M-M,\dots,M these index sets are disjoint: two frequencies congruent modulo NN to different nn in a window of NN consecutive integers are different. Hence

∑∣n∣≤M∣F^(n)−f^(n)∣  ≤  ∑∣m∣>M∣f^(m)∣,\sum_{\lvert n\rvert\le M}\bigl\lvert \hat F(n)-\hat f(n)\bigr\rvert \;\le\; \sum_{\lvert m\rvert>M}\bigl\lvert\hat f(m)\bigr\rvert ,

the second copy of the tail. Adding the two bounds gives part 2. □\square (for part 2)

3. With ∣f^(m)∣≤C∣m∣−k−1\lvert\hat f(m)\rvert\le C\lvert m\rvert^{-k-1} the tail is bounded by comparison with an integral:

∑∣m∣>M∣f^(m)∣  ≤  2C∑m=M+1∞m−k−1  ≤  2C∫M∞t−k−1 dt  =  2Ck M−k,\sum_{\lvert m\rvert>M}\lvert\hat f(m)\rvert \;\le\; 2C\sum_{m=M+1}^{\infty}m^{-k-1} \;\le\; 2C\int_{M}^{\infty}t^{-k-1}\,\mathrm{d}t \;=\;\frac{2C}{k}\,M^{-k} ,

the middle step because m−k−1≤∫m−1mt−k−1dtm^{-k-1}\le\int_{m-1}^{m}t^{-k-1}\mathrm{d}t for m≥M+1m\ge M+1. Doubling, by part 2, gives the stated constant. The hypothesis that f(k)f^{(k)} has bounded variation is what produces the decay rate ∣m∣−k−1\lvert m\rvert^{-k-1}; this is the content of Smoothness and decay of Fourier coefficients, where repeated integration by parts transfers each derivative onto a factor im\mathrm{i}m.

4. Fix m>0m>0 and consider the rectangle with corners 0, 2π, 2π−ia, −ia0,\ 2\pi,\ 2\pi-\mathrm{i}a,\ -\mathrm{i}a. The integrand f(z)e−imzf(z)\mathrm{e}^{-\mathrm{i}mz} is holomorphic inside and on it, since a<ba<b, so by Cauchy's theorem the contour integral around it vanishes. The two vertical sides cancel because f(z)e−imzf(z)\mathrm{e}^{-\mathrm{i}mz} is 2π2\pi-periodic in zz — here periodicity is used a second time, now in the complex plane. Therefore the integral over [0,2π][0,2\pi] equals the integral over the shifted segment [−ia,2π−ia][-\mathrm{i}a,2\pi-\mathrm{i}a], and

f^(m)=12π∫02πf(t−ia) e−im(t−ia) dt,∣e−im(t−ia)∣=e−ma,\hat f(m)=\frac{1}{2\pi}\int_{0}^{2\pi}f(t-\mathrm{i}a)\,\mathrm{e}^{-\mathrm{i}m(t-\mathrm{i}a)}\,\mathrm{d}t , \qquad \bigl\lvert \mathrm{e}^{-\mathrm{i}m(t-\mathrm{i}a)}\bigr\rvert=\mathrm{e}^{-ma} ,

so ∣f^(m)∣≤Ae−ma\lvert\hat f(m)\rvert\le A\mathrm{e}^{-ma}. For m<0m<0 shift the contour the other way, to +ia+\mathrm{i}a, and the same estimate appears with ∣m∣\lvert m\rvert. Summing the geometric series,

∑∣m∣>M∣f^(m)∣≤2A∑m=M+1∞e−ma=2A e−a(M+1)1−e−a≤2A e−aM1−e−a,\sum_{\lvert m\rvert>M}\lvert\hat f(m)\rvert\le 2A\sum_{m=M+1}^{\infty}\mathrm{e}^{-ma} =\frac{2A\,\mathrm{e}^{-a(M+1)}}{1-\mathrm{e}^{-a}}\le \frac{2A\,\mathrm{e}^{-aM}}{1-\mathrm{e}^{-a}} ,

and part 2 doubles it.

5. At the node xj=cos⁡(πj/N)x_j=\cos(\pi j/N) we have Tk(xj)=cos⁡(kπj/N)T_k(x_j)=\cos(k\pi j/N) by the defining identity Tk(cos⁡θ)=cos⁡kθT_k(\cos\theta)=\cos k\theta. Hence

T2N±k(xj)=cos⁡ ⁣((2N±k)πjN)=cos⁡ ⁣(2πj±kπjN)=cos⁡kπjN=Tk(xj),T_{2N\pm k}(x_j)=\cos\!\Bigl(\frac{(2N\pm k)\pi j}{N}\Bigr)=\cos\!\Bigl(2\pi j\pm\frac{k\pi j}{N}\Bigr)=\cos\frac{k\pi j}{N}=T_k(x_j),

using cos⁡(2πj+φ)=cos⁡φ\cos(2\pi j+\varphi)=\cos\varphi for integer jj and the evenness of the cosine for the minus sign. So degrees kk and 2N±k2N\pm k are indistinguishable on the grid, exactly as frequencies nn and n±Nn\pm N are on the Fourier grid. For the error bound, set g(θ)=f(cos⁡θ)g(\theta)=f(\cos\theta); gg is 2π2\pi-periodic and even, its Fourier cosine coefficients are the Chebyshev coefficients aka_k of ff, the CGL nodes are the points θj=πj/N\theta_j=\pi j/N, and sup⁡[−1,1]∣f−INf∣=sup⁡θ∣g−Ig∣\sup_{[-1,1]}\lvert f-I_Nf\rvert=\sup_{\theta}\lvert g - I g\rvert because θ↦cos⁡θ\theta\mapsto\cos\theta maps [0,π][0,\pi] onto [−1,1][-1,1]. Parts 2–4 applied to gg therefore give the claim. □\square

Remark(Where the hypotheses are used, and what fails without them)Original

Periodicity is not a technicality. Part 2 needs the coefficients of a periodic ff to be summable; part 4 uses periodicity again, to cancel the vertical sides of the contour. Apply a Fourier method to a function that is smooth on [0,2π][0,2\pi] but has f(0)≠f(2π)f(0)\ne f(2\pi) and the periodic extension has a jump, so ∣f^(m)∣\lvert \hat f(m)\rvert decays only like 1/∣m∣1/\lvert m\rvert, the tail is O(1)O(1), and the interpolant oscillates near the ends with an overshoot that does not shrink: this is exactly The Gibbs phenomenon, and no amount of resolution removes it. The Chebyshev grid exists precisely to deal with this case: g(θ)=f(cos⁡θ)g(\theta)=f(\cos\theta) is automatically periodic and even, whatever ff does at the endpoints.

Smoothness sets the order, not the grid. In part 3 the order kk comes from the function and not from the method. A solution with a shock or a corner gives first-order accuracy from a spectral method just as from a difference scheme, and worse: the error is spread over the whole domain rather than localised at the singularity, because the basis functions are global. Compare Finite-difference approximations, whose order is fixed by the stencil and is therefore insensitive, for better and for worse, to how smooth the solution is.

Clustering of the nodes is essential for Chebyshev. Taking N+1N+1 equally spaced nodes on [−1,1][-1,1] and interpolating by a polynomial of degree NN is not a spectral method at all: the nodal polynomial ω(x)=∏j(x−xj)\omega(x)=\prod_j (x-x_j), which carries the interpolation error (Polynomial and spline interpolation), is then exponentially larger near the ends than in the middle, and the interpolant of a perfectly analytic function can diverge as NN grows. The CGL nodes are, up to the endpoints, the extrema of TNT_N, and Kreyszig's Theorem 6.4-3 says that 21−NTN2^{1-N}T_N is the monic polynomial of degree NN with the smallest maximum modulus on [−1,1][-1,1], namely 21−N2^{1-N}. No node set can make the nodal polynomial smaller than that; the Chebyshev nodes very nearly achieve it.

The summability hypothesis. That ∑m∣f^(m)∣\sum_m\lvert\hat f(m)\rvert is finite is what lets us exchange the sums in part 1 and bound the exponentials termwise in part 2. It holds under the hypotheses of parts 3 (for k≥1k\ge1) and 4. Without it the interpolant still exists — interpolation is a finite linear-algebra problem — but the bound in part 2 carries no information.

Sharpness. Part 2 is sharp to within a small factor, not merely an order of magnitude: the example below finds the predicted bound exceeding the measured error by 7%7\% at N=9N=9 and by 4%4\% at N=17N=17.

Method(Running a spectral solver)Original

Fourier collocation (periodic domain).

  1. Choose the grid. NN points xj=2πj/Nx_j=2\pi j/N on [0,2π)[0,2\pi), rescaled to the physical period LL by x↦2πx/Lx\mapsto 2\pi x/L, which multiplies every wavenumber by 2π/L2\pi/L. Use NN a power of two if the FFT library wants one, and remember the Nyquist convention of the definition; use NN odd if you prefer the symmetric mode set.
  2. Transform. Compute F^(n)\hat F(n) for ∣n∣≤M\lvert n\rvert\le M with the FFT, at a cost of O(Nlog⁡N)O(N\log N) (The discrete Fourier transform and the FFT).
  3. Apply the operator in frequency space. Each ∂x\partial_x is a multiplication by in\mathrm{i}n, each ∂x2\partial_x^2 by −n2-n^{2}. A constant-coefficient linear problem L(∂x)u=fL(\partial_x)u=f is therefore solved by one division per mode: U^(n)=F^(n)/L(in)\hat U(n)=\hat F(n)/L(\mathrm{i}n), with the solvability condition L(0)≠0L(0)\neq0 or else an orthogonality condition on F^(0)\hat F(0).
  4. Evaluate nonlinear terms in physical space. To form u∂xuu\partial_x u: multiply by in\mathrm{i}n, transform back, multiply pointwise by the grid values of uu, transform forward again. Two forward and two inverse transforms per step, so O(Nlog⁡N)O(N\log N) — against O(N2)O(N^{2}) for the same operation done as a convolution in frequency space.
  5. Dealias. A quadratic nonlinearity of modes with ∣n∣≤K\lvert n\rvert\le K produces modes up to 2K2K, and the grid folds a mode pp with ∣p∣>M\lvert p\rvert>M back onto p∓Np\mp N. The folded modes first land inside the retained band when N−2K≤KN-2K\le K. Keeping 3K<N3K<N, that is zeroing all modes with ∣n∣>N/3\lvert n\rvert>N/3 before and after each product, removes the contamination; this is the two-thirds rule.
  6. Step in time with any integrator from Integrators for ODEs, bearing in mind that the diagonal entries −n2-n^{2} of the second-derivative operator reach −M2≈−N2/4-M^{2}\approx -N^{2}/4, so an explicit scheme for a diffusion problem is restricted to Δt=O(N−2)\Delta t = O(N^{-2}) and the problem is stiff in the sense of Stability and stiff equations. Treating the linear part implicitly costs nothing, because it is diagonal.

Chebyshev collocation (non-periodic interval).

  1. Map the interval. Send [α,β][\alpha,\beta] to [−1,1][-1,1] by x↦(2x−α−β)/(β−α)x\mapsto (2x-\alpha-\beta)/(\beta-\alpha); every derivative acquires a factor 2/(β−α)2/(\beta-\alpha).
  2. Build DND_N once, from (DN)jk=ℓk′(xj)(D_N)_{jk}=\ell_k'(x_j) at the CGL nodes, and form DN2D_N^{2} for a second-order problem. Cost O(N2)O(N^{2}) to store, O(N3)O(N^{3}) to form the square or factorise it.
  3. Impose boundary conditions by deletion. For u(±1)=0u(\pm1)=0, strike out the first and last rows and columns of DN2D_N^{2}; the remaining (N−1)×(N−1)(N-1)\times(N-1) block is invertible and acts on the interior values. For a Neumann condition, keep the row and replace it by the corresponding row of DND_N.
  4. Solve the dense system by LU, at a cost of 23N3+O(N2)\tfrac23 N^{3}+O(N^{2}) operations once and O(N2)O(N^{2}) per right-hand side thereafter (Solving linear systems numerically).
  5. If NN is large, transform instead. The map between nodal values and Chebyshev coefficients is a discrete cosine transform, computable in O(Nlog⁡N)O(N\log N), and the coefficient recurrence for differentiation is O(N)O(N); this replaces the dense matrix when NN runs into the hundreds.
  6. Watch the conditioning. The CGL nodes are spaced O(N−2)O(N^{-2}) near the endpoints, so ∥DN2∥\lVert D_N^{2}\rVert grows like N4N^{4} and the condition number of the interior block grows at the same rate (Matrix norms and condition numbers). Spectral accuracy is therefore eventually limited by rounding: in the example below the error stops improving at about 5×10−155\times10^{-15}.
Example(A periodic Helmholtz problem, and a Chebyshev two-point problem)Original

(a) How large is the interpolation error, really? Take f(x)=esin⁡xf(x)=\mathrm{e}^{\sin x}, which is entire, hence analytic in every strip. Its Fourier coefficients are Bessel functions. Put t=eixt=\mathrm{e}^{\mathrm{i}x} in the generating function e(z/2)(t−1/t)=∑nJn(z)tn\mathrm{e}^{(z/2)(t-1/t)}=\sum_n J_n(z)t^{n} of Bessel functions of the first kind: the exponent becomes izsin⁡x\mathrm{i}z\sin x, so the choice z=−iz=-\mathrm{i} gives esin⁡x=∑nJn(−i) einx\mathrm{e}^{\sin x}=\sum_n J_n(-\mathrm{i})\,\mathrm{e}^{\mathrm{i}nx}. Since Jn(−z)=(−1)nJn(z)J_n(-z)=(-1)^nJ_n(z) and In(x)=i−nJn(ix)I_n(x)=\mathrm{i}^{-n}J_n(\mathrm{i}x) (Modified Bessel functions), this is f^(n)=(−i)nIn(1)\hat f(n)=(-\mathrm{i})^{n}I_n(1), so ∣f^(n)∣=In(1)\lvert\hat f(n)\rvert=I_n(1). Numerically

I0(1)=1.266066,I1(1)=0.565159,I2(1)=0.135748,I3(1)=2.216842×10−2,I_0(1)=1.266066,\quad I_1(1)=0.565159,\quad I_2(1)=0.135748,\quad I_3(1)=2.216842\times10^{-2},I4(1)=2.737120×10−3,I5(1)=2.714632×10−4,I6(1)=2.248866×10−5.I_4(1)=2.737120\times10^{-3},\quad I_5(1)=2.714632\times10^{-4},\quad I_6(1)=2.248866\times10^{-5} .

For N=9N=9 we have M=4M=4, so part 2 predicts

∥f−I9f∥∞  ≤  4∑n≥5In(1)=4(2.714632×10−4+2.248866×10−5+1.599218×10−6+⋯ )=1.18263×10−3,\lVert f-I_9f\rVert_\infty\;\le\;4\sum_{n\ge5}I_n(1) = 4\bigl(2.714632\times10^{-4}+2.248866\times10^{-5}+1.599218\times10^{-6}+\cdots\bigr) = 1.18263\times10^{-3},

the factor 44 being the 22 of part 2 times the 22 from ±n\pm n. Evaluating the interpolant on a fine grid of 40014001 points gives a measured maximum error of 1.109873×10−31.109873\times10^{-3}: the bound is high by 7%7\%. At N=17N=17 the same computation predicts 2.32268×10−82.32268\times10^{-8} and measures 2.223491×10−82.223491\times10^{-8}, high by 4%4\%. At N=33N=33 the bound is 8.9×10−208.9\times10^{-20} and the measurement is 1.8×10−151.8\times10^{-15}, which is where double-precision rounding takes over: the error of the method has long since fallen below the error of the arithmetic.

(b) Solving −u′′+u=f-u''+u=f on the circle. Let u(x)=esin⁡xu(x)=\mathrm{e}^{\sin x} again. Then u′=cos⁡x esin⁡xu'=\cos x\,\mathrm{e}^{\sin x} and u′′=(cos⁡2x−sin⁡x)esin⁡xu''=(\cos^{2}x-\sin x)\mathrm{e}^{\sin x}, so the right-hand side is

f(x)=−u′′+u=(1−cos⁡2x+sin⁡x)esin⁡x=(sin⁡2x+sin⁡x)esin⁡x.f(x)=-u''+u=\bigl(1-\cos^{2}x+\sin x\bigr)\mathrm{e}^{\sin x}=\bigl(\sin^{2}x+\sin x\bigr)\mathrm{e}^{\sin x} .

Step 3 of the method is one line: U^(n)=F^(n)/(n2+1)\hat U(n)=\hat F(n)/(n^{2}+1). Carrying it out and comparing with uu at the nodes:

NN spectral, max⁡j∣Uj−u(xj)∣\max_j\lvert U_j-u(x_j)\rvert three-point differences, same NN
99 3.984146×10−43.984146\times10^{-4} 7.788135×10−27.788135\times10^{-2}
1717 3.176116×10−93.176116\times10^{-9} 2.160161×10−22.160161\times10^{-2}
3333 4.996004×10−164.996004\times10^{-16} 5.716368×10−35.716368\times10^{-3}
6565 1.054712×10−151.054712\times10^{-15} 1.472297×10−31.472297\times10^{-3}

The second column falls by a factor of about 44 each time NN doubles — second order, as Finite-difference approximations predicts for the stencil (Uj+1−2Uj+Uj−1)/h2(U_{j+1}-2U_j+U_{j-1})/h^{2}. The first column falls by five orders of magnitude from N=9N=9 to N=17N=17 and by seven more from N=17N=17 to N=33N=33, where it meets machine precision and stops. To reach 5×10−165\times10^{-16} with the difference scheme at second order would need N≈335.716×10−3/(5×10−16)≈1.1×108N\approx 33\sqrt{5.716\times10^{-3}/(5\times10^{-16})}\approx 1.1\times10^{8} points.

(c) Chebyshev collocation for u′′=fu''=f on [−1,1][-1,1], u(±1)=0u(\pm1)=0. Take u(x)=(1−x2)exu(x)=(1-x^{2})\mathrm{e}^{x}, which vanishes at both ends, and compute

u′=(1−2x−x2)ex,u′′=f(x)=−(x2+4x+1) ex.u'=(1-2x-x^{2})\mathrm{e}^{x},\qquad u''=f(x)=-(x^{2}+4x+1)\,\mathrm{e}^{x} .

With N=4N=4 the CGL nodes are xj=cos⁡(πj/4)x_j=\cos(\pi j/4), that is

x0=1,x1=22,x2=0,x3=−22,x4=−1.x_0=1,\quad x_1=\tfrac{\sqrt2}{2},\quad x_2=0,\quad x_3=-\tfrac{\sqrt2}{2},\quad x_4=-1 .

Differentiating the five Lagrange basis polynomials and evaluating at the nodes gives

D4=(112−4−222−4+22121+22−22−222−1+22−1220−2121−22−22222−1−22−124−22−24+22−112).D_4=\begin{pmatrix} \tfrac{11}{2} & -4-2\sqrt2 & 2 & -4+2\sqrt2 & \tfrac12\\[2pt] 1+\tfrac{\sqrt2}{2} & -\tfrac{\sqrt2}{2} & -\sqrt2 & \tfrac{\sqrt2}{2} & -1+\tfrac{\sqrt2}{2}\\[2pt] -\tfrac12 & \sqrt2 & 0 & -\sqrt2 & \tfrac12\\[2pt] 1-\tfrac{\sqrt2}{2} & -\tfrac{\sqrt2}{2} & \sqrt2 & \tfrac{\sqrt2}{2} & -1-\tfrac{\sqrt2}{2}\\[2pt] -\tfrac12 & 4-2\sqrt2 & -2 & 4+2\sqrt2 & -\tfrac{11}{2} \end{pmatrix} .

(Two checks: every row sums to zero, because D4D_4 differentiates the constant function to zero; and the centre row, (−12,2,0,−2,12)\bigl(-\tfrac12,\sqrt2,0,-\sqrt2,\tfrac12\bigr), is antisymmetric, as it must be because the node set is symmetric about the origin.) Squaring and deleting the first and last rows and columns leaves the interior operator — remarkably, an integer matrix:

(D42)int=(−146−24−64−26−14),F=(f(2/2)f(0)f(−2/2))=(−8.778548−1−0.655006).\bigl(D_4^{2}\bigr)_{\text{int}}=\begin{pmatrix}-14 & 6 & -2\\ 4 & -6 & 4\\ -2 & 6 & -14\end{pmatrix}, \qquad F=\begin{pmatrix}f(\sqrt2/2)\\ f(0)\\ f(-\sqrt2/2)\end{pmatrix} =\begin{pmatrix}-8.778548\\ -1\\ \phantom{-}0.655006\end{pmatrix} .

Solving the 3×33\times3 system gives, against the exact values,

node UjU_j (collocation) u(xj)u(x_j) exact error
2/2\sqrt2/2 1.0257861.025786 1.0140571.014057 +1.17×10−2+1.17\times10^{-2}
00 1.0102951.010295 11 +1.03×10−2+1.03\times10^{-2}
−2/2-\sqrt2/2 0.2396570.239657 0.2465340.246534 −6.88×10−3-6.88\times10^{-3}

Five points, three unknowns, one percent. Repeating with larger NN:

NN 44 88 1212 1616 2020
max error 1.17×10−21.17\times10^{-2} 4.85×10−74.85\times10^{-7} 2.41×10−122.41\times10^{-12} 5.22×10−155.22\times10^{-15} 1.33×10−151.33\times10^{-15}

Roughly five digits gained for every four points added, until the N4N^{4} growth of cond⁡(DN2)\operatorname{cond}(D_N^{2}) stops the descent at about 5×10−155\times10^{-15} — the limit anticipated in step 6 of the method.

(d) Aliasing on the Chebyshev grid, by hand. With N=4N=4, part 5 says T2N−1=T7T_{2N-1}=T_7 should agree with T1(x)=xT_1(x)=x at all five nodes. At x=2/2x=\sqrt2/2, using T7(x)=64x7−112x5+56x3−7xT_7(x)=64x^{7}-112x^{5}+56x^{3}-7x,

64(22)7−112(22)5+56(22)3−7⋅22=22(64⋅18−112⋅14+56⋅12−7)=22(8−28+28−7)=22,64\Bigl(\tfrac{\sqrt2}{2}\Bigr)^{7}-112\Bigl(\tfrac{\sqrt2}{2}\Bigr)^{5}+56\Bigl(\tfrac{\sqrt2}{2}\Bigr)^{3}-7\cdot\tfrac{\sqrt2}{2} = \tfrac{\sqrt2}{2}\bigl(64\cdot\tfrac18-112\cdot\tfrac14+56\cdot\tfrac12-7\bigr) =\tfrac{\sqrt2}{2}(8-28+28-7)=\tfrac{\sqrt2}{2} ,

which is xx itself. A degree-77 oscillation is invisible on a five-point Chebyshev grid, exactly as a frequency-77 oscillation is invisible on a five-point Fourier grid.

Application(Where spectral methods are used)Original

Turbulence and direct numerical simulation. The reference simulations of homogeneous isotropic turbulence are pseudo-spectral: the Navier–Stokes equations in a periodic box, with the viscous term diagonal in Fourier space, the nonlinear term evaluated on the grid, and the two-thirds rule applied at every step. The appeal is that the energy spectrum — the quantity the physics is about — is a primary variable of the method rather than something reconstructed afterwards, and that the dissipation range is resolved without the numerical viscosity that a low-order scheme adds.

Weather and climate models. Global atmospheric models have long used spherical harmonics as the horizontal basis: the Laplacian is diagonal, which makes semi-implicit time stepping cheap, and there is no pole problem of the kind a latitude–longitude difference grid suffers. The transform between grid-point and spectral representation is the dominant cost, and it is a Fourier transform in longitude combined with a Legendre transform in latitude (Spherical harmonics).

Quantum dynamics. The split-step Fourier method evolves the Schrödinger equation (The Schrodinger equation) by alternating an exact kinetic step, diagonal in momentum space because p^=−iℏ∂x\hat{p}=-\mathrm{i}\hbar\partial_x is multiplication by ℏk\hbar k, with an exact potential step, diagonal in position space. Both steps are unitary, so the norm is conserved to rounding error, and each costs one pair of transforms. The same structure underlies plane-wave electronic-structure codes, where the basis is the set of Fourier modes commensurate with a crystal lattice and the cutoff is quoted as an energy ℏ2kmax⁡2/2m\hbar^{2}k_{\max}^{2}/2m.

Why not always? Complex geometry. A Fourier basis needs a periodic box and a Chebyshev basis needs a tensor-product interval, so a domain with a curved or re-entrant boundary needs either a mapping, a decomposition into spectral elements, or the finite-element method of The finite element method, which gives up spectral accuracy and gains complete geometric freedom. Shocks are the other obstacle: for the conservation laws of Conservation laws and shocks the solution leaves the smoothness class in finite time, the tail of the coefficient series stops decaying, and the global basis spreads the resulting oscillations across the whole domain.

Method · advanced

The finite element method

Adapted

Replaces the weak formulation of an elliptic boundary-value problem by the same equation tested only against piecewise-linear hat functions on a triangulation, which turns it into a sparse symmetric positive-definite linear system; proves Galerkin orthogonality and Cea's quasi-optimality bound, states the interpolation estimate that converts quasi-optimality into an O(h)O(h) energy-norm error, and shows on a worked mesh why the method is the one that copes with awkward geometry.

Prerequisites: Weak derivatives and Sobolev spaces, The Lax-Milgram theorem and the Dirichlet problem, Quadratic forms and the Rayleigh quotient

Definition(Triangulation, hat functions and the Galerkin system)AdaptedAdapted from Strauss (2008), §8.5, Figures 1–2 and Eqs. (1)–(5), pp. 222–224; Stakgold & Holst (2011), §10.5, Assumptions 10.5.1–10.5.3 and Definition 10.5.1, pp. 737–739

Let Ω⊂R2\Omega\subset\mathbb{R}^{2} be a bounded polygon. The model problem is the one Strauss takes: Poisson's equation on Ω\Omega with the value of the unknown prescribed to be zero all along the boundary,

−Δu=f  in Ω,u=0  on ∂Ω,-\Delta u = f \ \text{ in }\Omega,\qquad u=0 \ \text{ on }\partial\Omega ,

in the weak form of Weak derivatives and Sobolev spaces: find u∈H01(Ω)u\in H^{1}_{0}(\Omega) with

a(u,v)  :=  ∫Ω∇u⋅∇v dx  =  ∫Ωfv dx  =:  ℓ(v)for every v∈H01(Ω).a(u,v)\;:=\;\int_\Omega \nabla u\cdot\nabla v \,\mathrm{d}x \;=\;\int_\Omega f v\,\mathrm{d}x\;=:\;\ell(v) \qquad\text{for every } v\in H^{1}_{0}(\Omega) .

Triangulation. A triangulation Th\mathcal{T}_h of Ω\Omega is a finite family of closed triangles whose union is Ω‾\overline\Omega, with disjoint interiors, and such that the intersection of two distinct triangles is empty, a common vertex, or a common whole edge. Stakgold and Holst call the last condition conformity and state it for elements of any shape in any dimension; it is what forbids a vertex of one triangle from landing in the middle of a neighbour's edge. Write hKh_K for the diameter of the smallest ball containing KK and ρK\rho_K for the diameter of the largest ball inside KK, put h=max⁡KhKh=\max_K h_K, and call the family shape regular with constant σ\sigma if

hKρK≤σfor every K∈Th,\frac{h_K}{\rho_K}\le\sigma\qquad\text{for every } K\in\mathcal{T}_h ,

which says no triangle is allowed to become arbitrarily thin as the mesh is refined.

The space and its basis. Let V1,…,VNV_1,\dots,V_N be the vertices of the triangulation that lie in the interior of Ω\Omega, and let

Vh={ v∈C(Ω‾) : v is affine on each K∈Th, v=0 on ∂Ω }.V_h=\bigl\{\,v\in C(\overline\Omega)\ :\ v\ \text{is affine on each } K\in\mathcal{T}_h,\ v=0 \text{ on }\partial\Omega\,\bigr\} .

For each interior vertex ViV_i let vi∈Vhv_i\in V_h be the unique element with

vi(Vj)=δij(j=1,…,N)v_i(V_j)=\delta_{ij} \qquad (j=1,\dots,N)

and vi=0v_i=0 at the boundary vertices. Each viv_i is determined on each triangle by its three vertex values, so it exists and is unique; its graph is a pyramid of height 11 with apex over ViV_i, supported on the triangles that touch ViV_i. These are the hat functions (Strauss's trial functions). They are a basis of VhV_h, and the expansion of any v∈Vhv\in V_h reads off its nodal values: v=∑jv(Vj) vjv=\sum_j v(V_j)\,v_j.

That Vh⊂H01(Ω)V_h\subset H^{1}_0(\Omega) is a small theorem, not a definition: a function that is a polynomial on each element and merely continuous across the edges has a weak gradient, because in the integration by parts the jump terms on each interior edge appear twice with opposite normals and cancel. Stakgold and Holst prove exactly this.

The discrete problem. The Galerkin approximation is: find uh∈Vhu_h\in V_h with

a(uh,vh)=ℓ(vh)for every vh∈Vh.a(u_h,v_h)=\ell(v_h)\qquad\text{for every } v_h\in V_h .

Writing uh=∑iUiviu_h=\sum_i U_i v_i and testing against each basis function in turn turns this into the N×NN\times N linear system

∑i=1NAji Ui=Fj(j=1,…,N),Aji=∫Ω∇vi⋅∇vj dx,Fj=∫Ωf vj dx.\sum_{i=1}^{N} A_{ji}\,U_i = F_j \quad (j=1,\dots,N), \qquad A_{ji}=\int_\Omega \nabla v_i\cdot\nabla v_j\,\mathrm{d}x, \qquad F_j=\int_\Omega f\,v_j\,\mathrm{d}x .

AA is the stiffness matrix and FF the load vector; when a time derivative is present the matrix ∫Ωvivj\int_\Omega v_iv_j also appears and is called the mass matrix. Two properties are immediate. AA is symmetric, and it is positive definite because ξTAξ=∫Ω∣∇(∑iξivi)∣2≥0\xi^{\mathsf T}A\xi=\int_\Omega\lvert\nabla(\sum_i\xi_iv_i)\rvert^{2}\ge0 with equality only if ∑ξivi\sum\xi_iv_i is constant, hence zero by the boundary condition (Quadratic forms and the Rayleigh quotient). And AA is sparse: Aji=0A_{ji}=0 unless ViV_i and VjV_j are joined by an edge, because otherwise the supports of viv_i and vjv_j meet in a set of measure zero. Finally Uk=uh(Vk)U_k=u_h(V_k), so the unknowns are the nodal values themselves.

A warning about names. Strauss writes the matrix with entries ∫∇vi⋅∇vj\int\nabla v_i\cdot\nabla v_j as MM and calls it the stiffness matrix, and writes the matrix with entries ∫vivj\int v_iv_j as KK and calls it the mass matrix. The names are his and are standard; the letters are the reverse of the usual engineering ones, in which KK is the stiffness and MM the mass. This unit keeps Strauss's names and uses neutral letters AA for the stiffness matrix and ℓ\ell, FF for the load.

Method(Galerkin orthogonality, quasi-optimality, and the rate)AdaptedAdapted from Stakgold & Holst (2011), §10.2, Eqs. (10.2.16) and (10.2.19)–(10.2.22), Theorem 10.2.9 and Lemma 10.2.3, pp. 677–679; Stakgold & Holst (2011), §10.5, Theorem 10.5.2, pp. 744–745; Evans (2010), §6.2.1, Theorem 1, pp. 297–299; Evans (2010), §6.3.2, Theorem 4, p. 315

Let HH be a real Hilbert space, let a:H×H→Ra:H\times H\to\mathbb{R} be bilinear with

∣a(u,v)∣≤M∥u∥ ∥v∥(M>0),a(u,u) ≥ m∥u∥2(m>0),\lvert a(u,v)\rvert\le M\lVert u\rVert\,\lVert v\rVert\quad (M>0), \qquad a(u,u)\ \ge\ m\lVert u\rVert^{2}\quad (m>0),

and let ℓ\ell be a bounded linear functional on HH. Let Vh⊂HV_h\subset H be a closed subspace.

1. Both problems are uniquely solvable. There is exactly one u∈Hu\in H with a(u,v)=ℓ(v)a(u,v)=\ell(v) for all v∈Hv\in H, and exactly one uh∈Vhu_h\in V_h with a(uh,vh)=ℓ(vh)a(u_h,v_h)=\ell(v_h) for all vh∈Vhv_h\in V_h. This is the Lax–Milgram theorem of The Lax-Milgram theorem and the Dirichlet problem applied twice: the hypotheses on aa are inherited by the subspace, which is why no separate condition on VhV_h is needed. (For a non-symmetric Petrov–Galerkin method, where the trial and test spaces differ, the inherited condition fails and must be imposed separately; Stakgold and Holst call it the Ladyzhenskaya–Babuska–Brezzi condition.)

2. Galerkin orthogonality.

a(u−uh, vh)=0for every vh∈Vh.a(u-u_h,\,v_h)=0\qquad\text{for every } v_h\in V_h .

3. Quasi-optimality (Cea).

∥u−uh∥  ≤  Mm inf⁡vh∈Vh∥u−vh∥.\lVert u-u_h\rVert \;\le\; \frac{M}{m}\,\inf_{v_h\in V_h}\lVert u-v_h\rVert .

The Galerkin solution is, up to the factor M/mM/m, the best approximation to uu available in VhV_h. If aa is in addition symmetric, then aa is an inner product, uhu_h is the aa-orthogonal projection of uu onto VhV_h, and in the energy norm ∥v∥a=a(v,v)1/2\lVert v\rVert_a=a(v,v)^{1/2} the constant is exactly 11: ∥u−uh∥a=inf⁡vh∥u−vh∥a\lVert u-u_h\rVert_a=\inf_{v_h}\lVert u-v_h\rVert_a.

4. The interpolation estimate. Let Th\mathcal{T}_h be shape regular with constant σ\sigma and let IhwI_h w denote the element of VhV_h that agrees with ww at every vertex. There is a constant CC depending only on σ\sigma with

∥w−Ihw∥L2(Ω)≤Ch2∣w∣H2(Ω),∣w−Ihw∣H1(Ω)≤Ch ∣w∣H2(Ω),\lVert w-I_hw\rVert_{L^{2}(\Omega)}\le C h^{2}\lvert w\rvert_{H^{2}(\Omega)}, \qquad \lvert w-I_hw\rvert_{H^{1}(\Omega)}\le C h\,\lvert w\rvert_{H^{2}(\Omega)},

for every w∈H2(Ω)∩H01(Ω)w\in H^{2}(\Omega)\cap H^{1}_0(\Omega). This is the case k=1k=1, p=q=2p=q=2, m=0m=0 and m=1m=1 of the general estimate of Stakgold and Holst, which for an affine-equivalent family reads

∣w−IKw∣m,p,K ≤ C(meas(Ω))(1/q)−(1/p) hK k+1ρK m ∣w∣k+1,p,K\lvert w-I_Kw\rvert_{m,p,K}\ \le\ C\bigl(\mathrm{meas}(\Omega)\bigr)^{(1/q)-(1/p)}\,\frac{h_K^{\,k+1}}{\rho_K^{\,m}}\,\lvert w\rvert_{k+1,p,K}

on each element KK; at p=qp=q the measure factor is 11, and shape regularity converts hKk+1/ρKmh_K^{k+1}/\rho_K^{m} into σmhKk+1−m\sigma^{m}h_K^{k+1-m}.

5. The a priori error bound. Combining 3 and 4 with H=H01(Ω)H=H^{1}_0(\Omega) and the Dirichlet form aa: if the exact solution lies in H2(Ω)H^{2}(\Omega) then

∥u−uh∥H1(Ω) ≤ C′h ∣u∣H2(Ω).\lVert u-u_h\rVert_{H^{1}(\Omega)}\ \le\ C' h\,\lvert u\rvert_{H^{2}(\Omega)} .

That u∈H2u\in H^{2} is a hypothesis about the domain, not a free gift: Evans's elliptic regularity theorem supplies it when f∈L2f\in L^{2} and ∂Ω\partial\Omega is of class C2C^{2}, and it is also true for a convex polygon, but it fails at a re-entrant corner.

Idea of the proofOriginal

Everything turns on one observation. The exact solution satisfies the weak equation against every test function; the approximation satisfies it against the test functions we kept. Subtracting, the error is invisible to the whole of VhV_h: that is Galerkin orthogonality, and it is the statement that uhu_h is a projection of uu along VhV_h.

A projection cannot be much worse than the best approximation, and in an inner-product space it is the best approximation. Coercivity and boundedness say that aa is a distorted inner product, distorted by no more than the factor M/mM/m, so the Galerkin solution is within that factor of best. This is Cea's lemma, and it splits the problem cleanly in two: an analysis question (how good is the projection?) answered once and for all, and an approximation-theory question (how well can piecewise-linear functions approximate uu?) answered by Taylor's theorem on each triangle.

The second question is where the rate comes from. On a triangle of size hh the linear interpolant of a C2C^{2} function is wrong by O(h2)O(h^{2}) and its gradient by O(h)O(h); shape regularity is exactly the condition that stops the gradient estimate from degenerating when a triangle is thin. Multiply the two answers and the energy-norm error is O(h)O(h).

Proof(Parts 2 and 3; part 4 by Taylor's theorem)AdaptedAdapted from Stakgold & Holst (2011), §10.2, proof of Theorem 10.2.9 and Lemma 10.2.3, pp. 678–679

2. The exact solution satisfies a(u,v)=ℓ(v)a(u,v)=\ell(v) for every v∈Hv\in H, and in particular for every vh∈Vhv_h\in V_h, because Vh⊂HV_h\subset H. The discrete solution satisfies a(uh,vh)=ℓ(vh)a(u_h,v_h)=\ell(v_h) for the same vhv_h. Subtracting and using bilinearity in the first slot gives a(u−uh,vh)=0a(u-u_h,v_h)=0. The hypothesis used is only the conformity of the method, Vh⊂HV_h\subset H; nothing else.

3. Let vh∈Vhv_h\in V_h be arbitrary. Coercivity applied to the error, then part 2 with the test function uh−vh∈Vhu_h-v_h\in V_h, then boundedness:

m∥u−uh∥2 ≤ a(u−uh, u−uh) = a(u−uh, u−uh)+a(u−uh, uh−vh)m\lVert u-u_h\rVert^{2} \ \le\ a(u-u_h,\,u-u_h) \ =\ a\bigl(u-u_h,\,u-u_h\bigr)+a\bigl(u-u_h,\,u_h-v_h\bigr)= a(u−uh, u−vh) ≤ M ∥u−uh∥ ∥u−vh∥.=\ a\bigl(u-u_h,\,u-v_h\bigr) \ \le\ M\,\lVert u-u_h\rVert\,\lVert u-v_h\rVert .

The added term vanishes by part 2 since uh−vh∈Vhu_h-v_h\in V_h; the two arguments then combine by bilinearity. If ∥u−uh∥=0\lVert u-u_h\rVert=0 the claim is trivial, and otherwise dividing by m∥u−uh∥m\lVert u-u_h\rVert gives ∥u−uh∥≤(M/m)∥u−vh∥\lVert u-u_h\rVert\le (M/m)\lVert u-v_h\rVert. Taking the infimum over vhv_h gives part 3.

Stakgold and Holst reach the constant 1+M/m1+M/m by bounding the norm of the generalized projection PhP_h and writing u−uh=(I−Ph)(u−vh)u-u_h=(I-P_h)(u-v_h), then remove the leading 11 in the Hilbert-space case by the Kato–Xu–Zikatanov lemma, which says that a non-trivial idempotent P≠0,IP\ne 0,I on a Hilbert space satisfies ∥P∥=∥I−P∥\lVert P\rVert=\lVert I-P\rVert. The direct argument above gives M/mM/m at once in the Hilbert setting, and is the one we use.

Symmetric case. If a(v,w)=a(w,v)a(v,w)=a(w,v) then coercivity and boundedness make aa an inner product whose norm ∥⋅∥a\lVert\cdot\rVert_a is equivalent to ∥⋅∥\lVert\cdot\rVert. Part 2 says u−uh⊥aVhu-u_h\perp_a V_h, so for every vhv_h, by Pythagoras in that inner product,

∥u−vh∥a2=∥u−uh∥a2+∥uh−vh∥a2 ≥ ∥u−uh∥a2,\lVert u-v_h\rVert_a^{2}=\lVert u-u_h\rVert_a^{2}+\lVert u_h-v_h\rVert_a^{2}\ \ge\ \lVert u-u_h\rVert_a^{2} ,

with equality exactly at vh=uhv_h=u_h. So in the energy norm the Galerkin solution is the best approximation; the factor M/mM/m in part 3 is the price of measuring in a different norm.

4, in one dimension and in outline. On an interval [xj,xj+1][x_{j},x_{j+1}] of length hh let e=w−Ihwe=w-I_hw, which vanishes at both endpoints. By Rolle's theorem e′e' vanishes at some interior ξ\xi, so for any xx in the interval e′(x)=∫ξxw′′e'(x)=\int_\xi^x w'', and by Cauchy–Schwarz ∣e′(x)∣2≤h∫∣w′′∣2\lvert e'(x)\rvert^{2}\le h\int\lvert w''\rvert^{2}; integrating over the interval gives ∫∣e′∣2≤h2∫∣w′′∣2\int\lvert e'\rvert^{2}\le h^{2}\int\lvert w''\rvert^{2}. Since ee vanishes at xjx_j, ∣e(x)∣2≤h∫∣e′∣2\lvert e(x)\rvert^2\le h\int\lvert e'\rvert^{2} in the same way, and a second integration gives ∫∣e∣2≤h4∫∣w′′∣2\int\lvert e\rvert^{2}\le h^{4}\int\lvert w''\rvert^{2}. Summing over the elements gives part 4 with C=1C=1 in one dimension. In two dimensions the same two powers of hh appear, by mapping each triangle affinely to a fixed reference triangle, estimating there by the Bramble–Hilbert argument, and mapping back; the Jacobian factors produce hKk+1/ρKmh_K^{k+1}/\rho_K^{m}, which is where shape regularity enters. Stakgold and Holst give this chain as Lemmas 10.5.1–10.5.3 and Theorem 10.5.2 and attribute the detailed proof to Ciarlet. □\square

Remark(Where the hypotheses are used, and what goes wrong without them)Original

Conformity (Vh⊂H01V_h\subset H^{1}_0) is the only hypothesis in Galerkin orthogonality, and it is why continuity across edges matters: a piecewise-linear function with a jump across an edge is not in H1H^1, its weak gradient picks up a delta on the edge, and the whole argument collapses. Non-conforming elements are used in practice, but they need their own error analysis with an extra consistency term.

Coercivity is what makes AA invertible and the error bound finite. For the Dirichlet form it comes from the Poincare inequality (The Lax-Milgram theorem and the Dirichlet problem), which uses the boundary condition; drop the boundary condition and a(1,1)=0a(1,1)=0, the constant function is in the kernel, and the pure Neumann problem is solvable only up to a constant and only for ff with mean zero.

Shape regularity is used only in part 4, and the bound genuinely fails without it. Take the flat triangle KK with vertices (0,0)(0,0), (h,0)(h,0), (h/2,ε)(h/2,\varepsilon), whose largest angle tends to π\pi as ε→0\varepsilon\to0, and interpolate w(x,y)=x2w(x,y)=x^{2}. The affine function through the three vertex values 00, h2h^{2}, h2/4h^{2}/4 is p(x,y)=hx−h24εyp(x,y)=hx-\tfrac{h^{2}}{4\varepsilon}y, so ∂y(w−p)=h2/(4ε)\partial_y(w-p)=h^{2}/(4\varepsilon) on all of KK and

∣w−IKw∣H1(K)2 ≥ h416ε2⋅meas(K)=h532ε,hK2 ∣w∣H2(K)2=h2⋅4 meas(K)=2h3ε.\lvert w-I_Kw\rvert_{H^1(K)}^{2}\ \ge\ \frac{h^{4}}{16\varepsilon^{2}}\cdot\mathrm{meas}(K)=\frac{h^{5}}{32\varepsilon}, \qquad h_K^{2}\,\lvert w\rvert^{2}_{H^{2}(K)}=h^{2}\cdot 4\,\mathrm{meas}(K)=2h^{3}\varepsilon .

Their ratio is h2/(64ε2)h^{2}/(64\varepsilon^{2}), which is unbounded: the clean estimate ∣w−IKw∣H1≤ChK∣w∣H2\lvert w-I_Kw\rvert_{H^1}\le Ch_K\lvert w\rvert_{H^2} is false for a degenerating family. The estimate that survives is the one Stakgold and Holst actually state, with hK2/ρKh_K^{2}/\rho_K in place of hKh_K; here ρK\rho_K is of order ε\varepsilon, that factor is of order h2/εh^{2}/\varepsilon, and the bound it gives, of order h5/εh^{5}/\varepsilon for the square of the seminorm, matches the true error. So the error is not mysteriously large — it is exactly as large as the general theorem says, and shape regularity is the hypothesis that turns the general theorem into a rate in hh. A mesh refined by flattening rather than shrinking its triangles need not converge in H1H^1 at all. Quasi-uniformity, the stronger condition hK1/hK2≤νh_{K_1}/h_{K_2}\le\nu that Stakgold and Holst state alongside, is not needed for the bound above; it is deliberately broken by adaptive methods, which refine only where an error indicator is large.

u∈H2u\in H^{2} is used in part 5 and nowhere else. On a convex polygon it holds; on an L-shaped domain the solution behaves like r2/3sin⁡(2θ/3)r^{2/3}\sin(2\theta/3) near the re-entrant corner, which is in H1H^1 but not in H2H^2, and the uniform-mesh rate drops from hh to h2/3h^{2/3} in the energy norm. Recovering the full rate there requires grading the mesh towards the corner — which is precisely the freedom that shape regularity without quasi-uniformity leaves open.

What quasi-optimality does not say. Part 3 bounds the error by the best approximation error; it says nothing about whether the best approximation is any good. All of the approximation power of the method is in part 4, and all of the geometry is in the triangulation. This separation is the reason the finite element method can be analysed at all on a domain whose shape no coordinate system fits.

Method(Assembling and solving)Original
  1. Triangulate. Produce a conforming, shape-regular mesh of Ω‾\overline\Omega; record the vertex coordinates and, for each triangle, the indices of its three vertices. Mark the vertices on ∂Ω\partial\Omega as constrained.
  2. Compute the element matrices. On a triangle KK with vertices P1,P2,P3P_1,P_2,P_3, the hat function λr\lambda_r associated with PrP_r is affine with λr(Ps)=δrs\lambda_r(P_s)=\delta_{rs}, so ∇λr\nabla\lambda_r is a constant vector on KK. Explicitly, with area(K)=12∣det⁡[P2−P1, P3−P1]∣\mathrm{area}(K)=\tfrac12\lvert\det[P_2-P_1,\,P_3-P_1]\rvert, ∇λr=12 area(K) (Pr+2−Pr+1)⊥,\nabla\lambda_r=\frac{1}{2\,\mathrm{area}(K)}\,\bigl(P_{r+2}-P_{r+1}\bigr)^{\perp}, where the indices are read modulo 33 in {1,2,3}\{1,2,3\}, (a,b)⊥=(−b,a)(a,b)^{\perp}=(-b,a), and P1,P2,P3P_1,P_2,P_3 are listed anticlockwise. (Check on the triangle (0,0),(1,0),(0,1)(0,0),(1,0),(0,1): λ1=1−x−y\lambda_1=1-x-y, and the formula gives ((0,1)−(1,0))⊥=(−1,−1)\bigl((0,1)-(1,0)\bigr)^{\perp}=(-1,-1).) The 3×33\times3 element stiffness matrix is then ArsK=area(K) ∇λr⋅∇λsA^K_{rs}=\mathrm{area}(K)\,\nabla\lambda_r\cdot\nabla\lambda_s, exactly, because the integrand is constant.
  3. Assemble. Initialise A=0A=0, F=0F=0 and loop over triangles, adding ArsKA^{K}_{rs} into the global entry (ir,is)(i_r,i_s) for each pair of local vertices and ∫Kfλr\int_K f\lambda_r into FirF_{i_r}. Skip rows and columns belonging to constrained vertices (or keep them and impose U=0U=0 there). The whole loop is O(#Th)=O(N)O(\#\mathcal{T}_h)=O(N).
  4. Integrate the load. ∫Kfλr\int_K f\lambda_r is rarely available in closed form; the usual choice is a quadrature rule exact for the polynomial degree in play (Numerical quadrature). For linear elements, the one-point rule ∫Kg≈area(K) g(centroid)\int_K g\approx \mathrm{area}(K)\,g(\text{centroid}) is exact for affine gg and enough to preserve the O(h)O(h) rate. For f≡1f\equiv1 it gives the exact value ∫Kλr=area(K)/3\int_K\lambda_r=\mathrm{area}(K)/3.
  5. Solve. AA is symmetric positive definite and sparse, with about 77 non-zeros per row for a typical triangulation. Use the Cholesky factorisation of a banded or reordered matrix for moderate NN, or the conjugate gradient method preconditioned so that the iteration count does not grow with NN (Solving linear systems numerically, Relaxation methods for elliptic problems). An unpreconditioned iteration is slow because cond⁡(A)=O(h−2)\operatorname{cond}(A)=O(h^{-2}), the same growth as for the difference Laplacian.
  6. Check the rate. Solve on a mesh and on its uniform refinement and compare: the energy-norm error should fall by 22 and the L2L^{2} error by 44. A rate below that is the usual sign that the solution is not in H2H^{2}, that the quadrature in step 4 is too crude, or that the mesh is degenerating.
  7. For a time-dependent problem keep the same space and leave the time variable continuous: K U˙=−κA U+F(t)K\,\dot U = -\kappa A\,U + F(t) with KK the mass matrix ∫vivj\int v_iv_j, then step in time by any method of Integrators for ODEs. Strauss writes out both the forward and the backward Euler versions; the backward one requires solving with K+κ Δt AK+\kappa\,\Delta t\,A at each step, which is the price of avoiding the Δt=O(h2)\Delta t=O(h^{2}) restriction of Stability and stiff equations.
Example(One dimension exactly, two dimensions on four triangles)Original

(a) A one-dimensional problem solved completely. Take

−u′′=f  on (0,1),u(0)=u(1)=0,f(x)=π2sin⁡πx,-u''=f \ \text{ on } (0,1),\qquad u(0)=u(1)=0,\qquad f(x)=\pi^{2}\sin\pi x,

whose exact solution is u(x)=sin⁡πxu(x)=\sin\pi x. Use the uniform mesh xj=jhx_j=jh, h=1/nh=1/n, with the tent functions vjv_j of the definition. Two integrals are needed.

Stiffness. vj′=1/hv_j'=1/h on (xj−1,xj)(x_{j-1},x_j) and −1/h-1/h on (xj,xj+1)(x_j,x_{j+1}), so

Ajj=∫01(vj′)2=2h⋅1h2=2h,Aj,j+1=∫xjxj+1 ⁣ ⁣(−1h)(1h)=−1h,A_{jj}=\int_0^1 (v_j')^{2}=2h\cdot\frac1{h^{2}}=\frac2h, \qquad A_{j,j+1}=\int_{x_j}^{x_{j+1}}\!\!\Bigl(-\frac1h\Bigr)\Bigl(\frac1h\Bigr)=-\frac1h ,

and Aji=0A_{ji}=0 for ∣i−j∣≥2\lvert i-j\rvert\ge2. So A=h−1tridiag(−1,2,−1)A=h^{-1}\mathrm{tridiag}(-1,2,-1), which is Strauss's tridiagonal matrix with 22 on the diagonal and −1-1 beside it, divided by hh.

Load. With ∫0hthsin⁡(π(xj−h+t))dt\int_{0}^{h}\frac{t}{h}\sin\bigl(\pi(x_j-h+t)\bigr)\mathrm{d}t and its mirror image combined,

Fj=π2 ⁣∫01sin⁡(πx) vj(x) dx=2(1−cos⁡πh)h sin⁡(πxj).F_j=\pi^{2}\!\int_0^1 \sin(\pi x)\,v_j(x)\,\mathrm{d}x=\frac{2\bigl(1-\cos\pi h\bigr)}{h}\,\sin(\pi x_j) .

Solving. Try Uj=csin⁡(πxj)U_j=c\sin(\pi x_j). The left side of the jjth equation is

ch(2sin⁡πxj−sin⁡πxj−1−sin⁡πxj+1)=ch(2−2cos⁡πh)sin⁡πxj,\frac{c}{h}\bigl(2\sin\pi x_j-\sin\pi x_{j-1}-\sin\pi x_{j+1}\bigr) =\frac{c}{h}\bigl(2-2\cos\pi h\bigr)\sin\pi x_j ,

using sin⁡(θ±πh)=sin⁡θcos⁡πh±cos⁡θsin⁡πh\sin(\theta\pm\pi h)=\sin\theta\cos\pi h\pm\cos\theta\sin\pi h, whose cos⁡θ\cos\theta terms cancel. Comparing with FjF_j gives c=1c=1. So

Uj=sin⁡(πxj)=u(xj)exactly, at every node and for every h.U_j=\sin(\pi x_j)=u(x_j)\quad\text{exactly, at every node and for every }h .

With h=14h=\tfrac14: A=4 tridiag(−1,2,−1)A=4\,\mathrm{tridiag}(-1,2,-1), F=(8−42)(22,1,22)=(1.656854, 2.343146, 1.656854)F=\bigl(8-4\sqrt2\bigr)\bigl(\tfrac{\sqrt2}{2},1,\tfrac{\sqrt2}{2}\bigr)=(1.656854,\,2.343146,\,1.656854), and the solution of the 3×33\times3 system is U=(22,1,22)U=(\tfrac{\sqrt2}{2},1,\tfrac{\sqrt2}{2}).

Why exact? Not an accident of this ff. Fix a node xkx_k and let GkG_k be the Green's function G(⋅,xk)G(\cdot,x_k) of the problem, so u(xk)=∫01Gkfu(x_k)=\int_0^1 G_k f and a(w,Gk)=w(xk)a(w,G_k)=w(x_k) for every w∈H01w\in H^1_0 (Green's function for a boundary-value problem). For −d2/dx2-\mathrm{d}^2/\mathrm{d}x^2 on an interval, GkG_k is piecewise linear with its only kink at xkx_k — a node — so Gk∈VhG_k\in V_h. Galerkin orthogonality then gives u(xk)−uh(xk)=a(u−uh, Gk)=0u(x_k)-u_h(x_k)=a(u-u_h,\,G_k)=0. In two dimensions the Green's function has a logarithmic singularity and is not in VhV_h, and nodal exactness is lost.

The error between the nodes is not zero, and this is what carries the rate. Computing ∥u−uh∥L2\lVert u-u_h\rVert_{L^{2}} and ∣u−uh∣H1\lvert u-u_h\rvert_{H^{1}} exactly, element by element:

nn hh ∥u−uh∥L2\lVert u-u_h\rVert_{L^2} ratio ∣u−uh∣H1\lvert u-u_h\rvert_{H^1} ratio
44 0.250.25 3.928435×10−23.928435\times10^{-2} — 0.49850850.4985085 —
88 0.1250.125 9.920920×10−39.920920\times10^{-3} 3.9603.960 0.25118180.2511818 1.98471.9847
1616 0.06250.0625 2.486501×10−32.486501\times10^{-3} 3.9903.990 0.12583320.1258332 1.99621.9962

The ratios approach 44 and 22: O(h2)O(h^{2}) in L2L^{2} and O(h)O(h) in H1H^{1}, as parts 4 and 5 predict. (Here ∣u∣H2=π2/2=6.9789\lvert u\rvert_{H^{2}}=\pi^{2}/\sqrt2=6.9789, and the measured H1H^1 error at h=1/16h=1/16 is 0.12580.1258, so the constant C′C' in part 5 is about 0.290.29.)

(b) Two dimensions on the coarsest possible mesh. Take Ω=(0,1)2\Omega=(0,1)^{2}, f≡1f\equiv1, u=0u=0 on the boundary. Triangulate by drawing both diagonals of the square: four triangles, four boundary vertices, and one interior vertex V1=(12,12)V_1=(\tfrac12,\tfrac12). So N=1N=1 and the system is a single equation.

On the lower triangle, with vertices (0,0),(1,0),(12,12)(0,0),(1,0),(\tfrac12,\tfrac12), the hat function v1v_1 vanishes at the first two and equals 11 at the third, and the affine function with those values is v1(x,y)=2yv_1(x,y)=2y. Hence ∣∇v1∣2=4\lvert\nabla v_1\rvert^{2}=4 there, and the triangle has area 14\tfrac14, contributing 4⋅14=14\cdot\tfrac14=1. By the fourfold symmetry of the mesh the other three contribute the same, so

A11=∫Ω∣∇v1∣2=4.A_{11}=\int_\Omega\lvert\nabla v_1\rvert^{2}=4 .

For the load, the integral of an affine function over a triangle is its area times the mean of its three vertex values, so each triangle contributes 14⋅0+0+13=112\tfrac14\cdot\tfrac{0+0+1}{3}=\tfrac1{12} and

F1=∫Ωv1=4⋅112=13.F_1=\int_\Omega v_1 = 4\cdot\tfrac1{12}=\tfrac13 .

Therefore

uh(12,12)=U1=F1A11=1/34=112=0.0833333.u_h\Bigl(\tfrac12,\tfrac12\Bigr)=U_1=\frac{F_1}{A_{11}}=\frac{1/3}{4}=\frac{1}{12}=0.0833333 .

The exact value, from the double sine series u=∑m,n odd16π4mn(m2+n2)sin⁡mπx sin⁡nπyu=\sum_{m,n\ \mathrm{odd}} \dfrac{16}{\pi^{4}mn(m^{2}+n^{2})}\sin m\pi x\,\sin n\pi y of Separation of variables in standard coordinates, is

u(12,12)=∑m,n odd16 (−1)(m+n)/2−1π4mn(m2+n2)=0.0736714,u\Bigl(\tfrac12,\tfrac12\Bigr)=\sum_{m,n\ \mathrm{odd}}\frac{16\,(-1)^{(m+n)/2-1}}{\pi^{4}mn(m^{2}+n^{2})}=0.0736714 ,

so the single-element answer is high by 13.1%13.1\%. That is a respectable showing for one unknown.

Refining. Take instead the uniform mesh of n2n^{2} squares each cut by its lower-left-to-upper-right diagonal. A short computation of the six triangles around an interior node (the same calculation as above, done on right triangles with legs hh) gives the row

Aii=4,Aij=−1 for the four axis neighbours,Aij=0 for the two diagonal ones,A_{ii}=4,\qquad A_{ij}=-1 \ \text{for the four axis neighbours},\qquad A_{ij}=0 \ \text{for the two diagonal ones},

with no hh in it, while Fi=∫Ωvi=h2F_i=\int_\Omega v_i = h^{2} for f≡1f\equiv1. So on this mesh the finite element equations are identical to the five-point difference scheme of Finite-difference approximations — the methods coincide here, and they diverge as soon as the mesh or the data stop being so symmetric. Solving:

nn hh uh(12,12)u_h(\tfrac12,\tfrac12) error ratio
22 0.50.5 0.06250000.0625000 −1.1171×10−2-1.1171\times10^{-2} —
44 0.250.25 0.07031250.0703125 −3.3589×10−3-3.3589\times10^{-3} 3.333.33
88 0.1250.125 0.07278260.0727826 −8.8872×10−4-8.8872\times10^{-4} 3.783.78
1616 0.06250.0625 0.07344580.0734458 −2.2559×10−4-2.2559\times10^{-4} 3.943.94
3232 0.031250.03125 0.07361470.0736147 −5.6616×10−5-5.6616\times10^{-5} 3.983.98

The nodal error falls by a factor approaching 44: second order, one power better than the O(h)O(h) of part 5, which is a bound in the energy norm. The L2L^{2} and pointwise errors of the finite element method on a convex domain are O(h2)O(h^{2}), by a duality argument that trades the extra power for the regularity of an auxiliary problem.

Application(Why engineering computes this way)Original

Structural analysis, where the names come from. The method was built by aeronautical and civil engineers in the 1950s to compute stresses in built-up structures, and the vocabulary is theirs: AA is the stiffness matrix because for the elasticity bilinear form a(u,v)=∫σ(u):ε(v)a(u,v)=\int \sigma(u):\varepsilon(v) it is literally the matrix of spring constants relating nodal displacements to nodal forces, and FF is the load. The energy-norm statement of part 3 then has a physical reading: among all displacement fields representable on the mesh, the computed one is the one of least potential energy, which is the Rayleigh–Ritz principle of The Rayleigh-Ritz method restricted to a finite-dimensional space. Strauss notes that the method was invented to deal with curved and irregular domains, where finite differences fit badly.

Why it wins over finite differences. Not accuracy on a square — the example above shows the two methods coinciding there — but geometry and boundary conditions. An aerofoil, a heart ventricle, a turbine blade and a reservoir have no coordinate system; a triangulation has no trouble with any of them, grades itself finely where the solution varies and coarsely elsewhere, and handles a Neumann or Robin condition for free, because such conditions appear as boundary terms in the weak form rather than as extra equations at ghost points.

Where the error estimate is used in anger. Part 5 bounds the error by a norm of the unknown solution, which cannot be evaluated. Practical codes therefore use a posteriori estimators, computable from uhu_h alone — typically the element residual ∥f+Δuh∥L2(K)\lVert f+\Delta u_h\rVert_{L^2(K)} together with the jumps of ∇uh\nabla u_h across edges — to decide which elements to refine, and iterate solve, estimate, mark, refine. Stakgold and Holst give exactly this loop as an algorithm. The theory of this unit is what guarantees that the loop is converging to something.

Beyond Poisson. The same three lines — weak form, conforming subspace, Galerkin — carry over to linear elasticity, to Stokes flow (where the velocity and pressure spaces must be chosen compatibly, or the inf–sup condition of part 1 fails and the pressure develops a checkerboard oscillation), to the eigenvalue problems of Sturm-Liouville eigenvalue problems in several dimensions, and to the time-dependent problems of step 7. The analysis of all of them is the same analysis: Cea's lemma plus an approximation estimate.

Method

Monte Carlo methods

Adapted

Turns an integral into the mean of a random variable, so that the law of large numbers computes it and the central limit theorem supplies an error bar; shows that the root-mean-square error is σ/n\sigma/\sqrt{n} whatever the dimension, which is why the method is used above four dimensions and not below; and derives importance sampling and the Metropolis algorithm as the two ways of changing the sampling distribution when the obvious one is too noisy or unavailable.

Prerequisites: Laws of large numbers, The central limit theorem, Convergence of Markov chains, Expectation, variance and covariance

Definition(The estimator, and the three ways of choosing the samples)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.4.4, Eqs. (27.48)–(27.49), pp. 1011–1012; Grimmett & Stirzaker (2020), §2.6, Example (3), p. 44; Grimmett & Stirzaker (2020), Exercise (4.11.12), pp. 142–143; Grimmett & Stirzaker (2020), §6.14, Eqs. (6.14.3)–(6.14.5) and Example (6.14.8), pp. 331–332

Every integral is an expectation. If D⊆RdD\subseteq\mathbb{R}^{d} has finite volume ∣D∣\lvert D\rvert and XX is uniform on DD, then

θ=∫Dg(x) dx=∣D∣ E[g(X)],\theta=\int_D g(x)\,\mathrm{d}x=\lvert D\rvert\,\mathrm{E}\bigl[g(X)\bigr] ,

and more generally, for any probability density pp that is positive wherever gg is non-zero,

θ=∫Dg(x) dx=Ep ⁣[g(Y)p(Y)],Y∼p.\theta=\int_D g(x)\,\mathrm{d}x=\mathrm{E}_p\!\left[\frac{g(Y)}{p(Y)}\right],\qquad Y\sim p .

A Monte Carlo method estimates θ\theta by drawing samples and averaging. Three choices of sampling distribution give the three methods of this unit. Throughout, X1,X2,…X_1,X_2,\dots are independent and ξ1,ξ2,…\xi_1,\xi_2,\dots are independent and uniform on [0,1)[0,1).

1. Crude Monte Carlo. Sample uniformly. Riley, Hobson and Bence first reduce the problem by a change of variable to the standard form θ=∫01f(x) dx\theta=\int_0^1 f(x)\,\mathrm{d}x and then estimate it by

θ^n=1n∑i=1nf(ξi).\hat\theta_n=\frac1n\sum_{i=1}^{n}f(\xi_i) .

They insist on two properties of any such scheme: the estimator must be unbiased, E[θ^n]=θ\mathrm{E}[\hat\theta_n]=\theta, and the method must report the variance of the estimate — a statistical statement, not an interval inside which the answer is guaranteed to lie.

A variant, the hit-or-miss method, estimates the area under a curve by the proportion of random points in a bounding box that fall below it: if 0≤f≤10\le f\le1 on [0,1][0,1] and (ξ2i−1,ξ2i)(\xi_{2i-1},\xi_{2i}) are uniform on the unit square, the fraction of ii with ξ2i≤f(ξ2i−1)\xi_{2i}\le f(\xi_{2i-1}) estimates θ\theta, because that event has probability exactly θ\theta. It is simpler and, as the remark below shows, always noisier.

2. Importance sampling. Sample from a density pp of our choosing and correct by the likelihood ratio. For θ=E[g(X)]\theta=\mathrm{E}[g(X)] with XX of density qq, choose a density pp that vanishes exactly where qq does and put

θ^n IS=1n∑i=1nw(Yi) g(Yi),w(y)=q(y)p(y),Yi∼p independent.\hat\theta_n^{\,\mathrm{IS}}=\frac1n\sum_{i=1}^{n} w(Y_i)\,g(Y_i), \qquad w(y)=\frac{q(y)}{p(y)}, \qquad Y_i\sim p \text{ independent} .

Grimmett and Stirzaker call pp the importance density. The point is to put the samples where ∣g∣q\lvert g\rvert q is large; the price is that one must be able to sample from pp.

3. Markov chain Monte Carlo. When π\pi is a distribution on a finite set Θ\Theta known only up to its normalising constant, as a Boltzmann weight π(ϑ)=Z−1e−βE(ϑ)\pi(\vartheta)=Z^{-1}\mathrm{e}^{-\beta E(\vartheta)} is, independent sampling from π\pi is out of reach. Instead build a Markov chain with stationary distribution π\pi and average along a single trajectory. Grimmett and Stirzaker's recipe has two ingredients: a proposal matrix H=(hij)H=(h_{ij}), any stochastic matrix that is cheap to simulate, and an acceptance matrix A=(aij)A=(a_{ij}) with 0≤aij≤10\le a_{ij}\le1. From state ii one draws jj with probability hijh_{ij} and moves there with probability aija_{ij}, staying put otherwise, so that

pij=hijaij (i≠j),pii=1−∑k≠ihikaik.p_{ij}=h_{ij}a_{ij}\ (i\ne j), \qquad p_{ii}=1-\sum_{k\ne i}h_{ik}a_{ik} .

The Hastings choice of acceptance probability is

aij=min⁡{1, πjhjiπihij},a_{ij}=\min\left\{1,\ \frac{\pi_j h_{ji}}{\pi_i h_{ij}}\right\} ,

and when the proposal is symmetric, hij=hjih_{ij}=h_{ji}, this reduces to the Metropolis rule

aij=min⁡{1, πjπi}.a_{ij}=\min\left\{1,\ \frac{\pi_j}{\pi_i}\right\} .

Both depend on π\pi only through ratios, so the unknown constant ZZ never appears. The estimator, allowing a burn-in of MM discarded steps, is

θ^M,n MC=1n∑r=MM+n−1g(Xr).\hat\theta^{\,\mathrm{MC}}_{M,n}=\frac1n\sum_{r=M}^{M+n-1} g(X_r) .
Method(What the three estimators cost)AdaptedAdapted from Riley, Hobson & Bence (2006), §27.4.4, pp. 1011–1012; Grimmett & Stirzaker (2020), Exercise (4.11.12), pp. 142–143; Grimmett & Stirzaker (2020), §6.14, Eqs. (6.14.3)–(6.14.5), pp. 331–332

1. Crude Monte Carlo. Let ff be measurable on [0,1][0,1] with θ=∫01f\theta=\int_0^1f and σ2=∫01f2−θ2<∞\sigma^{2}=\int_0^1 f^{2}-\theta^{2}<\infty. Then for every nn

E[θ^n]=θ,Var⁡[θ^n]=σ2n,E[(θ^n−θ)2]=σn.\mathrm{E}\bigl[\hat\theta_n\bigr]=\theta, \qquad \operatorname{Var}\bigl[\hat\theta_n\bigr]=\frac{\sigma^{2}}{n}, \qquad \sqrt{\mathrm{E}\bigl[(\hat\theta_n-\theta)^{2}\bigr]}=\frac{\sigma}{\sqrt n} .

Moreover θ^n→θ\hat\theta_n\to\theta almost surely; and if in addition σ>0\sigma>0, then n(θ^n−θ)/σ\sqrt n(\hat\theta_n-\theta)/\sigma converges in distribution to a standard normal, so that

Pr⁡(∣θ^n−θ∣≤1.96 snn)⟶0.95,sn2=1n−1∑i=1n(f(ξi)−θ^n)2.\Pr\Bigl(\lvert\hat\theta_n-\theta\rvert\le 1.96\,\frac{s_n}{\sqrt n}\Bigr)\longrightarrow 0.95, \qquad s_n^{2}=\frac{1}{n-1}\sum_{i=1}^{n}\bigl(f(\xi_i)-\hat\theta_n\bigr)^{2} .

(The hypothesis σ>0\sigma>0 is not cosmetic: for ff constant the ratio is 0/00/0, sns_n vanishes identically, and the probability on the left is 11 for every nn, not 0.950.95.)

2. Dimension. None of this mentions the dimension. In dd dimensions, with θ=∫[0,1]df\theta=\int_{[0,1]^d}f and σ2=Var⁡f(X)\sigma^{2}=\operatorname{Var}f(X) for XX uniform on the cube, the same three statements hold verbatim. By contrast a product quadrature rule of order pp (Numerical quadrature) with kk nodes per axis uses n=kdn=k^{d} points and has error O(k−p)=O(n−p/d)O(k^{-p})=O(n^{-p/d}). Hence

Monte Carlo is asymptotically the better rate exactly when d>2p.\text{Monte Carlo is asymptotically the better rate exactly when } d>2p .

For the trapezoidal rule (p=2p=2) the crossover is d=4d=4; for Simpson's rule (p=4p=4) it is d=8d=8.

3. Importance sampling. With qq, pp, w=q/pw=q/p and Yi∼pY_i\sim p as in the definition, and assuming Ep[(wg)2]<∞\mathrm{E}_p[(wg)^{2}]<\infty,

E[θ^n IS]=θ,Var⁡[θ^n IS]=1n(∫g2q2p−θ2),\mathrm{E}\bigl[\hat\theta^{\,\mathrm{IS}}_n\bigr]=\theta, \qquad \operatorname{Var}\bigl[\hat\theta^{\,\mathrm{IS}}_n\bigr]=\frac{1}{n}\left(\int \frac{g^{2}q^{2}}{p}-\theta^{2}\right),

and θ^n IS→θ\hat\theta^{\,\mathrm{IS}}_n\to\theta almost surely. The variance is minimised, over all densities pp that are positive wherever gq≠0gq\neq0, by

p∗(y)=∣g(y)∣q(y)∫∣g∣q,p^{\ast}(y)=\frac{\lvert g(y)\rvert q(y)}{\int\lvert g\rvert q} ,

for which the variance is (∫∣g∣q)2−θ2\bigl(\int\lvert g\rvert q\bigr)^{2}-\theta^{2}, and this is zero when gg does not change sign. The class competed over here is wider than the one the definition allows: p∗p^{\ast} vanishes wherever gg does, so if g=0g=0 on a set where q>0q>0 then p∗p^{\ast} is not a density that "vanishes exactly where qq does". That is harmless — the estimator needs p>0p>0 only where gq≠0gq\neq0, since the summand wgwg is zero elsewhere — but the two conditions are different, and it is the weaker one that the optimality is proved over. The ideal is unusable — it needs the answer — but it says what to aim at: make wgw g nearly constant.

4. Markov chain Monte Carlo. Let π\pi be positive on a finite Θ\Theta, let HH be a stochastic matrix with hij>0h_{ij}>0 exactly when hji>0h_{ji}>0, and let PP be built with the Hastings acceptance probabilities. Then PP satisfies the detailed balance equations πipij=πjpji\pi_ip_{ij}=\pi_jp_{ji}, so π\pi is stationary for PP and the chain is reversible. If PP is in addition irreducible and aperiodic then, by Convergence of Markov chains,

θ^M,n MC⟶∑ϑg(ϑ)π(ϑ)almost surely as n→∞, for every M and every starting state,\hat\theta^{\,\mathrm{MC}}_{M,n}\longrightarrow\sum_{\vartheta}g(\vartheta)\pi(\vartheta) \quad\text{almost surely as } n\to\infty,\ \text{for every } M \text{ and every starting state},

and the distribution of XnX_n approaches π\pi geometrically at the rate ∣λ2∣\lvert\lambda_2\rvert, the second largest eigenvalue modulus of PP. For large nn the variance of the estimator is

Var⁡[θ^M,n MC] ∼ γ0 τn,τ=1+2∑k=1∞ρk,ρk=γkγ0,γk=Cov⁡π(g(X0),g(Xk)),\operatorname{Var}\bigl[\hat\theta^{\,\mathrm{MC}}_{M,n}\bigr]\ \sim\ \frac{\gamma_0\,\tau}{n}, \qquad \tau=1+2\sum_{k=1}^{\infty}\rho_k, \qquad \rho_k=\frac{\gamma_k}{\gamma_0},\qquad \gamma_k=\operatorname{Cov}_\pi\bigl(g(X_0),g(X_k)\bigr) ,

so n/τn/\tau correlated samples are worth nn independent ones. The quantity τ\tau is the integrated autocorrelation time; it exceeds 11 when successive states are positively correlated, which is the usual case, and can be less than 11.

Idea of the proofOriginal

The law of large numbers is a numerical method. Write the quantity you want as an average over a probability distribution, draw from that distribution, and average: convergence is guaranteed by Laws of large numbers, and the central limit theorem (The central limit theorem) converts the convergence into an error bar computed from the same samples that produced the answer. Nothing in that argument knows how many variables there are, which is the whole reason the method exists: a product quadrature rule must pay kdk^{d} points to resolve kk scales per axis, while a Monte Carlo estimate pays σ2/ϵ2\sigma^{2}/\epsilon^{2} points for accuracy ϵ\epsilon no matter what dd is.

The price is the rate: n−1/2n^{-1/2} is slow, and nothing improves it, because it is the central limit theorem. What can be improved is σ\sigma, and the two refinements do exactly that. Importance sampling changes the measure so that the quantity being averaged is more nearly constant, which is the only thing that makes a variance small. The Metropolis algorithm changes the measure in the opposite situation, where the target distribution is known only up to a constant: it gives up independence, building instead a chain whose equilibrium is the target, and buys that with a loss of efficiency measured by the autocorrelation time.

The acceptance formula is not guessed. Demand detailed balance — that the chain in equilibrium runs the same backwards as forwards — write out what that requires of aija_{ij}, and the condition is a single equation in the ratio aij/ajia_{ij}/a_{ji}. Taking each aa as large as that equation allows gives the minimum, and it involves π\pi only through ratios, which is why an unknown partition function is no obstacle.

Proof(Parts 1–4)AdaptedAdapted from Grimmett & Stirzaker (2020), Exercise (4.11.12), pp. 142–143; Grimmett & Stirzaker (2020), §6.14, Eqs. (6.14.3)–(6.14.5), p. 332

1. Each f(ξi)f(\xi_i) has mean θ\theta and variance σ2\sigma^{2}, so E[θ^n]=θ\mathrm{E}[\hat\theta_n]=\theta by linearity. Since the ξi\xi_i are independent, the variances add (Expectation, variance and covariance):

Var⁡[θ^n]=1n2∑i=1nVar⁡[f(ξi)]=σ2n.\operatorname{Var}\bigl[\hat\theta_n\bigr]=\frac1{n^{2}}\sum_{i=1}^{n}\operatorname{Var}\bigl[f(\xi_i)\bigr]=\frac{\sigma^{2}}{n} .

Because the estimator is unbiased, its mean square error is its variance, which gives the third formula. Almost sure convergence is the strong law of Laws of large numbers, which needs only E∣f(ξ)∣<∞\mathrm{E}\lvert f(\xi)\rvert<\infty — weaker than the variance hypothesis. The normal limit is The central limit theorem applied to the i.i.d. summands f(ξi)f(\xi_i); replacing σ\sigma by the sample standard deviation sns_n is legitimate because sn→σs_n\to\sigma almost surely and Slutsky's lemma lets a convergent-in-probability factor be substituted into a weak limit.

2. The computation in part 1 used independence and the two moments of f(ξ)f(\xi) and nothing else, so it is insensitive to the domain. For the comparison, a product rule of order pp has error Ck−pCk^{-p} per axis with kk nodes per axis, hence n=kdn=k^{d} and error Cn−p/dCn^{-p/d}. Setting n−p/d=n−1/2n^{-p/d}=n^{-1/2} gives p/d=1/2p/d=1/2; for d>2pd>2p the exponent p/dp/d is smaller than 1/21/2 and the deterministic rule is asymptotically worse.

3. Since p>0p>0 wherever q>0q>0, the substitution is legitimate and

E[w(Y)g(Y)]=∫q(y)p(y)g(y) p(y) dy=∫g q=θ,\mathrm{E}\bigl[w(Y)g(Y)\bigr]=\int \frac{q(y)}{p(y)}g(y)\,p(y)\,\mathrm{d}y=\int g\,q=\theta ,

so each summand is unbiased and so is the average. The summands are independent with common variance Ep[(wg)2]−θ2=∫g2q2/p−θ2\mathrm{E}_p[(wg)^{2}]-\theta^{2}=\int g^{2}q^{2}/p-\theta^{2}, and dividing by nn gives the stated variance; the strong law gives almost sure convergence. For the optimal density, apply the Cauchy–Schwarz inequality in the form

(∫∣g∣q)2=(∫∣g∣qp⋅p )2≤∫g2q2p⋅∫p=∫g2q2p,\left(\int \lvert g\rvert q\right)^{2}=\left(\int \frac{\lvert g\rvert q}{\sqrt p}\cdot\sqrt p\,\right)^{2}\le \int\frac{g^{2}q^{2}}{p}\cdot\int p=\int\frac{g^{2}q^{2}}{p} ,

using ∫p=1\int p=1. So ∫g2q2/p\int g^{2}q^{2}/p is at least (∫∣g∣q)2(\int\lvert g\rvert q)^{2} for every pp that is positive wherever gq≠0gq\neq0 (read g2q2/pg^{2}q^{2}/p as 00 on the set where gqgq and pp both vanish, which is what the estimator does), and equality holds exactly when ∣g∣q/p\lvert g\rvert q/\sqrt p is a constant multiple of p\sqrt p, that is when p∝∣g∣qp\propto\lvert g\rvert q. Substituting p=p∗p=p^{\ast} gives the variance (∫∣g∣q)2−θ2(\int\lvert g\rvert q)^{2}-\theta^{2}, which vanishes when ∣∫gq∣=∫∣g∣q\lvert\int gq\rvert=\int\lvert g\rvert q, that is when gg has one sign.

4. Detailed balance forces the acceptance rule. For i≠ji\ne j the requirement πipij=πjpji\pi_ip_{ij}=\pi_jp_{ji} reads

πihijaij=πjhjiaji,that isaijaji=πjhjiπihij=:Rij,\pi_i h_{ij}a_{ij}=\pi_j h_{ji}a_{ji}, \qquad\text{that is}\qquad \frac{a_{ij}}{a_{ji}}=\frac{\pi_j h_{ji}}{\pi_i h_{ij}}=:R_{ij} ,

with Rji=1/RijR_{ji}=1/R_{ij}. Any pair (aij,aji)(a_{ij},a_{ji}) in [0,1]2[0,1]^{2} with that ratio will do; taking the larger of the two equal to 11 gives the largest admissible pair, namely aij=min⁡{1,Rij}a_{ij}=\min\{1,R_{ij}\} and aji=min⁡{1,1/Rij}a_{ji}=\min\{1,1/R_{ij}\} — exactly the Hastings formula, which is therefore the choice that rejects as rarely as possible. The diagonal entries satisfy detailed balance trivially. Since detailed balance implies stationarity (sum πipij=πjpji\pi_ip_{ij}=\pi_jp_{ji} over ii and use ∑ipji=1\sum_ip_{ji}=1), π\pi is stationary and the chain is reversible; both statements, and the convergence of the nn-step probabilities and the geometric rate ∣λ2∣\lvert\lambda_2\rvert, are proved in Convergence of Markov chains. The almost sure convergence of the time average is the ergodic theorem for an irreducible positive-recurrent chain; it holds for every starting state, so the burn-in MM affects the finite-nn bias but not the limit.

The autocorrelation formula. In equilibrium {g(Xr)}\{g(X_r)\} is stationary (Stationary processes and spectral densities), so Cov⁡(g(Xr),g(Xs))=γ∣r−s∣\operatorname{Cov}(g(X_r),g(X_s))=\gamma_{\lvert r-s\rvert} and

Var⁡[1n∑r=0n−1g(Xr)]=1n2∑r,s=0n−1γ∣r−s∣=1n(γ0+2∑k=1n−1(1−kn)γk),\operatorname{Var}\Bigl[\frac1n\sum_{r=0}^{n-1}g(X_r)\Bigr] =\frac{1}{n^{2}}\sum_{r,s=0}^{n-1}\gamma_{\lvert r-s\rvert} =\frac{1}{n}\left(\gamma_0+2\sum_{k=1}^{n-1}\Bigl(1-\frac kn\Bigr)\gamma_k\right) ,

counting the n−kn-k pairs at lag kk for each k≥1k\ge1. If ∑k∣γk∣<∞\sum_k\lvert\gamma_k\rvert<\infty, which geometric mixing guarantees, dominated convergence lets n→∞n\to\infty inside and the bracket tends to γ0+2∑k≥1γk=γ0τ\gamma_0+2\sum_{k\ge1}\gamma_k=\gamma_0\tau. □\square

Remark(Where the hypotheses are used, and the traps)Original

Finite variance is the hypothesis that matters. The strong law needs only E∣f∣<∞\mathrm{E}\lvert f\rvert<\infty, so the estimator converges; but if σ2=∞\sigma^{2}=\infty the error bar is meaningless, the central limit theorem does not apply, and the sample standard deviation sns_n wanders without settling — while the running mean, deceptively, still looks as though it is converging. This is the characteristic failure of an importance density with tails lighter than ∣g∣q\lvert g\rvert q: then wgw g has heavy tails, ∫g2q2/p\int g^{2}q^{2}/p diverges, and the estimator is worse than the crude one it was meant to improve, yet it reports a small error bar until a rare large ww arrives. The safe habit is to choose pp with tails at least as heavy as qq and to monitor max⁡iw(Yi)/∑iw(Yi)\max_i w(Y_i)/\sum_i w(Y_i).

Unbiasedness is not automatic for a ratio. When qq is known only up to a constant, one uses the self-normalised estimator ∑iwig(Yi)/∑iwi\sum_i w_ig(Y_i)/\sum_i w_i. It is consistent but biased at order 1/n1/n; the bias is harmless beside the n−1/2n^{-1/2} noise, but it means two such estimates may not be averaged naively.

Hit-or-miss is always worse than crude. With 0≤f≤10\le f\le1, the hit-or-miss indicator has variance θ(1−θ)=E[f]−θ2 ≥ E[f2]−θ2=σ2\theta(1-\theta)=\mathrm{E}[f]-\theta^{2}\ \ge\ \mathrm{E}[f^{2}]-\theta^{2}=\sigma^{2}, since f2≤ff^{2}\le f on [0,1][0,1]. It also spends two random numbers per sample instead of one. Its merits are elsewhere: it needs no bound on ff beyond the box, and it generalises immediately to a region of complicated shape, which is Riley, Hobson and Bence's octahedron example.

The crossover in part 2 is asymptotic and the constants matter. At d=10d=10 with a smooth integrand, a sparse grid or a quasi-random (low-discrepancy) sequence will usually beat plain Monte Carlo in practice — but not for the reason the rates suggest, and the rate bound must not be offered as the explanation. The Koksma–Hlawka bound for a low-discrepancy sequence is O(n−1(log⁡n)d)O\bigl(n^{-1}(\log n)^{d}\bigr), and at d=10d=10 that bound is worse than n−1/2n^{-1/2} throughout every range anyone computes in. Comparing the two, (log⁡n)dn−1/2(\log n)^{d}n^{-1/2} equals 11 when dlog⁡log⁡n=12log⁡nd\log\log n=\tfrac12\log n; at d=10d=10 this gives log⁡n=89.995\log n=89.995, that is n=1.2×1039n=1.2\times10^{39}, and below that the quasi-random bound is the larger one — by a factor 4.4×1074.4\times10^{7} at n=104n=10^{4}, worst of all (4.6×1084.6\times10^{8}) near n=e2d=4.9×108n=\mathrm{e}^{2d}=4.9\times10^{8}, and still 1.11.1 at n=1039n=10^{39}. What actually wins is that the bound is grossly pessimistic for an integrand of low effective dimension, where the observed error behaves like n−1n^{-1} with no power of log⁡n\log n in evidence. The rate bound therefore settles the question in neither direction at d=10d=10. The honest statement of the case for Monte Carlo is not the rate alone but the rate together with the fact that the method needs nothing from the integrand — no smoothness, no product structure, no description of the domain beyond the ability to test membership.

Burn-in and ergodicity are different questions. Part 4 says the time average converges for any MM, including M=0M=0: discarding a burn-in is about reducing bias at finite nn, not about correctness. The hard practical question is τ\tau, not MM, and Grimmett and Stirzaker are explicit that deciding when a chain is near equilibrium is notoriously difficult. What makes τ\tau large is a chain that moves slowly through the state space; the acceptance rule is the usual culprit, since a proposal that is too bold is almost always rejected and a proposal that is too timid moves nowhere.

Detailed balance is sufficient, not necessary. Part 4 builds a reversible chain because reversibility makes the construction easy and the spectral bound explicit. A chain can have π\pi stationary without being reversible, and such chains are deliberately used to reduce τ\tau.

Method(Running a Monte Carlo calculation)Original
  1. Write the target as an expectation. Identify θ=Ep[h(Y)]\theta=\mathrm{E}_p[h(Y)] for some density pp you can sample and some hh you can evaluate. For ∫Dg\int_D g over a complicated DD inside a box BB, take pp uniform on BB and h=∣B∣ g 1Dh=\lvert B\rvert\,g\,\mathbf{1}_D.
  2. Generate the uniforms. Riley, Hobson and Bence (Riley, Hobson & Bence (2006), §27.4.4, p. 1017) give the linear congruential recipe xi=axi−1+c(modm)x_i=ax_{i-1}+c \pmod m with ξi=xi/m\xi_i=x_i/m, where cc is odd and a=4k+1a=4k+1, which runs through all mm values before repeating; they take mm a large power of two. Any modern library generator is better, but fix and record the seed: a Monte Carlo result that cannot be reproduced cannot be debugged.
  3. Transform to the distribution you want. If FF is the distribution function of the target and F−1F^{-1} is available, Y=F−1(ξ)Y=F^{-1}(\xi) has distribution FF, because Pr⁡(F−1(ξ)≤y)=Pr⁡(ξ≤F(y))=F(y)\Pr(F^{-1}(\xi)\le y)=\Pr(\xi\le F(y))=F(y); this is the inverse-transform rule of Riley, Hobson and Bence (Riley, Hobson & Bence (2006), §27.4.4, p. 1017), who also give the look-up table for a discrete or tabulated FF. When F−1F^{-1} has no closed form, use rejection, a look-up table, or a special-purpose transformation.
  4. Run and accumulate. Keep running sums of hh and h2h^{2}; never store the samples. After nn draws report θ^n±1.96 snn,sn2=nn−1(1n∑hi2−θ^n2).\hat\theta_n\pm 1.96\,\frac{s_n}{\sqrt n}, \qquad s_n^{2}=\frac{n}{n-1}\left(\frac{1}{n}\sum h_i^{2}-\hat\theta_n^{2}\right) .
  5. Decide how many samples. Inverting the error formula, a target root-mean-square error ϵ\epsilon needs n=σ2/ϵ2n=\sigma^{2}/\epsilon^{2}. Estimate σ\sigma from a short pilot run. Halving the error costs four times the work; one more decimal digit costs a hundred times.
  6. Reduce the variance before increasing nn. Factor out what you can integrate: if g≈g~g\approx \tilde g with ∫g~\int\tilde g known, estimate ∫(g−g~)\int(g-\tilde g) instead (a control variate). Or sample from p∝g~p\propto\tilde g (importance sampling). Either way the figure of merit is variance ×\times cost per sample, since doubling the cost per sample to halve the variance is a wash.
  7. If you cannot sample the target, build a chain. Choose a symmetric proposal HH, use aij=min⁡{1,πj/πi}a_{ij}=\min\{1,\pi_j/\pi_i\}, and tune the proposal so that a sensible fraction of moves is accepted. Discard a burn-in, then estimate τ\tau from the empirical autocorrelations and quote the error as γ0τ/n\sqrt{\gamma_0\tau/n}, not γ0/n\sqrt{\gamma_0/n} — the second is the commonest way to publish an error bar that is too small by a factor of several.
Example(An error function, an importance density, and a three-state Metropolis chain)Original

(a) Crude Monte Carlo and its exact variance. Estimate

θ=∫01e−x2 dx=π2erf⁡(1)=0.746824132812\theta=\int_0^1 \mathrm{e}^{-x^{2}}\,\mathrm{d}x=\frac{\sqrt\pi}{2}\operatorname{erf}(1)=0.746824132812

(Error function and incomplete Gamma function). The crude estimator is θ^n=n−1∑e−ξi2\hat\theta_n=n^{-1}\sum \mathrm{e}^{-\xi_i^{2}}. Its variance constant is exactly computable: writing J(a)=∫01e−at2dtJ(a)=\int_0^1\mathrm{e}^{-at^{2}}\mathrm{d}t,

σ2=J(2)−J(1)2=0.598144006661−0.557746285351=0.040397721310,σ=0.200991844.\sigma^{2}=J(2)-J(1)^{2}=0.598144006661-0.557746285351=0.040397721310, \qquad \sigma=0.200991844 .

So an accuracy of 10−310^{-3} needs n=σ2/10−6=40398n=\sigma^{2}/10^{-6}=40398 samples.

(b) An importance density, chosen and used. The integrand falls from 11 to e−1=0.3679\mathrm{e}^{-1}=0.3679, so sample more near 00. Take the linear density

p(y)=23(2−y)  on [0,1],P(y)=∫0yp=4y−y23,p(y)=\tfrac23(2-y)\ \text{ on }[0,1], \qquad P(y)=\int_0^y p=\frac{4y-y^{2}}{3} ,

which is positive throughout [0,1][0,1] — so the ratio w=1/pw=1/p is bounded — and invertible in closed form: solving P(y)=ξP(y)=\xi, that is y2−4y+3ξ=0y^{2}-4y+3\xi=0, and taking the root in [0,1][0,1] gives

y=2−4−3ξ.y=2-\sqrt{4-3\xi} .

The weight is w(y)g(y)=e−y2/[23(2−y)]=3 e−y22(2−y)w(y)g(y)=\mathrm{e}^{-y^{2}}\big/\bigl[\tfrac23(2-y)\bigr]=\dfrac{3\,\mathrm{e}^{-y^{2}}}{2(2-y)}, and by part 3 its variance is

σIS2=∫01e−2y2p(y) dy−θ2=0.562409079663−0.557746285351=0.004662794312,σIS=0.068284656.\sigma^{2}_{\mathrm{IS}}=\int_0^1\frac{\mathrm{e}^{-2y^{2}}}{p(y)}\,\mathrm{d}y-\theta^{2} =0.562409079663-0.557746285351=0.004662794312, \qquad \sigma_{\mathrm{IS}}=0.068284656 .

The variance has dropped by the factor 0.040397721/0.004662794=8.6640.040397721/0.004662794=8.664: the same accuracy now needs n=4663n=4663 samples instead of 4039840398. (The weight ranges only over [0.5518, 0.8064][0.5518,\,0.8064] on [0,1][0,1]: its smallest value there is wg(1)=0.551819wg(1)=0.551819 and its largest is wg(1−1/2)=0.806444wg(1-1/\sqrt2)=0.806444, at the stationary point y=1−1/2=0.292893y=1-1/\sqrt2=0.292893 of log⁡wg\log wg. That near-constancy is the reason for the gain, since part 3 says the variance measures how far wgwg is from constant.)

(c) The two estimators on the same ten numbers. Generate ξi\xi_i with the congruential recipe of step 2, taking m=231m=2^{31}, a=1103515245a=1103515245, c=12345c=12345 and x0=1x_0=1:

ξ=(0.5138701, 0.1757413, 0.3086515, 0.5345339, 0.9476279, 0.1717363, 0.7022312, 0.2264307, 0.4947734, 0.1247203).\xi=(0.5138701,\ 0.1757413,\ 0.3086515,\ 0.5345339,\ 0.9476279,\ 0.1717363,\ 0.7022312,\ 0.2264307,\ 0.4947734,\ 0.1247203).

Crude: averaging e−ξi2\mathrm{e}^{-\xi_i^{2}} gives θ^10=0.8104593\hat\theta_{10}=0.8104593, an error of +0.063635+0.063635. The predicted standard deviation is σ/10=0.0635592\sigma/\sqrt{10}=0.0635592 — the error landed at 1.0011.001 standard deviations.

Importance sampling, on the same ten uniforms: yi=2−4−3ξiy_i=2-\sqrt{4-3\xi_i} gives

y=(0.4320747, 0.1364614, 0.2467044, 0.4519695, 0.9243066, 0.1332405, 0.6240253, 0.1777190, 0.4139106, 0.0958364),y=(0.4320747,\ 0.1364614,\ 0.2467044,\ 0.4519695,\ 0.9243066,\ 0.1332405,\ 0.6240253,\ 0.1777190,\ 0.4139106,\ 0.0958364),

and averaging 3e−yi2/[2(2−yi)]3\mathrm{e}^{-y_i^{2}}/[2(2-y_i)] gives θ^10 IS=0.7675041\hat\theta^{\,\mathrm{IS}}_{10}=0.7675041, an error of +0.020680+0.020680 against a predicted standard deviation σIS/10=0.0215935\sigma_{\mathrm{IS}}/\sqrt{10}=0.0215935 — 0.9580.958 standard deviations. Ten samples is far too few to demonstrate anything statistically, and that is the point of quoting the predicted deviations: the two errors are where they should be, and the two predicted deviations differ by the factor 8.664=2.94\sqrt{8.664}=2.94 that part 3 forecast.

(d) A Metropolis chain small enough to do exactly. Take Θ={1,2,3}\Theta=\{1,2,3\} with target π∝(1,2,3)\pi\propto(1,2,3), so π=(16,13,12)\pi=(\tfrac16,\tfrac13,\tfrac12), and the symmetric proposal "pick one of the other two states at random", hij=12h_{ij}=\tfrac12 for i≠ji\ne j. The Metropolis rule aij=min⁡{1,πj/πi}a_{ij}=\min\{1,\pi_j/\pi_i\} gives, for instance, a12=min⁡{1,2}=1a_{12}=\min\{1,2\}=1 and a21=min⁡{1,12}=12a_{21}=\min\{1,\tfrac12\}=\tfrac12, hence p12=12p_{12}=\tfrac12 and p21=14p_{21}=\tfrac14. Carrying this out for every pair:

P=(01212141412161312).P=\begin{pmatrix} 0 & \tfrac12 & \tfrac12\\[2pt] \tfrac14 & \tfrac14 & \tfrac12\\[2pt] \tfrac16 & \tfrac13 & \tfrac12 \end{pmatrix} .

Checks. Rows sum to 11. Detailed balance: π1p12=16⋅12=112\pi_1p_{12}=\tfrac16\cdot\tfrac12=\tfrac1{12} and π2p21=13⋅14=112\pi_2p_{21}=\tfrac13\cdot\tfrac14=\tfrac1{12}; π1p13=112=12⋅16=π3p31\pi_1p_{13}=\tfrac1{12}=\tfrac12\cdot\tfrac16=\pi_3p_{31}; π2p23=13⋅12=16=12⋅13=π3p32\pi_2p_{23}=\tfrac13\cdot\tfrac12=\tfrac16=\tfrac12\cdot\tfrac13=\pi_3p_{32}. So πP=π\pi P=\pi, as part 4 promises.

Rate. The characteristic polynomial of PP factorises as λ(λ−1)(λ+14)\lambda(\lambda-1)(\lambda+\tfrac14), so the spectrum is {1,−14,0}\{1,-\tfrac14,0\} and the second largest eigenvalue modulus is ∣λ2∣=14\lvert\lambda_2\rvert=\tfrac14. Starting from state 11, the exact nn-step row is

p1⋅(n)=(16+23(−14)n,  13−23(−14)n,  12),n≥1p_{1\cdot}(n)=\Bigl(\tfrac16+\tfrac{2}{3}\bigl(-\tfrac14\bigr)^{n},\ \ \tfrac13-\tfrac{2}{3}\bigl(-\tfrac14\bigr)^{n},\ \ \tfrac12\Bigr),\qquad n\ge1

— the third component is exactly right after a single step, because the third column of PP is constant. Hence, in the normalisation of Convergence of Markov chains,

dTV(p1⋅(n),π)=43 4−n=13, 112, 148, 1192,…  for n=1,2,3,4.d_{\mathrm{TV}}\bigl(p_{1\cdot}(n),\pi\bigr)=\tfrac43\,4^{-n} = \tfrac13,\ \tfrac1{12},\ \tfrac1{48},\ \tfrac1{192},\dots\ \text{ for } n=1,2,3,4 .

The reversible spectral bound of that unit gives, with N=3N=3, ∣λ2∣=14\lvert\lambda_2\rvert=\tfrac14 and the π\pi-orthonormal right eigenvectors v1=(1,1,1)v_1=(1,1,1), v2=(−2,1,0)v_2=(-2,1,0), v3=(1,1,−1)v_3=(1,1,-1) (each already of unit norm for ⟨x,y⟩=∑πixiyi\langle x,y\rangle=\sum\pi_ix_iy_i), sup⁡r∣vr(1)∣=2\sup_r\lvert v_r(1)\rvert=2 and so dTV≤6⋅4−nd_{\mathrm{TV}}\le 6\cdot4^{-n}. True value 434−n\tfrac43 4^{-n}: the bound has the rate exactly right and the prefactor too large by 4.54.5.

Efficiency. Estimate θ=Eπ[g]\theta=\mathrm{E}_\pi[g] with g(i)=ig(i)=i, so θ=16+23+32=73\theta=\tfrac16+\tfrac23+\tfrac32=\tfrac73. Then γ0=Var⁡πg=6−499=59\gamma_0=\operatorname{Var}_\pi g=6-\tfrac{49}{9}=\tfrac59, and expanding gg in the eigenbasis gives γk=19(−14)k\gamma_k=\tfrac19(-\tfrac14)^{k} for k≥1k\ge1 (the λ=0\lambda=0 mode contributes only at k=0k=0). Hence

τ=1+2∑k≥1γkγ0=1+2⋅95⋅19⋅−141+14=1−225=2325=0.92,\tau=1+2\sum_{k\ge1}\frac{\gamma_k}{\gamma_0} =1+2\cdot\frac95\cdot\frac19\cdot\frac{-\tfrac14}{1+\tfrac14} =1-\frac{2}{25}=\frac{23}{25}=0.92 ,

so the predicted variance of the time average is γ0τ/n=2345n=0.511111/n\gamma_0\tau/n=\tfrac{23}{45n}=0.511111/n. Computing the variance exactly from the finite-nn formula of the proof gives 0.05146670.0514667 at n=10n=10 and 0.005114670.00511467 at n=100n=100, against the predictions 0.05111110.0511111 and 0.005111110.00511111. Note τ<1\tau<1: successive states are negatively correlated, because a Metropolis move from state 11 never stays put, so this chain is very slightly more efficient than independent sampling. That is unusual, and it happens here only because the chain mixes in essentially one step.

Application(Where the method earns its keep)Original

Statistical mechanics. The canonical average ⟨A⟩=Z−1∑ϑA(ϑ)e−βE(ϑ)\langle A\rangle=Z^{-1}\sum_{\vartheta}A(\vartheta)\mathrm{e}^{-\beta E(\vartheta)} over the 2Ld2^{L^{d}} configurations of a lattice model cannot be enumerated or sampled directly, and ZZ is not known. The Metropolis rule needs neither: a single spin flip changes the energy by a local amount ΔE\Delta E and is accepted with probability min⁡{1,e−βΔE}\min\{1,\mathrm{e}^{-\beta\Delta E}\}. This is the original application — the algorithm was published for exactly this problem in the early 1950s — and it remains the standard tool for lattice gauge theory, for polymer and protein conformations, and for phase diagrams. Near a critical point τ\tau diverges with system size, which is the critical slowing down discussed in Convergence of Markov chains.

Particle transport and radiation. Neutron transport, radiotherapy dose planning and detector response are all high-dimensional integrals over particle histories, with geometry too complicated for a mesh. Each simulated history is one sample, variance reduction is done by splitting and Russian roulette in the regions that matter, and the reported dose carries a statistical error bar computed exactly as in step 4. Grimmett and Stirzaker record that the name and the method date from the Los Alamos work of Metropolis, von Neumann and Ulam in the 1940s, where this was the problem.

Financial valuation. The price of a path-dependent option is an expectation under a risk-neutral measure over paths of the stochastic differential equation of Stochastic differential equations; the dimension is the number of time steps, often hundreds, so no quadrature rule is possible. Importance sampling is used in precisely the form of part 3 to price deep out-of-the-money options, where the payoff is non-zero on an event of probability 10−410^{-4}, so that 10810^{8} crude paths would produce only 10410^{4} non-zero ones and the other 99.99%99.99\% of the work would be wasted.

Bayesian inference. The posterior π(ϑ∣x)∝f(x∣ϑ)π(ϑ)\pi(\vartheta\mid x)\propto f(x\mid\vartheta)\pi(\vartheta) is known up to its normalising constant by construction, which is the situation part 4 was built for; Markov chain Monte Carlo is what made Bayesian analysis of large structured models practical, and Grimmett and Stirzaker open their treatment with this example. The quantity a practitioner must report alongside a posterior mean is the effective sample size n/τn/\tau, which is the content of part 4's variance formula.

And where it does not. For a smooth one-dimensional integral, Monte Carlo is absurd: Gauss–Legendre quadrature (Numerical quadrature) gets twenty digits from twenty points, while Monte Carlo would need some 103910^{39} samples (step 5 with ϵ=7.5×10−21\epsilon=7.5\times10^{-21} gives n=σ2/ϵ2=7.2×1038n=\sigma^{2}/\epsilon^{2}=7.2\times10^{38}). The method is for problems whose dimension or whose geometry defeats a grid, and for nothing else.