Numerical Methods

All books

M06 — Elliptic, parabolic, hyperbolic

A second-order equation carries its class in three coefficients, and the class decides what a solver must respect: an equilibrium that is settled everywhere at once, a diffusion that forgets its start, or a wave that arrives at a finite speed. Each class brings its own failure: a time step tied to Δx2\Delta x^2, a time step tied to Δx\Delta x, or an iteration count that grows with the mesh.

Book pages: Reading the class off the equation, Elliptic, Parabolic (and Why the time step is tied to the square of the mesh), Hyperbolic (and The condition a wave equation imposes) in books/numerical-methods.

The question. Why does an explicit heat solver need Δt∝Δx2\Delta t \propto \Delta x^2, an explicit wave solver only Δt∝Δx\Delta t \propto \Delta x, and a steady (elliptic) solve no time step at all, yet still slows down as the mesh is refined?

By the end you can:

  • classify a second-order equation from B2−4ACB^2 - 4AC, and say what each class means physically
  • derive the explicit heat limit r=αΔt/Δx2≤12r = \alpha\Delta t/\Delta x^2 \le \tfrac12 from the von Neumann growth factor, and recognise the blow-up
  • explain why an implicit step is stable for every rr, and what it still costs
  • measure a scheme's order with a convergence table, and say what it mixes
  • state the CFL condition c Δt/Δx≤1c\,\Delta t/\Delta x \le 1 as a domain-of-dependence argument
  • predict Jacobi's iteration count on Laplace's equation from its spectral radius

Assumes: M01 (convergence tables), M03 (linear systems), M05 (eigenvalues and spectral radius), and Taylor series.

How to use it: predict before you reveal, commit before you check, and move the controls until the equation's behaviour stops surprising you.

Predict first. Try first: the explicit heat scheme runs at r=0.55r = 0.55, just above the textbook limit of 12\tfrac12, from a smooth triangle on 21 nodes. After 60 steps the largest ∣u∣|u| is

Choose a prediction

Check answer (without scripting)

Answer: over 100, as a sawtooth that keeps growing. The grid-scale mode has growth factor 1−4r≈−1.21 - 4r \approx -1.2 per step. It starts small in a triangle, but sixty multiplications by 1.2 are enough.

Warm-up: from earlier notebooks (closed book)

1. Power iteration on a symmetric matrix with ∣λ2/λ1∣=0.9|\lambda_2/\lambda_1| = 0.9. Per step, the error in the vector is multiplied by about

Question 1
How sure?

2. Gradient descent with a fixed step tt on a quadratic whose Hessian has eigenvalues 2 and 50. Which steps converge?

Question 2
How sure?

3. Bisection starts from a bracket of width 1. About how many halvings shrink it to 10−610^{-6}?

Question 3
How sure?

Show answers and explanations

1. 0.9. Akv0=λ1k(c1u1+∑i>1ci(λi/λ1)kui)A^k v_0 = \lambda_1^k(c_1 u_1 + \sum_{i>1} c_i (\lambda_i/\lambda_1)^k u_i): the slowest wrong component shrinks by ∣λ2/λ1∣|\lambda_2/\lambda_1| each step.

2. 0 < t < 0.04, two over the largest eigenvalue. Each mode is multiplied by 1−tλi1 - t\lambda_i; all shrink only if ∣1−tλi∣<1|1 - t\lambda_i| \lt 1 for every ii, so t<2/50t \lt 2/50.

3. 20. The width after kk halvings is 2−k2^{-k}, and 220≈1.05×1062^{20} \approx 1.05 \times 10^6: k=⌈log⁡2106⌉=20k = \lceil \log_2 10^6 \rceil = 20.

1. Reading the class

Setting: the problem, its sets and its symbols

Problem. Given an open Ω⊆R2\Omega \subseteq \mathbb{R}^2 and coefficients A,B,C:Ω→RA, B, C : \Omega \to \mathbb{R}, not all zero, of a linear equation Auxx+Buxy+Cuyy+(lower-order terms)=0Au_{xx} + Bu_{xy} + Cu_{yy} + (\text{lower-order terms}) = 0 for u∈C2(Ω)u \in C^2(\Omega), find at each point its class and its characteristic slopes m∈Rm \in \mathbb{R}, the real roots of Am2−Bm+C=0Am^2 - Bm + C = 0.

Symbol In Meaning
x, yx,\ y Ω⊆R2\Omega \subseteq \mathbb{R}^2 the independent variables; yy is tt for heat and wave
uu C2(Ω)C^2(\Omega) the unknown
A, B, CA,\ B,\ C Ω→R\Omega \to \mathbb{R} the coefficients of uxxu_{xx}, uxyu_{xy}, uyyu_{yy}; constants on the sliders
mm R\mathbb{R} a characteristic slope dy/dx\mathrm{d}y/\mathrm{d}x
Δ\Delta Ω→R\Omega \to \mathbb{R} the discriminant B2−4ACB^2 - 4AC
p, qp,\ q R\mathbb{R} exponents of the trial u=epx+qyu = e^{px + qy} in the sympy classifier
How these symbols connect

On an open region Ω⊆R2\Omega \subseteq \mathbb{R}^2, the second-order coefficients A,B,C:Ω→RA, B, C : \Omega \to \mathbb{R} of Auxx+Buxy+Cuyy+(lower-order terms)=0Au_{xx} + Bu_{xy} + Cu_{yy} + (\text{lower-order terms}) = 0 define, at each point (x,y)(x, y), the quadratic Am2−Bm+C=0Am^2 - Bm + C = 0 for characteristic slopes m=dy/dxm = \mathrm{d}y/\mathrm{d}x. Its discriminant Δ(x,y)=B2−4AC\Delta(x, y) = B^2 - 4AC counts the real roots — two, one, or none — and assigns the equation's class at that point, independent of lower-order terms. Substituting the exponential trial u=epx+qyu = e^{px + qy} reads off A,B,CA, B, C automatically as the coefficients of p2,pq,q2p^2, pq, q^2.

Symbol-by-symbol notes
$x,\ y$ — space–space or space–time

Both independent variables live in Ω⊆R2\Omega \subseteq \mathbb{R}^2 and enter the same classification algebra, whether (x,y)(x, y) are two spatial coordinates (Laplace) or space and time (x,t)(x, t) (heat and wave).

$A,\ B,\ C$ — pointwise functions, all on one side

In general A,B,CA, B, C can vary with (x,y)(x, y) so the class can change across Ω\Omega, although the sliders fix constant values. Move every second-order term to the same side of the equals sign before reading A,B,CA, B, C, or a sign slip in AA or CC flips the sign of −4AC-4AC.

$m$ and $\Delta$ — characteristic slopes and discriminant

A characteristic slope m=dy/dxm = \mathrm{d}y/\mathrm{d}x solves Am2−Bm+C=0Am^2 - Bm + C = 0 (vertical characteristics occur when A=0A = 0). The sign of Δ=B2−4AC\Delta = B^2 - 4AC counts the real slopes at (x,y)(x, y): positive gives two (hyperbolic), zero gives one (parabolic), and negative gives none (elliptic).

$p,\ q$ — symbolic probe exponents

Used only inside the SymPy helper classify: differentiating u=epx+qyu = e^{px + qy} pulls down pp for each ∂x\partial_x and qq for each ∂y\partial_y. Dividing out epx+qye^{px + qy} leaves a polynomial whose degree-2 coefficients are A,B,CA, B, C.

Move every term to the left of a linear second-order equation in two variables:

A uxx+B uxy+C uyy+(lower-order terms)=0.A\,u_{xx} + B\,u_{xy} + C\,u_{yy} + (\text{lower-order terms}) = 0.

A characteristic is a direction along which the equation does not fix the second derivative across it, so a disturbance can travel there. Its slope m=dy/dxm = \mathrm{d}y/\mathrm{d}x solves Am2−Bm+C=0A m^2 - B m + C = 0, a quadratic, so the number of real directions is decided by its discriminant

