Skip to content
Tutorials Center
My learning

Topics

Lesson 44 of 68 ยท Series, Transforms and PDEs

Partial Differential Equations: Heat and Wave

Meet the heat, wave and Laplace equations, solve them by separation of variables, and build a finite-difference heat solver with its stability limit in Python.

An ordinary differential equation describes something that changes in one variable, usually time. A partial differential equation (PDE) involves rates of change in several variables at once: how temperature varies along a rod and in time, how a guitar string moves along its length and in time, how voltage is spread over a plate. PDEs are the language of heat flow, vibration, fluids, electromagnetism and diffusion in finance.

Three PDEs cover a remarkable amount of engineering, and each represents a different kind of physics. This lesson meets them, solves them in two ways (an exact method using Fourier series, and a numerical method you can run anywhere), and shows the single most important numerical pitfall: stability.

The three classic equations

Heat (diffusion) equation. u_t = alpha * u_xx. Here u(x, t) is temperature, u_t its rate of change in time, u_xx its second derivative along the rod, and alpha the thermal diffusivity. Intuition: where the temperature curve bends upward (u_xx > 0), the point is colder than its neighbours' average and warms up. Heat smooths things out.

Wave equation. u_tt = c**2 * u_xx. Now the second time derivative appears, so this describes acceleration: a string segment accelerates according to its curvature. Disturbances travel at speed c and do not decay on their own.

Laplace equation. u_xx + u_yy = 0. There is no time at all: it describes a steady state, such as the final temperature on a plate whose edges are held at fixed temperatures. Solutions have no local hot or cold spots; each value is the average of its surroundings.

flowchart TD
    A["PDEs in engineering"] --> B["Heat: u_t = a u_xx<br/>diffusion, smoothing"]
    A --> C["Wave: u_tt = c^2 u_xx<br/>vibration, propagation"]
    A --> D["Laplace: u_xx + u_yy = 0<br/>steady state"]

Parabolic, hyperbolic and elliptic: three families, three behaviours.

A PDE alone has many solutions. You must also supply boundary conditions (what happens at the ends, for example u = 0 at both ends of the rod) and, for time-dependent problems, initial conditions (the starting shape).

Separation of variables

Take a rod of length L = 1 with both ends held at temperature 0 and an initial temperature profile u(x, 0) = f(x). Try solutions of the form

u(x, t) = X(x) * T(t)

Substituting into the heat equation and dividing by alpha * X * T gives T'/(alpha*T) = X''/X. The left side depends only on t, the right side only on x, so both must equal one constant, -lambda. We get two ordinary differential equations:

  • X'' = -lambda * X with X(0) = X(1) = 0: only lambda = (n*pi)**2 works, with X_n(x) = sin(n*pi*x).
  • T' = -alpha * lambda * T: solved by T_n(t) = e**(-alpha * (n*pi)**2 * t).

Each mode sin(n*pi*x) * e**(-alpha*(n*pi)**2*t) solves the PDE, and sums of solutions are solutions (the equation is linear). Expand the initial shape in a sine series, f(x) = sum of b_n sin(n*pi*x), with b_n = 2 * integral from 0 to 1 of f(x) sin(n*pi*x) dx, and the complete solution is

u(x, t) = sum of b_n * sin(n*pi*x) * e**(-alpha*(n*pi)**2*t)

Read it physically. The n-th mode dies at rate alpha*(n*pi)**2, so sharp, wiggly features vanish fastest while the smooth fundamental lingers. After a short time, almost any initial profile looks like one half-sine that slowly fades.

Python Heat equation by Fourier series

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The block starts with a maximum slightly above 1 at t = 0 (that is the Gibbs ringing of a 60-term sine series, nothing physical), then rounds off almost immediately as the high modes decay, spreads and cools. A longer time makes the curve look like a single sine arch.

A finite-difference heat solver

Most PDEs have no neat series solution, so engineers solve them numerically. Chop the rod into grid points x_j = j*dx and time into steps dt. Replace derivatives by differences, exactly as in The Derivative as a Rate of Change:

  • u_t becomes (u[j]_new - u[j]) / dt
  • u_xx becomes (u[j+1] - 2*u[j] + u[j-1]) / dx**2

