Numerical AnalysisDifferential Equations

The Heat Equation: An Explicit Scheme

uᵢⁿ⁺¹ = uᵢⁿ + r(uᵢ₊₁ⁿ − 2uᵢⁿ + uᵢ₋₁ⁿ) with r = kΔt/Δx² is stable only when r ≤ 1/2.

Not started Jump to practice

The The Heat Equation, $u_t = ku_{xx}$, describes heat spreading along a rod. To compute it, combine two ideas you already have: the second difference in space from Boundary Value Problems by Finite Differences, and a forward Euler step in time, whose stability limits will matter.

On a grid $x_i = i\Delta x$, $t_n = n\Delta t$, write $u_i^{n} \approx u(x_i, t_n)$. The explicit scheme is $$u_i^{n+1} = u_i^{n} + r\left(u_{i+1}^{n} - 2u_i^{n} + u_{i-1}^{n}\right),\qquad r = \frac{k\Delta t}{\Delta x^{2}},$$ with the end values given by the boundary conditions.

Key idea

The explicit scheme is stable only when $r \le \frac{1}{2}$, that is, $\Delta t \le \frac{\Delta x^{2}}{2k}$. Refining the space grid by a factor of 2 forces 4 times as many time steps.

Why it works

Two views. First, rewrite the update as $u_i^{n+1} = ru_{i-1}^{n} + (1 - 2r)u_i^{n} + ru_{i+1}^{n}$. When $r \le \frac{1}{2}$ all three weights are nonnegative and add to 1, so each new value is an average of old ones and nothing can grow. Second, try the sawtooth $u_i = (-1)^{i}$: then $u_{i+1} - 2u_i + u_{i-1} = -4u_i$, so the sawtooth is multiplied by $1 - 4r$ each step. $|1 - 4r| \le 1$ exactly when $r \le \frac{1}{2}$; otherwise it grows and flips sign every step. (In method-of-lines terms, the fastest mode is $y' = \lambda y$ with $\lambda \approx -\frac{4k}{\Delta x^{2}}$, and Euler needs $\Delta t|\lambda| \le 2$.)
The explicit heat scheme on a rod with its ends held at 0. Below r = 1/2 the bump spreads smoothly; above it, a tiny sawtooth (like round-off) grows until it swamps the solution.

Worked example: One step

With $r = \frac{1}{4}$, the current row (ends held at 0) is $u = (0, 1, 2, 1, 0)$. Find the next row.
  1. $u_1 = 1 + \frac{1}{4}(2 - 2 + 0) = 1$.
  2. $u_2 = 2 + \frac{1}{4}(1 - 4 + 1) = 1.5$.
  3. $u_3 = 1$ by symmetry. The peak drops and the heat spreads.

Answer: $(0, 1, 1.5, 1, 0)$

Worked example: The cost of refining

For $k = 1$ and $\Delta x = 0.1$, find the largest stable $\Delta t$. What happens if $\Delta x$ is halved?
  1. $\Delta t \le \frac{(0.1)^{2}}{2} = 0.005$.
  2. With $\Delta x = 0.05$: $\Delta t \le \frac{0.0025}{2} = 0.00125$, 4 times smaller.
  3. Twice the grid points and 4 times the steps: 8 times the work to reach the same final time. In two space dimensions the same refinement costs 16 times as much.

Answer: $0.005$, then $0.00125$

Worked example: How fast instability wins

With $r = 0.6$, a sawtooth of size $10^{-16}$ (round-off) is present. How big is it after 100 steps?
  1. Each step multiplies it by $|1 - 4(0.6)| = 1.4$.
  2. $1.4^{100} \approx 4 \times 10^{14}$, so it reaches about $4 \times 10^{14} \times 10^{-16} = 0.04$, and a few dozen steps later it dominates the solution.

Answer: about $0.04$

Common mistake

Refining the space grid without shrinking the time step. Halving $\Delta x$ quadruples $r$, which can push a stable computation past $r = \frac{1}{2}$. Always recompute $r = \frac{k\Delta t}{\Delta x^{2}}$ after changing either step. (Implicit schemes, such as backward Euler or Crank–Nicolson in time, remove this limit.)

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 3 XP.

Loading practice…

Builds on

Leads to

This is one of the top rungs of Numerical Analysis.

Sources and further reading

  • Tobin A. Driscoll and Richard J. Braun, Fundamentals of Numerical Computation (University of Delaware, free online edition): chapter "Diffusion equations", sections "The method of lines" and "Method of lines for parabolic PDEs"
  • MIT OpenCourseWare 18.330, Introduction to Numerical Analysis: lecture notes on finite differences for the heat equation
@teddyrookbook GitHub