Δ=B2−4AC:Δ>0 hyperbolic (two),Δ=0 parabolic (one),Δ<0 elliptic (none).\Delta = B^2 - 4AC: \qquad \Delta > 0 \text{ hyperbolic (two)}, \quad \Delta = 0 \text{ parabolic (one)}, \quad \Delta \lt 0 \text{ elliptic (none)}.

Physically: two directions means signals travel both ways at a finite speed (waves); one means the answer marches forward and smooths (diffusion); none means nothing travels, and every point feels every boundary at once (equilibrium). Start at Laplace (A=C=1A = C = 1, B=0B = 0) and find the BB at which a direction first appears.

Figure 1
quantity value
Δ=B2−4AC\Delta = B^2 - 4AC -4
class elliptic
real slopes dy/dx\mathrm{d}y/\mathrm{d}x none
-1-0.500.51-1.12-0.5600.561.12xy

Let the computer read the coefficients. Substitute u=epx+qyu = e^{px + qy}: each second derivative returns a factor p2p^2, pqpq or q2q^2, so AA, BB, CC are the coefficients of those monomials, and lower-order terms land at lower degree and are ignored. The sympy helper above does exactly that.

equation =0= 0 Δ\Delta class
Laplace: uxx+uyyu_{xx} + u_{yy} −4-4 elliptic
Heat: uxx−utu_{xx} - u_t 00 parabolic
Wave: utt−uxxu_{tt} - u_{xx} 44 hyperbolic
Cross: uxx+4uxy+3uyyu_{xx} + 4u_{xy} + 3u_{yy} 44 hyperbolic
Mixed: uyy−x uxxu_{yy} - x\,u_{xx} 4x4 x depends on position

The last row has Δ=4x\Delta = 4x: hyperbolic for x>0x > 0, parabolic on x=0x = 0, elliptic for x<0x \lt 0. The class is a property of a point, not of an equation.

When the discriminant test breaks
  • Assumes: a linear second-order equation in two variables, read at one point
  • When it fails: with variable coefficients the class can change across the region (uyy−x uxxu_{yy} - x\,u_{xx} has Δ=4x\Delta = 4x); with three or more variables a single discriminant no longer exists
  • Check: evaluate B2−4ACB^2 - 4AC over the whole region, or the signs of the coefficient matrix's eigenvalues in more variables

2. Parabolic: the explicit heat scheme and its limit

Setting: the problem, its sets and its symbols

Problem. Given a diffusivity α>0\alpha > 0, a start u0:[0,1]→Ru_0 : [0, 1] \to \mathbb{R} with u0(0)=u0(1)=0u_0(0) = u_0(1) = 0 and a horizon T>0T > 0, find u:[0,1]×[0,T]→Ru : [0, 1] \times [0, T] \to \mathbb{R} with ut=αuxxu_t = \alpha u_{xx}, u(x,0)=u0(x)u(x, 0) = u_0(x) and u(0,t)=u(1,t)=0u(0, t) = u(1, t) = 0, approximated by FTCS on a grid; and find the mesh ratios rr for which the grid values stay bounded as n→∞n \to \infty.

Symbol In Meaning
uu [0,1]×[0,T]→R[0, 1] \times [0, T] \to \mathbb{R} the temperature, the unknown; dimensionless here
α\alpha R>0\mathbb{R}_{>0} diffusivity, m2^2/s; α=1\alpha = 1 here
u0u_0 [0,1]→R[0, 1] \to \mathbb{R} the start: the triangle 1−∣2x−1∣1 - \lvert 2x - 1 \rvert
Δx, Δt\Delta x,\ \Delta t R>0\mathbb{R}_{>0} mesh spacing 1/N1/N with N=20N = 20 (21 nodes), and time step
xi, tnx_i,\ t_n [0,1], [0,T][0, 1],\ [0, T] nodes xi=iΔxx_i = i\Delta x, i=0,…,Ni = 0, \dots, N; times tn=nΔtt_n = n\Delta t, n∈Nn \in \mathbb{N}
uinu_i^n R\mathbb{R} the scheme's value at (xi,tn)(x_i, t_n), held at zero for i=0,Ni = 0, N
rr R>0\mathbb{R}_{>0} the mesh ratio αΔt/Δx2\alpha\Delta t/\Delta x^2, set by the slider
θ\theta [0,π][0, \pi] phase per cell of a Fourier mode uin=gneiθiu_i^n = g^n e^{\mathrm{i}\theta i}
gg [0,π]→R[0, \pi] \to \mathbb{R} the growth factor per step of the mode with phase θ\theta
How these symbols connect

Given diffusivity α>0\alpha > 0 (m2/s\text{m}^2/\text{s}) and initial profile u0u_0 on [0,1][0, 1] with zero endpoints, the continuous problem seeks the temperature u(x,t)u(x, t) solving ut=αuxxu_t = \alpha u_{xx} up to t=Tt = T. Discretising [0,1]×[0,T][0, 1] \times [0, T] onto nodes xi=iΔxx_i = i\Delta x and times tn=nΔtt_n = n\Delta t produces grid values uinu_i^n updated explicitly by FTCS, where α\alpha, Δx\Delta x and Δt\Delta t enter only through the dimensionless mesh ratio r=αΔt/Δx2r = \alpha\Delta t/\Delta x^2. Testing a single Fourier mode of cell phase θ∈[0,π]\theta \in [0, \pi] gives its per-step growth factor g(θ)g(\theta), which decides whether uinu_i^n remains bounded as nn grows.

Symbol-by-symbol notes
$u_i^n$ — superscript is time level, not a power

The subscript i∈{0,…,N}i \in \{0, \dots, N\} indexes space xi=iΔxx_i = i\Delta x and the superscript n∈Nn \in \mathbb{N} indexes time tn=nΔtt_n = n\Delta t (not an exponent). The endpoints u0n=uNn=0u_0^n = u_N^n = 0 stay fixed, so only the N−1N - 1 interior values are updated.

$r = \alpha\Delta t/\Delta x^2$ — dimensionless mesh ratio

With α\alpha in m2/s\text{m}^2/\text{s}, Δt\Delta t in s\text{s} and Δx\Delta x in m\text{m}, the units cancel so rr is dimensionless. Because Δx\Delta x is squared in the denominator, holding rr fixed ties Δt\Delta t quadratically to Δx\Delta x.

$\theta$ — phase per grid cell

A discrete spatial wave eiθie^{\mathrm{i}\theta i} advances in phase by θ\theta radians from node ii to node i+1i + 1. The interval [0,π][0, \pi] covers every grid-resolvable wavelength by symmetry, from a flat mode (θ=0\theta = 0) to the shortest node-to-node alternating mode (θ=π\theta = \pi, where eiπi=(−1)ie^{\mathrm{i}\pi i} = (-1)^i).

$g(\theta)$ — per-step amplification factor

Substituting uin=gneiθiu_i^n = g^n e^{\mathrm{i}\theta i} into the linear update multiplies each mode by g(θ)g(\theta) per step, so after nn steps its amplitude scales by ∣g(θ)∣n\lvert g(\theta)\rvert^n. A negative g(θ)g(\theta) flips the mode's sign every step, while ∣g(θ)∣>1\lvert g(\theta)\rvert > 1 drives geometric growth.

$u_0$ — the triangle initial profile

u0(x)=1−∣2x−1∣u_0(x) = 1 - \lvert 2x - 1\rvert rises linearly from 00 at x=0x = 0 to 11 at x=0.5x = 0.5 and returns to 00 at x=1x = 1. Its corner at the midpoint gives it a non-zero (though small) component in every high-θ\theta Fourier mode.