Solving for the new value gives the explicit (FTCS) scheme:

u[j]_new = u[j] + r * (u[j+1] - 2*u[j] + u[j-1]), where r = alpha * dt / dx**2

Each point moves toward the average of its neighbours. It is the Euler method from Solving ODEs Numerically applied at every grid point.

Python Explicit finite-difference heat solver

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For the initial shape sin(pi*x) only the first mode exists, so the exact answer is one decaying sine and we can check the numbers. The error is a small fraction of a percent.

The stability limit

There is a catch. The explicit scheme works only if r = alpha*dt/dx**2 <= 1/2. Pick a time step too large and rounding noise is not damped but amplified at every step until the answer is garbage. This is not a bug in your code but a property of the method.

Why? In the new value (1 - 2r)*u[j] + r*(u[j+1] + u[j-1]), the middle weight is negative when r > 1/2. Then a spike at one point overshoots its neighbours, the overshoot gets bigger, and a sawtooth pattern explodes. Note what this costs: halving dx for better accuracy forces dt to shrink by a factor of four. That is why implicit methods (see the project Heat Flow in a Rod) matter for fine grids.

Python Stable versus unstable time steps

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

At r = 0.25 and 0.5 the maximum shrinks, as heat should. Just past 0.5 it begins to grow, and at 0.6 it blows up.

The wave and Laplace equations

Wave equation. The same separation of variables gives, for a string of length 1 fixed at both ends, modes sin(n*pi*x) * cos(n*pi*c*t). Unlike heat modes, these never decay; they oscillate at frequencies n*c/2. That is why a plucked string produces a fundamental plus overtones in whole-number ratios (the harmonic series from the Fourier series lesson). D'Alembert's solution shows the other face: any shape splits into two copies, one travelling right and one left, each at speed c.

Laplace equation. A grid point in a steady state equals the average of its four neighbours. Start with any guess and repeatedly replace each interior value by that average (the Jacobi iteration) and the plate relaxes toward the true solution.

Python Steady-state temperature on a plate

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The grid value is a hair under 25 (the grid is coarse and the corners are a compromise). The exact centre value of 25 follows from superposition and symmetry: rotating the plate so each of the four edges takes its turn at 100 gives four solutions that add up to a uniform 100, so each contributes a quarter at the centre.

Types of PDE. Heat equation: parabolic (smooths, irreversible in time). Wave equation: hyperbolic (information travels at finite speed). Laplace equation: elliptic (a boundary-value problem with no time). The type tells you which boundary data the problem needs and which numerical method is appropriate.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which PDE describes a steady state with no time dependence?

    The Laplace equation u_xx + u_yy = 0 has no time derivative; it describes the final, steady temperature or potential.
  2. 2. In separation of variables for the heat equation, why do high-frequency modes disappear faster?

    Mode n decays like exp(-alpha*(npi)**2t), so large n means a very fast decay. Sharp features smooth out first.
  3. 3. For the explicit finite-difference heat solver, what is the stability condition?

    With r = alpha*dt/dx**2 greater than 1/2, the scheme amplifies small errors and the solution blows up.
  4. 4. You halve the grid spacing dx in the explicit heat solver. How must dt change to stay stable?

    Since r = alpha*dt/dx2, halving dx makes dx2 four times smaller, so dt must shrink four times as well.
  5. 5. What does the Laplace equation say about the value at an interior point?

    Harmonic functions satisfy a mean-value property: each value is the average of its neighbours, which is why Jacobi relaxation converges to the solution.

Summary

  • A PDE relates partial derivatives; the heat (u_t = alpha*u_xx), wave (u_tt = c**2*u_xx) and Laplace (u_xx + u_yy = 0) equations model diffusion, vibration and steady states.
  • Boundary and initial conditions pick one solution out of many.
  • Separation of variables, plus a Fourier sine series for the initial shape, gives exact solutions as sums of decaying (heat) or oscillating (wave) modes.
  • The explicit finite-difference heat solver needs r = alpha*dt/dx**2 <= 1/2; beyond that it is unstable.
  • Laplace solutions are averaging: relaxation on a grid converges to the steady state.

Next: Matrices and Linear Systems.