---
title: The heat equation by separation of variables
heading: Splitting a diffusion problem into modes that each decay on their own
eyebrow: A12 · Lesson 30 · The heat equation by separation of variables
xp: 40
---

::: hook
How long does a hot component take to cool once its ends are clamped to a heat sink? How long until a voltage step diffuses down a long RC line? Both are the heat equation, and both yield to the same method: **separation of variables**. Guess solutions that are a shape in space times a function of time, find which shapes fit the boundary conditions (sines, for ends held at zero), and build the actual initial condition as a Fourier series of those shapes. Each term then decays at its own rate, and the slowest one sets the time scale engineers quote.
:::

::: play
- A rod at temperature 1 has both ends dropped to 0 at t = 0. The curve is the separated solution: the first six odd sine modes, with amplitudes $4/(n\pi)$.
- At t = 0 the sum wiggles around the flat initial value (and the ends' jump), as Fourier series do near a discontinuity. Advance t a little: the wiggles, high modes, vanish almost at once.
- After that, the profile is essentially one sine hump shrinking as $e^{-\pi^2\alpha t}$: the readout compares the true center temperature with that single-mode estimate.
:::
:::

```sim plot
view: graph
x: x = 0..1 m
y: u = -0.2..1.3
slider: t = 0..0.3 step 0.001 = 0.002 s
slider: a = 0.5..2 step 0.1 = 1
plot: 4/pi*(sin(pi*x)*exp(-pi^2*a*t) + sin(3*pi*x)/3*exp(-9*pi^2*a*t) + sin(5*pi*x)/5*exp(-25*pi^2*a*t) + sin(7*pi*x)/7*exp(-49*pi^2*a*t) + sin(9*pi*x)/9*exp(-81*pi^2*a*t) + sin(11*pi*x)/11*exp(-121*pi^2*a*t)) | samples: 600 | label: u(x, t)
plot: 4/pi*sin(pi*x)*exp(-pi^2*a*t) | dashed | label: first mode only
readout: center, six modes = 4/pi*(exp(-pi^2*a*t) - exp(-9*pi^2*a*t)/3 + exp(-25*pi^2*a*t)/5 - exp(-49*pi^2*a*t)/7 + exp(-81*pi^2*a*t)/9 - exp(-121*pi^2*a*t)/11)
readout: center, first mode = 4/pi*exp(-pi^2*a*t)
```

::: predict
## The rod starts uniformly at 1 with its ends held at 0. What's the amplitude of its first sine mode, $\sin(\pi x/L)$?

- [ ] 1
- [x] $4/\pi \approx 1.27$
- [ ] $2/\pi$
- [ ] 0.5

::: reveal
$4/\pi$: the Fourier sine coefficient of a constant is $b_n = \frac{2}{L}\int_0^L \sin\frac{n\pi x}{L}dx = \frac{4}{n\pi}$ for odd n and 0 for even n. The first mode overshoots 1 because the other modes (negative at the center) bring the sum back down.
:::
:::

::: nameit
## The method

For $u_t = \alpha u_{xx}$ on $0 < x < L$ with $u(0, t) = u(L, t) = 0$:

1. **Separate:** try $u = X(x)T(t)$. Then $\frac{T'}{\alpha T} = \frac{X''}{X} = -\lambda$, a constant, since one side depends only on t and the other only on x.
2. **Solve the space problem:** $X'' + \lambda X = 0$ with $X(0) = X(L) = 0$ has nonzero solutions only for $\lambda_n = (n\pi/L)^2$: $X_n = \sin(n\pi x/L)$.
3. **Solve the time problem:** $T_n = e^{-\alpha\lambda_n t}$.
4. **Superpose and fit the initial condition:**

$$u = \sum_{n=1}^{\infty} b_n\sin\frac{n\pi x}{L}e^{-\alpha(n\pi/L)^2 t}, \qquad b_n = \frac{2}{L}\int_0^L f(x)\sin\frac{n\pi x}{L}dx$$

## Other boundary conditions

- **Insulated ends** ($u_x = 0$): cosines, $\lambda_n = (n\pi/L)^2$ for n = 0, 1, 2, ..., and the n = 0 term is the average temperature, which never changes.
- **Ends held at fixed nonzero temperatures:** subtract the steady straight-line solution first; what's left has zero ends.

## The slow mode

After a short while only the first mode remains, so the whole rod relaxes with the time constant $\tau = \frac{L^2}{\alpha\pi^2}$: proportional to the square of the length. Halving a heat path quarters its cooling time.
:::

::: example
## A 5 cm aluminum bar (α = 9.7 × 10⁻⁵ m²/s), initially at 80 °C, has its ends clamped at 20 °C. When is its center below 30 °C?

::: solution
1. **Subtract the steady state.** The excess starts at 60 °C and must fall to 10 °C.
2. **First mode at the center.** Its amplitude is
   $$\frac{4}{\pi} \times 60 = 76.4\ \text{°C}$$
3. **Its time constant.**
   $$\begin{aligned} \tau &= \frac{0.05^2}{9.7 \times 10^{-5}\pi^2}\ \text{s} \\ &= 2.61\ \text{s} \end{aligned}$$
4. **Solve for the time.** Set the center's excess to 10 °C:
   $$76.4e^{-t/2.61} = 10$$
   $$\begin{aligned} t &= 2.61\ln 7.64 \\ &= 5.3\ \text{s} \end{aligned}$$
   By then the higher modes are negligible.

**Answer:** the center is below 30 °C after about 5.3 s.
:::
:::

::: example
## A rod with insulated ends starts with $u = x$ on $0 < x < 1$. What temperature does it settle to?

::: solution
1. **Insulated ends.** They keep the heat in, so the rod settles to the average.
2. **The average.**
   $$\int_0^1 x\,dx = 0.5$$
   This is the n = 0 cosine term.

**Answer:** it settles to 0.5 everywhere.
:::
:::

::: example
## A 10 cm copper rod ($\alpha = 1.1 \times 10^{-4}$ m²/s) sits at 20 °C. One end is suddenly raised to 100 °C, and the other stays at 20 °C. When is the midpoint within 1 °C of its final temperature?

::: solution
1. **The steady state.** It's the straight line from 100 °C to 20 °C, which is 60 °C at the midpoint.
2. **Subtract it.** The remainder w starts as $-80(1 - x/L)$ and has zero ends, so it's a sine series.
3. **The sine series.** The sine coefficients of $1 - x/L$ are $\frac{2}{n\pi}$, so
   $$w = -\sum\frac{160}{n\pi}\sin\frac{n\pi x}{L}e^{-t/\tau_n}$$
   with $\tau_n = \frac{L^2}{n^2\pi^2\alpha}$.
4. **At the midpoint.** The n = 1 term is $-50.9e^{-t/\tau_1}$, with
   $$\begin{aligned} \tau_1 &= \frac{0.01}{\pi^2 \times 1.1 \times 10^{-4}}\ \text{s} \\ &= 9.21\ \text{s} \end{aligned}$$
   Even modes vanish there, and n = 3 decays 9 times faster.
5. **Solve for the time.**
   $$50.9e^{-t/\tau_1} = 1$$
   $$\begin{aligned} t &= 9.21\ln 50.9 \\ &= 36\ \text{s} \end{aligned}$$
6. **Check the next term.** By then the n = 3 term is about $10^{-14}$ °C, so the one-term answer is exact for practical purposes.

**Answer:** the midpoint is within 1 °C of its final 60 °C after about 36 s.
:::
:::

::: check
given: n = 1 | 3 | 5 | 7
answer: 4/(n*pi)
tolerance: 0.5%

## A rod starts uniformly at 1 with ends held at 0. What's the amplitude $b_n$ of mode n = {n}?

::: right
Right. $4/(n\pi)$ = {answer}.
:::

::: misses
- [2/(n*pi)] The integral gives $\frac{2}{L}\cdot\frac{2L}{n\pi}$ for odd n.
- [any] Not yet. $b_n = \frac{2}{L}\int_0^L\sin\frac{n\pi x}{L}dx$.
:::
:::

::: check
given: L = 0.02 | 0.05 | 0.2; a = 0.0001 | 0.00002
answer: L^2/(a*pi^2)
unit: s
tolerance: 0.5%

## What's the slowest time constant of a rod of length {L} m, diffusivity {a} m²/s, with both ends held at a fixed temperature?

::: right
Right. $L^2/(\alpha\pi^2)$ = {answer} s.
:::

::: misses
- [L^2/a] Include the $\pi^2$ from the first mode's wavenumber.
- [any] Not yet. $\tau = L^2/(\alpha\pi^2)$.
:::
:::

::: check
given: U = 40 | 60 | 100; r = 5 | 10 | 20; tau = 2 | 10
answer: tau*ln(4/pi*U/r)
unit: s
tolerance: 0.5%

## A rod's excess temperature starts uniformly at {U} K; its slow mode has τ = {tau} s. Using the first mode alone, when does the center's excess fall to {r} K?

::: right
Right. $\tau\ln\left(\frac{4U}{\pi r}\right)$ = {answer} s.
:::

::: misses
- [tau*ln(U/r)] The first mode starts at $\frac{4}{\pi}U$ at the center, not U.
- [any] Not yet. Solve $\frac{4}{\pi}Ue^{-t/\tau} = r$.
:::
:::

::: check
given: T1 = 20 | 0; T2 = 80 | 100; x = 0.25 | 0.5; L = 1
answer: T1 + (T2 - T1)*x/L
unit: °C
tolerance: 0.5%

## A rod of length {L} m has its ends held at {T1} °C and {T2} °C. In the steady state, what's the temperature at x = {x} m?

::: right
Right. A straight line between the ends: {answer} °C.
:::

::: misses
- [any] Not yet. The steady state satisfies $u'' = 0$.
:::
:::

::: check
given: a = 1 | 2 | 3
answer: a/2
tolerance: 0.5%

## A rod with insulated ends starts with $u = \given{a}x$ on $0 < x < 1$. What temperature does it settle to?

::: right
Right. The average, {answer}.
:::

::: misses
- [a] That's the hot end; the heat spreads out to the average.
- [any] Not yet. Insulated ends conserve the total heat.
:::
:::

::: check
kind: choice

## Why do only sines appear when both ends of the rod are held at 0?

- [ ] Sines are easier to integrate
- [x] Only $\sin(n\pi x/L)$ satisfies $X'' + \lambda X = 0$ with $X(0) = X(L) = 0$, apart from zero
- [ ] Cosines decay too slowly
- [ ] The initial condition is odd

::: misses
- [1] Convenience isn't the reason; the boundary conditions decide.
- [3] Cosines aren't zero at x = 0, so they break the condition.
- [4] The initial condition can be anything.
:::
:::

::: check
kind: parts
given: L = 0.05 | 0.1; a = 0.00011 | 0.000097; D = 40 | 80

## A rod {L} m long with diffusivity {a} m²/s has both ends at one temperature. One end is suddenly raised by {D} K.

::: part
answer: L^2/(pi^2*a)
unit: s
tolerance: 0.5%

### What is the time constant of the slowest mode?

::: misses
- [L^2/a] Include the $\pi^2$: the slowest mode is half a sine wave.
- [any] $\tau_1 = \frac{L^2}{\pi^2\alpha}$.
:::
:::

::: part
answer: L^2/(pi^2*a)*ln(2*D/pi)
unit: s
tolerance: 0.5%

### When is the midpoint within 1 K of its final temperature?

::: misses
- [L^2/(pi^2*a)*ln(4*D/pi)] That's for a uniform start; here the remainder starts as a straight line, with sine coefficients $\frac{2D}{n\pi}$.
- [any] Solve $\frac{2D}{\pi}e^{-t/\tau_1} = 1$.
:::
:::
:::

::: check
kind: derivation
vars: q = 1..10, k = 1..10, L = 0.5..2, x = 0..0.5

## A strip heated uniformly at q per unit volume, with conductivity k and both edges held at 0, satisfies $-ku'' = q$ on (0, L).

::: step
answer: q*x*(L - x)/(2*k)

### What is u(x)?
:::

::: step
answer: q*L^2/(8*k)

### What is the hottest temperature?
:::

::: right
Right. A parabola peaking at the middle, $\frac{qL^2}{8k}$: doubling the width quadruples the temperature rise.
:::
:::

::: explain
## Why does a heated rod's cooling time grow as the square of its length?

::: model
The rod's slowest mode is the single sine hump $\sin(\pi x/L)$, and the heat equation makes a mode with wavenumber k decay at the rate $\alpha k^2$. For that hump $k = \pi/L$, so its rate is $\alpha\pi^2/L^2$ and its time constant $L^2/(\alpha\pi^2)$. Physically, heat must diffuse about half the length to escape, and diffusion covers a distance d in a time proportional to $d^2/\alpha$, not to d, because it's a random walk rather than a steady flow. Doubling the length therefore quadruples the cooling time.
:::
:::

::: practice

::: check
given: n = 1 | 3 | 5 | 7 | 9 | 11 | 13
answer: 4/(n*pi)
tolerance: 0.5%

## $b_n$ for n = {n}, uniform initial 1?

::: misses
- [any] $4/(n\pi)$.
:::
:::

::: check
given: L = 0.03 | 0.1; a = 0.00001 | 0.0001
answer: L^2/(a*pi^2)
unit: s
tolerance: 0.5%

## Slowest τ, L = {L} m, α = {a}?

::: misses
- [any] $L^2/(\alpha\pi^2)$.
:::
:::

::: check
given: a = 1..20 int
answer: a/2
tolerance: 0.5%

## Final temperature, insulated, $u_0 = \given{a}x$ on [0, 1]?

::: misses
- [any] The average.
:::
:::
:::