Take ut=αuxxu_t = \alpha u_{xx} on [0,1][0, 1] with u=0u = 0 at both ends. Forward in time, centred in space (FTCS):

uin+1−uinΔt=α ui+1n−2uin+ui−1nΔx2⟹uin+1=uin+r (ui+1n−2uin+ui−1n),r=α ΔtΔx2.\frac{u_i^{n+1} - u_i^n}{\Delta t} = \alpha\,\frac{u_{i+1}^n - 2u_i^n + u_{i-1}^n}{\Delta x^2} \quad\Longrightarrow\quad u_i^{n+1} = u_i^n + r\,(u_{i+1}^n - 2u_i^n + u_{i-1}^n), \qquad r = \frac{\alpha\,\Delta t}{\Delta x^2}.

The scheme sees Δt\Delta t and Δx\Delta x only through rr. Von Neumann: try one Fourier mode, uin=gneiθiu_i^n = g^n e^{\mathrm{i}\theta i}, with θ\theta the phase per cell. The bracket becomes eiθ−2+e−iθ=−4sin⁡2(θ/2)e^{\mathrm{i}\theta} - 2 + e^{-\mathrm{i}\theta} = -4\sin^2(\theta/2), so

g(θ)=1−4rsin⁡2(θ/2).g(\theta) = 1 - 4r\sin^2(\theta/2).

Stability needs ∣g∣≤1|g| \le 1 for every θ\theta. Smooth modes (θ→0\theta \to 0) have g→1g \to 1 and are safe. The grid-scale sawtooth (θ=π\theta = \pi, signs alternating node to node) has g=1−4rg = 1 - 4r, and 1−4r≥−11 - 4r \ge -1 gives r≤12r \le \tfrac12. With Δx=0.05\Delta x = 0.05 and α=1\alpha = 1 that is Δt≤0.00125\Delta t \le 0.00125. Halve Δx\Delta x and the step quarters: four times the steps, each over twice the nodes, so eight times the work to reach the same time.

The start is a triangle on 21 nodes. Physically it should only smooth and decay: a diffusing answer never exceeds its initial maximum.

Figure 2

What the explicit scheme does

Reveal result (lock in your prediction above first)
00.250.50.751-159-78.91.2781.4162startafter 60 stepsxu

At r=0.55r = 0.55: g(π)=1−4r=−1.20g(\pi) = 1 - 4r = -1.20; after 60 steps max⁡∣u∣=144\max|u| = 144. The growth curves below, at three values of rr, are straight lines on a log axis once the sawtooth dominates: geometric growth.

030609012010⁻¹10³10⁷10¹¹10¹⁵r = 0.5r = 0.55r = 0.6stepmax |u|

At r=0.55r = 0.55 step 60 reaches 144. The triangle's sawtooth component is only about 0.005 at the start (the kink is the only non-smooth part), which is why the growth takes a few dozen steps to show. Run it longer and even r=0.51r = 0.51 blows up: 17 after 300 steps.

source: solvers/ot-solve/src/kernels/heat.rs:100-113

The browser kernel's step is the same line: next = u + r(u[i-1] - 2u[i] + u[i+1]), ends held at zero. It reports Unstable once max|u| passes 10610^6.

    let mut field = [0.0f64; CAP];
    let norm = {
        let state = a.state_mut();
        let (u, rest) = state.split_at_mut(CAP);
        let next = &mut rest[..CAP];
        for index in 1..cells - 1 {
            next[index] = u[index] + r * (u[index - 1] - 2.0 * u[index] + u[index + 1]);
        }
        next[0] = 0.0;
        next[cells - 1] = 0.0;
        u[..cells].copy_from_slice(&next[..cells]);
        field[..cells].copy_from_slice(&next[..cells]);
        grid::max_abs(&next[..cells])
    };
When the explicit limit r ≤ 1/2 breaks
  • Assumes: constant α\alpha on a uniform mesh, so one rr describes every node
  • When it fails: a variable α\alpha or a stretched mesh has a local rr; the largest one decides, and a single hot spot over the limit grows a sawtooth there
  • Check: compute max⁡iαi Δt/Δxi2\max_i \alpha_i\,\Delta t/\Delta x_i^2, and watch max⁡∣u∣\max|u|: a diffusing answer never exceeds its initial maximum

3. Parabolic: an implicit step

Setting: the problem, its sets and its symbols

Problem. Given §2's heat problem and grid and any mesh ratio r>0r > 0, find un+1∈RN−1u^{n+1} \in \mathbb{R}^{N-1} with (I−rL) un+1=un(I - rL)\,u^{n+1} = u^n (backward Euler), and decide for which rr the step is stable and how accurate it is.

Symbol In Meaning
uu [0,1]×[0,T]→R[0, 1] \times [0, T] \to \mathbb{R} the solution of ut=αuxxu_t = \alpha u_{xx}, u=0u = 0 at x=0,1x = 0, 1; α=1\alpha = 1
NN N\mathbb{N} cells, N=20N = 20, so Δx=1/N\Delta x = 1/N
unu^n RN−1\mathbb{R}^{N-1} interior values (u1n,…,uN−1n)(u_1^n, \dots, u_{N-1}^n) at tn=nΔtt_n = n\Delta t
LL R(N−1)×(N−1)\mathbb{R}^{(N-1) \times (N-1)} the second difference: tridiagonal, −2-2 on the diagonal, 11 beside it
rr R>0\mathbb{R}_{>0} αΔt/Δx2\alpha\Delta t/\Delta x^2, set by the slider up to 10
θ\theta [0,π][0, \pi] phase per cell of a Fourier mode
gBE, gCNg_{\text{BE}},\ g_{\text{CN}} [0,π]→R[0, \pi] \to \mathbb{R} growth factors per step of backward Euler and Crank–Nicolson
How these symbols connect

On §2's grid of NN cells (Δx=1/N\Delta x = 1/N) and dimensionless mesh ratio r=αΔt/Δx2r = \alpha\Delta t/\Delta x^2, stacking the N−1N - 1 interior unknowns into a vector un∈RN−1u^n \in \mathbb{R}^{N-1} expresses the spatial second difference as the tridiagonal matrix LL. Backward Euler evaluates that difference at the new time level, replacing the explicit update with the linear system (I−rL) un+1=un(I - rL)\,u^{n+1} = u^n at every step. Substituting a Fourier mode of cell phase θ∈[0,π]\theta \in [0, \pi] defines the per-step growth factors gBE(θ)g_{\text{BE}}(\theta) and gCN(θ)g_{\text{CN}}(\theta) that govern stability and damping across all r>0r > 0.

Symbol-by-symbol notes
$u^n$ — interior-node vector in $\mathbb{R}^{N-1}$

Because u0n=uNn=0u_0^n = u_N^n = 0 are fixed by the boundary conditions, they are omitted from un=(u1n,…,uN−1n)Tu^n = (u_1^n, \dots, u_{N-1}^n)^{\mathsf T}. As in §2, the superscript nn marks time level tn=nΔtt_n = n\Delta t, not a power.

$L$ — discrete second-difference matrix

L∈R(N−1)×(N−1)L \in \mathbb{R}^{(N-1) \times (N-1)} has −2-2 on the main diagonal and 11 on the two adjacent diagonals, so (Lu)i=ui−1−2ui+ui+1(Lu)_i = u_{i-1} - 2u_i + u_{i+1} with u0=uN=0u_0 = u_N = 0 built in. The system matrix I−rLI - rL is symmetric and tridiagonal, so solving (I−rL) un+1=un(I - rL)\,u^{n+1} = u^n takes O(N)O(N) operations per step.

$g\lt em>{\text{BE}}$ vs $g\lt /em>{\text{CN}}$ — two implicit schemes

Both are per-step Fourier amplification factors over θ∈[0,π]\theta \in [0, \pi], analogous to g(θ)g(\theta) in §2. Backward Euler evaluates the space difference solely at tn+1t_{n+1}, while Crank–Nicolson averages the levels tnt_n and tn+1t_{n+1} equally.

$r$ — slider range past the explicit limit

r=αΔt/Δx2r = \alpha\Delta t/\Delta x^2 is the same dimensionless ratio as in §2, with the slider extended up to r=10r = 10 to probe implicit behaviour far beyond FTCS's stability boundary.

Evaluate the space difference at the new time level instead (backward Euler):

uin+1−r (ui+1n+1−2uin+1+ui−1n+1)=uin.u_i^{n+1} - r\,(u_{i+1}^{n+1} - 2u_i^{n+1} + u_{i-1}^{n+1}) = u_i^n .

Each step is now a tridiagonal linear system, (I−rL) un+1=un(I - rL)\,u^{n+1} = u^n (M03): O(N)O(N) operations by elimination, so not much dearer than an explicit step. Crank–Nicolson averages the explicit and implicit differences and is second order in time. Before substituting a Fourier mode, predict what the implicit step does past the explicit limit.

Predict first. Backward Euler at r=5r = 5, ten times the explicit limit, on the same triangle. After 20 steps the profile is

Choose a prediction

Check answer (without scripting)

Answer: smooth and decaying. Every mode is damped, the sawtooth most of all (g(π)=1/21g(\pi) = 1/21). The profile smooths at once and decays: stable, though not necessarily accurate.

Reveal result (lock in your prediction above first)
00.250.50.751-0.060.220.50.781.060 steps5 steps20 stepsxu

The same Fourier substitution as in §2 gives

gBE(θ)=11+4rsin⁡2(θ/2)∈(0,1]for every r>0,gCN(θ)=1−2rsin⁡2(θ/2)1+2rsin⁡2(θ/2).g_{\text{BE}}(\theta) = \frac{1}{1 + 4r\sin^2(\theta/2)} \in (0, 1] \quad\text{for every } r > 0, \qquad g_{\text{CN}}(\theta) = \frac{1 - 2r\sin^2(\theta/2)}{1 + 2r\sin^2(\theta/2)}.

Both satisfy ∣g∣≤1|g| \le 1 for every rr: unconditionally stable. Backward Euler's factor is also positive, so nothing flips sign. Move rr and watch where each factor sits in the band ∣g∣≤1|g| \le 1.

00.7851.572.363.14-7.48-5.24-3-0.761.48explicit (FTCS)backward EulerCrank–Nicolsonθ (phase per cell)growth factor g

Stable is not accurate. Start from sin⁡πx\sin\pi x (exact solution e−π2tsin⁡πxe^{-\pi^2 t}\sin\pi x) and reach t=0.05t = 0.05 on the same 21-node grid with backward Euler. Every run is stable; the error grows with the step: at r=20r = 20 it is 28 times its value at r=0.4r = 0.4.

r Δt steps to t = 0.05 backward Euler error
0.4 0.001 50 0.002093
1 0.0025 20 0.004276
5 0.0125 4 0.018
20 0.05 1 0.05953
When an implicit step breaks
  • Assumes: a long step is still short next to the time scale you care about
  • When it fails: past that, it is stable and wrong: backward Euler over-damps, and Crank–Nicolson keeps g(π)g(\pi) near −1-1, so a kink rings instead of smoothing
  • Check: halve Δt\Delta t and compare; if the answer moves by more than the tolerance, the step is set by accuracy, not stability

4. Measuring the order of a scheme

Setting: the problem, its sets and its symbols

Problem. Given the heat problem ut=uxxu_t = u_{xx} on [0,1][0, 1], u=0u = 0 at both ends, u(x,0)=sin⁡πxu(x, 0) = \sin\pi x, with exact solution uu, and FTCS at a fixed mesh ratio rr on grids Δx=1/10,1/20,…\Delta x = 1/10, 1/20, \dots, find the observed order pp such that the error at t=0.1t = 0.1 behaves like E(Δx)≈C ΔxpE(\Delta x) \approx C\,\Delta x^p.

Symbol In Meaning
uu [0,1]×[0,0.1]→R[0, 1] \times [0, 0.1] \to \mathbb{R} the exact solution, e−π2tsin⁡πxe^{-\pi^2 t}\sin\pi x
Δx\Delta x {1/10, 1/20, … }\{1/10,\ 1/20,\ \dots\} mesh spacing, halved per grid; the slider sets how many grids
Δt\Delta t R>0\mathbb{R}_{>0} time step r Δx2r\,\Delta x^2, so it shrinks with the mesh
rr {0.4, 0.25, 1/6}\{0.4,\ 0.25,\ 1/6\} the fixed mesh ratio, one table column each
uinu_i^n R\mathbb{R} FTCS's value at (xi,tn)(x_i, t_n), with tn=0.1t_n = 0.1 at the last step
EE R>0→R≥0\mathbb{R}_{>0} \to \mathbb{R}_{\ge 0} the error max⁡i∣uin−u(xi,0.1)∣\max_i \lvert u_i^n - u(x_i, 0.1) \rvert as a function of Δx\Delta x
p, Cp,\ C R\mathbb{R} observed order, p=log⁡2(EΔx/EΔx/2)p = \log_2(E_{\Delta x}/E_{\Delta x/2}), and the error constant
How these symbols connect

For ut=uxxu_t = u_{xx} on [0,1][0, 1] with exact solution u(x,t)=e−π2tsin⁡πxu(x, t) = e^{-\pi^2 t}\sin\pi x, fixing a mesh ratio r∈{0.4,0.25,1/6}r \in \{0.4, 0.25, 1/6\} and halving the spacing Δx∈{1/10,1/20,… }\Delta x \in \{1/10, 1/20, \dots\} shrinks the time step via Δt=r Δx2\Delta t = r\,\Delta x^2. Running FTCS to tn=0.1t_n = 0.1 yields grid values uinu_i^n, whose largest nodal discrepancy against u(xi,0.1)u(x_i, 0.1) defines the total error E(Δx)E(\Delta x). Fitting E(Δx)≈C ΔxpE(\Delta x) \approx C\,\Delta x^p across consecutive grid halvings produces the observed order pp for each column rr.

Symbol-by-symbol notes
$\Delta t = r\,\Delta x^2$ — coupled refinement

With rr held fixed down each column of the table, halving Δx\Delta x quarters Δt\Delta t and quadruples the number of steps to t=0.1t = 0.1. The measured error therefore combines spatial and temporal discretisation errors into a single function of Δx\Delta x.

$E(\Delta x)$ — maximum nodal error at $t = 0.1$

E(Δx)=max⁡i∣uin−u(xi,0.1)∣E(\Delta x) = \max_i\lvert u_i^n - u(x_i, 0.1)\rvert is the ∞\infty-norm error over all grid nodes at the final time t=0.1t = 0.1 (dimensionless here, matching uu). Comparing against the exact solution isolates discretisation error directly.

$p$ and $C$ — observed order and error constant

If E(Δx)≈C ΔxpE(\Delta x) \approx C\,\Delta x^p, taking consecutive rows where Δx\Delta x halves gives p=log⁡2(EΔx/EΔx/2)p = \log_2(E_{\Delta x}/E_{\Delta x/2}), as in M01. The leading constant CC can depend on the chosen rr and on uu, not on Δx\Delta x.

$r \in \{0.4,\ 0.25,\ 1/6\}$ — three stable columns

All three ratios sit below §2's explicit stability bound r≤12r \le \tfrac12, so every run is stable and the table measures convergence order rather than blow-up.

M01's convergence table works on a PDE exactly as on a derivative: run the scheme on grids Δx,Δx/2,Δx/4,…\Delta x, \Delta x/2, \Delta x/4, \dots, take the error against an exact solution, and read p=log⁡2(EΔx/EΔx/2)p = \log_2(E_{\Delta x}/E_{\Delta x/2}). Here the exact solution is u=e−π2tsin⁡πxu = e^{-\pi^2 t}\sin\pi x at t=0.1t = 0.1, and the scheme is FTCS at a fixed rr, so Δt=r Δx2\Delta t = r\,\Delta x^2 shrinks with the mesh.

Predict first. The table runs FTCS at r=0.4r = 0.4, 0.250.25 and 1/61/6. At r=1/6r = 1/6 the observed order in Δx\Delta x is

Choose a prediction

Check answer (without scripting)

Answer: 4. At r=1/6r = 1/6 the time and space errors cancel at leading order, r/2−1/12=0r/2 - 1/12 = 0, and the next term is O(Δx4)O(\Delta x^4).

Reveal result (lock in your prediction above first)
Δx error r=0.4 error r=0.25 error r=1/6 order r=0.4 order r=0.25 order r=1/6
0.1 0.004294 0.00152 6.694e-06 — — —
0.05 0.001063 0.0003786 4.156e-07 2.015 2.005 4.01
0.025 0.0002649 9.457e-05 2.593e-08 2.004 2.001 4.002
0.0125 6.62e-05 2.364e-05 1.62e-09 2.001 2 4.001

Taylor's theorem explains it. The centred second difference is uxx+Δx212uxxxx+O(Δx4)u_{xx} + \tfrac{\Delta x^2}{12} u_{xxxx} + O(\Delta x^4), the forward time difference is ut+Δt2utt+O(Δt2)u_t + \tfrac{\Delta t}{2} u_{tt} + O(\Delta t^2). With Δt=rΔx2\Delta t = r\Delta x^2 both errors are O(Δx2)O(\Delta x^2). Since utt=uxxxxu_{tt} = u_{xxxx} for the heat equation (with α=1\alpha = 1), the leading error is Δx2(r2−112)uxxxx\Delta x^2 \left(\tfrac{r}{2} - \tfrac{1}{12}\right) u_{xxxx}, which vanishes at r=1/6r = 1/6 and leaves O(Δx4)O(\Delta x^4).

The same stencil reads as order 2 or order 4 depending on how Δt\Delta t is tied to Δx\Delta x. A convergence table measures the total error, so a claim about the spatial order alone needs the time error made negligible (or cancelled) first. The r=1/6r = 1/6 trick is specific to this scheme and this equation; do not expect it elsewhere.

When a measured order breaks
  • Assumes: every error source shrinks with the refinement you make, at a known rate
  • When it fails: tying Δt\Delta t to Δx\Delta x mixes the time and space errors, so the table can show order 2 or 4 for the same spatial stencil
  • Check: refine Δx\Delta x with Δt\Delta t held tiny to isolate the space error, then the other way round

5. Hyperbolic: the wave equation and the CFL condition

Setting: the problem, its sets and its symbols

Problem. Given a wave speed c>0c > 0, a start f:R→Rf : \mathbb{R} \to \mathbb{R}, zero initial velocity and u=0u = 0 at x=0,1x = 0, 1, find u:[0,1]×[0,T]→Ru : [0, 1] \times [0, T] \to \mathbb{R} with utt=c2uxxu_{tt} = c^2u_{xx}, u(x,0)=f(x)u(x, 0) = f(x), ut(x,0)=0u_t(x, 0) = 0, approximated by leapfrog; and find how the Courant number ν\nu decides whether the grid values stay bounded and how accurate they are.

Symbol In Meaning
uu [0,1]×[0,T]→R[0, 1] \times [0, T] \to \mathbb{R} the displacement, the unknown
cc R>0\mathbb{R}_{>0} wave speed; c=1c = 1 here
ff R→R\mathbb{R} \to \mathbb{R} the start: a Gaussian pulse of width 0.08 at x=0.5x = 0.5, extended odd and 2-periodic, so d'Alembert's formula meets the fixed ends
D(x,t)D(x, t) [x−ct, x+ct][x - ct,\ x + ct] the domain of dependence of (x,t)(x, t)
Δx, Δt\Delta x,\ \Delta t R>0\mathbb{R}_{>0} mesh spacing 1/801/80 and time step
xi, tnx_i,\ t_n [0,1], [0,T][0, 1],\ [0, T] nodes xi=iΔxx_i = i\Delta x, i=0,…,80i = 0, \dots, 80; times tn=nΔtt_n = n\Delta t, n∈Nn \in \mathbb{N}
uinu_i^n R\mathbb{R} leapfrog's value at (xi,tn)(x_i, t_n); u−1u^{-1} is a fictitious level that encodes the zero velocity
ν\nu R>0\mathbb{R}_{>0} the Courant number c Δt/Δxc\,\Delta t/\Delta x, set by the slider
θ, g\theta,\ g [0,π], C[0, \pi],\ \mathbb{C} phase per cell of a Fourier mode and its growth factor per step
δ2\delta^2 R81→R81\mathbb{R}^{81} \to \mathbb{R}^{81} the second difference, (δ2u)i=ui+1−2ui+ui−1(\delta^2 u)_i = u_{i+1} - 2u_i + u_{i-1}
How these symbols connect

The wave equation utt=c2uxxu_{tt} = c^2 u_{xx} (wave speed c>0c > 0, initial shape ff, zero initial velocity, fixed ends u=0u = 0) carries information from the initial interval D(x,t)=[x−ct,x+ct]D(x, t) = [x - ct, x + ct] to the displacement u(x,t)u(x, t). On the grid (xi,tn)(x_i, t_n) with Δx=1/80\Delta x = 1/80 and time step Δt\Delta t, leapfrog advances unu^n and un−1u^{n-1} using the spatial second difference δ2\delta^2 weighted by ν2\nu^2, where ν=c Δt/Δx\nu = c\,\Delta t/\Delta x is the dimensionless Courant number. Comparing the stencil's reach with D(x,t)D(x, t) — alongside a Fourier mode's phase θ\theta and complex growth factor gg — shows how ν\nu governs boundedness and accuracy.

Symbol-by-symbol notes
$f$ — odd, 2-periodic extension

Although the physical domain is [0,1][0, 1] with u(0,t)=u(1,t)=0u(0, t) = u(1, t) = 0, ff is extended to all of R\mathbb{R} by reflecting the Gaussian pulse oddly across x=0x = 0 and x=1x = 1 (period 22). That extension makes d'Alembert's formula vanish identically at both endpoints, encoding inverted reflections.

$D(x, t)$ — physical domain of dependence

The closed interval [x−ct,x+ct][x - ct, x + ct] on the initial line t=0t = 0 contains all initial data that can physically reach (x,t)(x, t) at speed cc. Changing ff outside D(x,t)D(x, t) has no effect on u(x,t)u(x, t).

$\nu = c\,\Delta t/\Delta x$ — Courant number

With cc in m/s\text{m/s}, Δt\Delta t in s\text{s} and Δx\Delta x in m\text{m}, ν\nu is dimensionless and counts how many grid cells a wave travels per time step. Notice Δx\Delta x enters linearly here, unlike r=αΔt/Δx2r = \alpha\Delta t/\Delta x^2 for heat in §2.

$u^{-1}$ — fictitious level for zero initial velocity

Because leapfrog is a two-step recurrence needing both unu^n and un−1u^{n-1} to compute un+1u^{n+1}, starting at n=0n = 0 requires an extra level u−1u^{-1} built from u0u^0 and the initial condition ut(x,0)=0u_t(x, 0) = 0.

$\theta,\ g \in \mathbb{C}$ and $\delta^2$

Because leapfrog spans two previous time levels, substituting a Fourier mode of phase θ\theta yields a quadratic in gg, so gg can be complex (capturing wave phase advance as well as amplitude). The discrete operator δ2\delta^2 acts at interior nodes by (δ2u)i=ui+1−2ui+ui−1(\delta^2 u)_i = u_{i+1} - 2u_i + u_{i-1}.

utt=c2uxxu_{tt} = c^2 u_{xx} with zero velocity at the start has d'Alembert's solution u=12[f(x−ct)+f(x+ct)]u = \tfrac12\left[f(x - ct) + f(x + ct)\right]: the start splits into two halves that travel at speed cc and keep their shape. The value at (x,t)(x, t) depends only on the start in [x−ct, x+ct][x - ct,\ x + ct], its domain of dependence. Nothing outside that interval can affect it, however long you wait.

Centred differences in both time and space give leapfrog:

uin+1=2uin−uin−1+ν2 (ui+1n−2uin+ui−1n),ν=c ΔtΔx.u_i^{n+1} = 2u_i^n - u_i^{n-1} + \nu^2\,(u_{i+1}^n - 2u_i^n + u_{i-1}^n), \qquad \nu = \frac{c\,\Delta t}{\Delta x}.

After nn steps node ii has read nodes i−ni - n to i+ni + n: an interval of half-width nΔx=ct/νn\Delta x = ct/\nu. The exact answer needs half-width ctct, so the scheme can see what it must only if ν≤1\nu \le 1. That is the CFL condition: a scheme cannot be right where it cannot see. Von Neumann agrees: the factor solves g2−2(1−2ν2sin⁡2θ2)g+1=0g^2 - 2\left(1 - 2\nu^2\sin^2\tfrac\theta2\right)g + 1 = 0, whose roots have product one, so ∣g∣=1|g| = 1 exactly when νsin⁡(θ/2)≤1\nu\sin(\theta/2) \le 1 for every θ\theta, i.e. ν≤1\nu \le 1. Past it, ∣g∣>1|g| > 1 for the shortest waves.

Here c=1c = 1, Δx=1/80\Delta x = 1/80, a Gaussian pulse of width 0.08 at x=0.5x = 0.5, and the ends held at zero (the exact solution reflects with a sign change).

Predict first. Run leapfrog to t=0.25t = 0.25 at ν=0.5\nu = 0.5, 0.90.9 and 1.01.0. Which Courant number gives the smallest error?

Choose a prediction

Check answer (without scripting)

Answer: 1.0, the largest stable step. At ν=1\nu = 1 the update is uin+1=ui−1n+ui+1n−uin−1u_i^{n+1} = u_{i-1}^n + u_{i+1}^n - u_i^{n-1}, which is d'Alembert's formula on the grid: exact to rounding.

Reveal result (lock in your prediction above first)
00.250.50.751-0.030.110.250.390.53leapfrog (nodes)exact (d'Alembert)xu

ν=0.90\nu = 0.90, t=0.225t = 0.225, max⁡∣u∣=0.5\max|u| = 0.5. The leapfrog nodes sit on the exact curve: the largest gap is 1.1e-03, too small to see at this scale, and at ν=1\nu = 1 the two coincide to rounding (the table's last row). Below, the domain of dependence of (0.5,t)(0.5, t): the scheme's cone must contain the physical one.

0.250.3750.50.6250.75-0.01350.04950.1130.1750.238physicalschemext
ν steps error error, kernel's start
0.5 40 0.004621 0.01313
0.8 25 0.002237 0.02507
0.9 22 0.00118 0.02936
1 20 6.661e-16 0.03339

The first error column starts with the Taylor step u−1=u0+12ν2δ2u0u^{-1} = u^0 + \tfrac12\nu^2\delta^2 u^0 (zero velocity, second order). The kernel instead copies the start into the previous level, a first-order start, and that alone leaves the error in the last column at every ν\nu. Now set ν=1.05\nu = 1.05 and 100 steps: the shortest waves, present only at rounding level, have ∣g(π)∣≈1.88|g(\pi)| \approx 1.88 and take over.

source: solvers/ot-solve/src/kernels/wave.rs:115-135

The kernel's leapfrog step, with c2 the squared Courant number, and the rotation of the three time levels.

    let c2 = courant * courant;
    let mut field = [0.0f64; CAP];
    let (norm, total) = {
        let state = a.state_mut();
        let (prev_block, rest) = state.split_at_mut(CAP);
        let (u, rest) = rest.split_at_mut(CAP);
        let next = &mut rest[..CAP];
        for index in 1..cells - 1 {
            next[index] = 2.0 * u[index] - prev_block[index]
                + c2 * (u[index - 1] - 2.0 * u[index] + u[index + 1]);
        }
        next[0] = 0.0;
        next[cells - 1] = 0.0;
        // Rotate the three time levels: prev <- u, u <- next.
        prev_block[..cells].copy_from_slice(&u[..cells]);
        u[..cells].copy_from_slice(&next[..cells]);
        field[..cells].copy_from_slice(&next[..cells]);
        let norm = grid::max_abs(&next[..cells]);
        let total = energy(&u[..cells], &prev_block[..cells], cells, courant);
        (norm, total)
    };
When the CFL condition breaks
  • Assumes: one known, constant wave speed cc
  • When it fails: with a variable speed or a system, the fastest local wave decides; with a nonlinear equation the speed depends on the answer and can grow during the run
  • Check: compute ν\nu from the largest speed on the grid at every step; a conserved energy that drifts upwards is an instability starting

6. Elliptic: Laplace's equation by Jacobi iteration

Setting: the problem, its sets and its symbols

Problem. Given Ω=(0,1)2\Omega = (0, 1)^2 and boundary data g:∂Ω→Rg : \partial\Omega \to \mathbb{R}, find u∈C2(Ω)∩C(Ωˉ)u \in C^2(\Omega) \cap C(\bar\Omega) with uxx+uyy=0u_{xx} + u_{yy} = 0 in Ω\Omega and u=gu = g on ∂Ω\partial\Omega. Discretised: find u∈Rn2\mathbf u \in \mathbb{R}^{n^2} with Au=bA\mathbf u = \mathbf b by Jacobi iteration, and the number of sweeps kk that cuts the error by 10610^6.

Symbol In Meaning
Ω\Omega (0,1)2⊂R2(0, 1)^2 \subset \mathbb{R}^2 the unit square, with boundary ∂Ω\partial\Omega
uu C2(Ω)∩C(Ωˉ)C^2(\Omega) \cap C(\bar\Omega) the steady temperature, the unknown
gg ∂Ω→R\partial\Omega \to \mathbb{R} sin⁡πx\sin\pi x on the top edge (y=1y = 1), zero on the other three
nn N\mathbb{N} interior nodes per side; n=15n = 15 on the slider
hh R>0\mathbb{R}_{>0} mesh spacing 1/(n+1)1/(n + 1)
ui,ju_{i,j} R\mathbb{R} the value at (ih,jh)(ih, jh), i,j=1,…,ni, j = 1, \dots, n
AA Rn2×n2\mathbb{R}^{n^2 \times n^2} the five-point matrix times h2h^2: 44 on the diagonal, −1-1 per neighbour; sparse and symmetric
b\mathbf b Rn2\mathbb{R}^{n^2} the boundary values moved to the right-hand side
DD Rn2×n2\mathbb{R}^{n^2 \times n^2} Jacobi's splitting, the diagonal 4I4I
MM Rn2×n2\mathbb{R}^{n^2 \times n^2} the iteration matrix I−D−1AI - D^{-1}A
ek\mathbf e^k Rn2\mathbb{R}^{n^2} the error after k∈Nk \in \mathbb{N} sweeps, ek+1=Mek\mathbf e^{k+1} = M\mathbf e^k
ρ(M)\rho(M) [0,∞)[0, \infty) the spectral radius, the largest eigenvalue modulus (M05)
How these symbols connect

Laplace's equation uxx+uyy=0u_{xx} + u_{yy} = 0 on Ω=(0,1)2\Omega = (0, 1)^2 with boundary data gg on ∂Ω\partial\Omega has no time variable: discretising on an n×nn \times n interior grid of spacing h=1/(n+1)h = 1/(n + 1) couples all n2n^2 unknowns ui,ju_{i,j} at once in Au=bA\mathbf u = \mathbf b, with known boundary values from gg moved into b\mathbf b. Jacobi iteration splits out the diagonal D=4ID = 4I of AA and sweeps repeatedly across the grid, so the error vector ek\mathbf e^k after kk sweeps obeys ek+1=Mek\mathbf e^{k+1} = M\mathbf e^k with iteration matrix M=I−D−1AM = I - D^{-1}A. The spectral radius ρ(M)\rho(M) (M05) sets the asymptotic per-sweep decay factor and determines how many sweeps kk cut the error by 10610^6.

Symbol-by-symbol notes
$n$ vs $h$ — interior nodes and mesh spacing

With nn interior nodes per side plus 22 boundary nodes, each edge of the unit square is split into n+1n + 1 cells, so h=1/(n+1)h = 1/(n + 1) (not 1/n1/n). Stacking the interior grid gives n2n^2 unknowns, so AA, DD and MM are n2×n2n^2 \times n^2 matrices.

$u \in C^2(\Omega) \cap C(\bar\Omega)$ and $g$

The solution uu is twice continuously differentiable in the open interior Ω\Omega (so uxx+uyyu_{xx} + u_{yy} exists) and continuous up to the closed square Ωˉ=[0,1]2\bar\Omega = [0, 1]^2 to match gg on ∂Ω\partial\Omega. Here gg is boundary data, unrelated to the growth factors g(θ)g(\theta) in §2–§5.

$A$ and $\mathbf b$ — five-point stencil times $h^2$

Multiplying the discrete equation (4ui,j−ui±1,j−ui,j±1)/h2=0(4u_{i,j} - u_{i\pm 1,j} - u_{i,j\pm 1})/h^2 = 0 by h2h^2 leaves 44 on the diagonal of AA and −1-1 at each interior neighbour. Whenever a neighbour lies on ∂Ω\partial\Omega, its known value from gg moves into the right-hand side b\mathbf b.

$D$ and $M = I - D^{-1}A$ — Jacobi's splitting

D=4ID = 4I is the diagonal of AA, so M=I−D−1AM = I - D^{-1}A has zeros on its diagonal and 14\tfrac14 at each interior neighbour. One application of MM replaces every interior value with the average of its four neighbours.

$\mathbf e^k$ and $\rho(M)$ — error vector and spectral radius

ek=uk−u\mathbf e^k = \mathbf u^k - \mathbf u is the algebraic error against the discrete solution u=A−1b\mathbf u = A^{-1}\mathbf b after kk sweeps (not the discretisation error against continuous uu), with superscript kk indexing sweeps. Its asymptotic contraction factor per sweep is ρ(M)=max⁡i∣λi(M)∣\rho(M) = \max_i\lvert\lambda_i(M)\rvert (M05), which must lie below 11 for Jacobi to converge.

Steady heat in the unit square: uxx+uyy=0u_{xx} + u_{yy} = 0, u=sin⁡πxu = \sin\pi x on the top edge and 00 on the others. The exact solution is u=sin⁡(πx)sinh⁡(πy)/sinh⁡πu = \sin(\pi x)\sinh(\pi y)/\sinh\pi. The five-point stencil 4ui,j−ui±1,j−ui,j±1=04u_{i,j} - u_{i\pm1,j} - u_{i,j\pm1} = 0 (times 1/h21/h^2) turns it into one linear system Au=bA\mathbf u = \mathbf b (M03), with no time in it: every unknown is coupled to every other through the matrix.

Jacobi splits A=D−(D−A)A = D - (D - A) with D=4ID = 4I and iterates uk+1=D−1(b+(D−A)uk)\mathbf u^{k+1} = D^{-1}\big(\mathbf b + (D - A)\mathbf u^k\big): each node becomes the average of its four neighbours. The error obeys ek+1=Mek\mathbf e^{k+1} = M\mathbf e^k with M=I−D−1AM = I - D^{-1}A, so it shrinks like ρ(M)k\rho(M)^k, the spectral radius (M05). For this matrix the eigenvalues are 12(cos⁡pπh+cos⁡qπh)\tfrac12(\cos p\pi h + \cos q\pi h), and the largest, from the smoothest mode, is

ρ=cos⁡πh.\rho = \cos\pi h.

Information moves one cell per sweep. Move the slider: the boundary value creeps down from the top edge.

0.0620.9380.1250.9380.1880.9380.250.9380.3120.9380.3750.9380.4380.9380.50.9380.5620.9380.6250.9380.6880.9380.750.9380.8120.9380.8750.9380.9380.938x

After 60 sweeps the largest error against the direct solve is 1.02e-01 (it starts at 0.82). ρ=cos⁡(π/16)=0.9808\rho = \cos(\pi/16) = 0.9808, so one sweep removes only 1.9% of the slowest error.

Predict first. Jacobi needs some number of sweeps to cut the error by 10610^6 on a 7×77 \times 7 interior grid (h=1/8h = 1/8). On 31×3131 \times 31 (h=1/32h = 1/32) it needs about

Choose a prediction

Check answer (without scripting)

Answer: 16 times as many. k∝h−2k \propto h^{-2}, and hh shrank by four, so the count grows sixteenfold. The direct solve did not care.

Reveal result (lock in your prediction above first)
interior n h ρ = cos πh predicted sweeps measured sweeps discretisation error ρ from eigenvalues order
7 0.125 0.9239 174.5 165 0.004322 0.9239 —
15 0.0625 0.9808 712.1 664 0.001109 0.9808 1.963
31 0.03125 0.9952 2862 2646 0.000278 — 1.996

Since ρ=cos⁡πh≈1−π2h2/2\rho = \cos\pi h \approx 1 - \pi^2 h^2/2, the error falls like ρk\rho^k and

k≈ln⁡(tol)ln⁡ρ≈2ln⁡(1/tol)π2h2:k \approx \frac{\ln(\text{tol})}{\ln\rho} \approx \frac{2\ln(1/\text{tol})}{\pi^2 h^2}:

sweeps grow like h−2h^{-2}. The smooth error needs many one-cell crossings to drain out.

Measured ratio 16.0 from h=1/8h = 1/8 to 1/321/32, step ratios 4.02 and 3.98. The measured counts sit a little below ln⁡(10−6)/ln⁡ρ\ln(10^{-6})/\ln\rho because the starting error is not purely the slowest mode. The spectral radius from the eigenvalues of I−D−1AI - D^{-1}A matches cos⁡πh\cos\pi h to rounding, and the discretisation error has order 2 (M01's table again). The cure is not more sweeps: conjugate gradients needs O(1/h)O(1/h) iterations, multigrid O(1)O(1).

When Jacobi iteration breaks
  • Assumes: a spectral radius below one, which irreducible diagonal dominance guarantees here
  • When it fails: ρ=cos⁡(πh)→1\rho = \cos(\pi h) \to 1 as the mesh refines, so the smooth error modes barely move and the count grows like h−2h^{-2}
  • Check: plot the error or residual on a log scale: a straight line of slope ln⁡ρ\ln\rho; if the count quadruples when hh halves, use CG or multigrid

Practice

Practice A (steps partly filled). An explicit heat solve has α=0.01\alpha = 0.01, Δx=0.05\Delta x = 0.05 and Δt=0.15\Delta t = 0.15. First r=αΔt/Δx2=0.01×0.15/0.0025=  ?r = \alpha\Delta t/\Delta x^2 = 0.01 \times 0.15 / 0.0025 = \;?, then g(π)=1−4rg(\pi) = 1 - 4r. Enter g(π)g(\pi).

Worked solution

r=0.0015/0.0025=0.6r = 0.0015/0.0025 = 0.6, so g(π)=1−2.4=−1.4g(\pi) = 1 - 2.4 = -1.4. Since ∣g∣>1|g| > 1 the sawtooth grows by 1.4 each step: unstable. The largest stable step is Δt=Δx2/(2α)=0.125\Delta t = \Delta x^2/(2\alpha) = 0.125.

Practice B (with a hint). Sound in air, c=340c = 340 m/s, on a mesh with Δx=0.5\Delta x = 0.5 m, stepped by leapfrog. Enter the largest stable Δt\Delta t in milliseconds.

Worked solution

Δt≤0.5/340=1.47×10−3\Delta t \le 0.5/340 = 1.47 \times 10^{-3} s =1.47= 1.47 ms. Halving Δx\Delta x halves it: the hyperbolic limit is linear in the mesh.

Hint 1

The CFL condition is ν=c Δt/Δx≤1\nu = c\,\Delta t/\Delta x \le 1.

Hint 2

So Δt≤Δx/c\Delta t \le \Delta x / c; convert seconds to milliseconds at the end.

Practice C (on your own). Jacobi on the one-dimensional model problem −u′′=f-u'' = f with h=1/50h = 1/50 has ρ=cos⁡πh\rho = \cos\pi h. About how many sweeps cut the error by 10610^6?

Worked solution

cos⁡(π/50)=0.99803\cos(\pi/50) = 0.99803, ln⁡ρ=−0.001975\ln\rho = -0.001975, and k=ln⁡(10−6)/ln⁡ρ=13.82/0.001975≈6990k = \ln(10^{-6})/\ln\rho = 13.82/0.001975 \approx 6990. The shortcut 2ln⁡(106)/(π2h2)=27.6×2500/9.87≈70002\ln(10^6)/(\pi^2 h^2) = 27.6 \times 2500/9.87 \approx 7000 agrees.

Mixed practice: which method, and why? These mix this notebook with M01, M03 and M05.

1. Steady temperature in a plate with fixed edge temperatures, 10510^5 unknowns. Which approach first?

Question 1

2. An implicit heat code is refined in Δx\Delta x with Δt\Delta t held fixed. The observed order falls from 2 towards 0, with errors near 10−410^{-4}. Why?

Question 2

3. An explicit diffusion code is stable on a coarse mesh and blows up on a fine one with the same Δt\Delta t. What should you compute?

Question 3

Show answers and explanations

1. Assemble the sparse system and solve it with CG or multigrid. Elliptic means one linear system (M03). A Krylov method or multigrid beats Jacobi because its count grows slowly or not at all with the mesh.

2. The fixed time error now dominates the total. The total is O(Δt)+O(Δx2)O(\Delta t) + O(\Delta x^2); with Δt\Delta t fixed the first term is a floor, and the table measures it (§4, M01 §3).

3. The largest r = α Δt / Δx² on the fine mesh. rr quadruples when Δx\Delta x halves at fixed Δt\Delta t, so a stable r=0.4r = 0.4 becomes 1.61.6. The growth factor's size at θ=π\theta = \pi (an eigenvalue question, M05) says the rest.

Check yourself (closed book)

1. uxx+4uxy+3uyy=0u_{xx} + 4u_{xy} + 3u_{yy} = 0. Which class?

Question 1
How sure?

2. The explicit heat scheme has growth factor g(θ)=1−4rsin⁡2(θ/2)g(\theta) = 1 - 4r\sin^2(\theta/2). Which mode decides the limit r≤1/2r \le 1/2?

Question 2
How sure?

3. Backward Euler for the heat equation is stable for every rr. What does a very large rr cost you?

Question 3
How sure?

4. The explicit heat scheme at fixed rr shows observed order 2 in Δx\Delta x. Why 2, when the time step is only first order?

Question 4
How sure?

5. Leapfrog for utt=c2uxxu_{tt} = c^2 u_{xx} runs at Courant number ν=c Δt/Δx=1.05\nu = c\,\Delta t/\Delta x = 1.05. Why does it fail?

Question 5
How sure?

6. Jacobi on the five-point Laplacian has spectral radius ρ=cos⁡(πh)\rho = \cos(\pi h). Halve hh: the iterations to a fixed tolerance grow by about

Question 6
How sure?

Show answers and explanations

1. Hyperbolic, because B² exceeds 4AC. B2−4AC=16−12=4>0B^2 - 4AC = 16 - 12 = 4 > 0: two real characteristic directions through every point, so hyperbolic.

2. The grid-scale sawtooth, θ = π. g(π)=1−4rg(\pi) = 1 - 4r, and ∣1−4r∣≤1|1 - 4r| \le 1 needs r≤1/2r \le 1/2. The mode that alternates sign from node to node is the first to grow.

3. Accuracy: the step is too long to follow the decay. The time error is O(Δt)O(\Delta t), and Δt=r Δx2\Delta t = r\,\Delta x^2 grows with rr. Stability lets you take the step; accuracy decides whether you should.

4. Because Δt = r Δx², so O(Δt) is O(Δx²). The time error O(Δt)O(\Delta t) and the space error O(Δx2)O(\Delta x^2) are the same size when Δt\Delta t is tied to Δx2\Delta x^2. At r=1/6r = 1/6 their leading terms even cancel.

5. The scheme cannot see the data the exact answer depends on. After nn steps the scheme reads nΔx=ct/νn\Delta x = ct/\nu either side, which is less than the physical ctct when ν>1\nu > 1. Von Neumann gives the same line: ∣g∣>1|g| > 1 for the shortest waves.

6. a factor of 4. Iterations ≈ln⁡(tol)/ln⁡ρ≈2ln⁡(1/tol)/(π2h2)\approx \ln(\text{tol})/\ln\rho \approx 2\ln(1/\text{tol})/(\pi^2 h^2), so halving hh multiplies them by four. §6 measures 4.0.

Keep these:

  1. B2−4ACB^2 - 4AC, read with every term on one side, gives the class at a point: waves travel, diffusion forgets, equilibrium is settled everywhere at once.
  2. Explicit diffusion: g(π)=1−4rg(\pi) = 1 - 4r, so r≤1/2r \le 1/2 and Δt∝Δx2\Delta t \propto \Delta x^2; just above the limit a sawtooth grows geometrically.
  3. Implicit steps remove the limit for the price of a linear solve per step; they do not remove the time error.
  4. A convergence table measures the total error: tie Δt\Delta t to Δx\Delta x and you measure both at once.
  5. CFL: the scheme's domain of dependence must contain the physical one, c Δt/Δx≤1c\,\Delta t/\Delta x \le 1.
  6. Jacobi converges like ρk\rho^k with ρ=cos⁡πh\rho = \cos\pi h: sweeps grow like h−2h^{-2}, which is why elliptic solvers are Krylov or multigrid.

Your connection

Pick a model you know (a part heating, a signal on a line, a field at equilibrium). Which class is it, which limit would an explicit solver hit, and how would you notice?

Answers

Practice A. r=0.6r = 0.6, g(π)=−1.4g(\pi) = -1.4: unstable.

Practice B. Δt≤1.47\Delta t \le 1.47 ms.

Practice C. about 6990 sweeps.

Mixed practice. solve the sparse system with CG or multigrid; the fixed time error dominates; compute the largest rr on the fine mesh.

Where the maths is derived

Optional. These notes give the intuition and application; the sources below give the full derivations and proofs.

§1 Reading the class

§2 The explicit heat scheme

§3 Implicit schemes

§5 The wave equation and the CFL condition

§6 Jacobi on the Laplacian


Compiled from notebooks/methods/m06_equation_classes.py — run locally with cd notebooks && uv run marimo edit methods/m06_equation_classes.py for live Python scratch cells.

Back to the book: Reading the class off the equation · Elliptic · Parabolic · Hyperbolic

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Reading offline

Keep this book on this device and read it offline.