Heat Equation & Separation of Variables
Full step-by-step derivation • Three-case eigenvalue analysis • Fourier sine series
1. Setting Up the Heat Equation
Consider a thin, laterally insulated wire of length $L$ placed along the $x$-axis from $x = 0$ to $x = L$. Let $u(x,t)$ denote the temperature at position $x$ at time $t$. The heat equation is:
$$\frac{\partial u}{\partial t} = K\,\frac{\partial^2 u}{\partial x^2}, \qquad 0 < x < L,\quad t > 0$$where $K > 0$ is the thermal diffusivity of the material (a positive constant).
Initial and Boundary Conditions
To pin down a unique solution, the heat equation must be accompanied by:
• One initial condition (temperature at $t = 0$): $$u(x,0) = f(x), \qquad 0 < x < L$$
• Two boundary conditions (one at each end of the wire). The possibilities are:
(a) Homogeneous Dirichlet: $u(0,t) = 0$ and $u(L,t) = 0$ — both ends held at zero temperature.
(b) Non-homogeneous Dirichlet: $u(0,t) = T_1$, $u(L,t) = T_2$ — prescribed (non-zero) temperatures.
(c) Neumann: $u_x(0,t) = 0$, $u_x(L,t) = 0$ — insulated ends (no heat flux).
This page focuses on the simplest case: homogeneous Dirichlet boundary conditions. Once you understand this case completely, the others (covered in Section 6.3) follow the same logic with minor variations.
2. The Separation of Variables Idea
Assume the solution can be written as a product of two single-variable functions:
$$u(x,t) = P(x)\,Q(t)$$where $P(x)$ depends only on $x$ and $Q(t)$ depends only on $t$.
This ansatz is bold: we are assuming the space and time parts "separate". Remarkably, for linear PDEs like the heat equation, it works — and gives us infinitely many such solutions, which we can combine to satisfy arbitrary initial data.
Substituting into the Heat Equation
Compute the derivatives:
$$\frac{\partial u}{\partial t} = P(x)\,Q'(t), \qquad \frac{\partial^2 u}{\partial x^2} = P''(x)\,Q(t).$$Substituting both into $u_t = K u_{xx}$:
$$P(x)\,Q'(t) = K\,P''(x)\,Q(t).$$Divide both sides by $K\,P(x)\,Q(t)$ (assuming neither is zero):
$$\frac{Q'(t)}{K\,Q(t)} = \frac{P''(x)}{P(x)}.$$The left side depends only on $t$; the right side depends only on $x$. The only way this can hold for all $(x,t)$ is if both sides equal the same constant. We call that constant $-\lambda$:
$$\frac{Q'(t)}{K\,Q(t)} = \frac{P''(x)}{P(x)} = -\lambda.$$The choice of $-\lambda$ (rather than $+\lambda$) is a convention that makes the final eigenvalues $\lambda$ come out positive. It has no mathematical consequence — the equations would be equivalent with the opposite sign.
The Two ODEs
The single PDE has now been replaced by two ordinary differential equations, coupled through the common constant $\lambda$:
with the spatial boundary conditions inherited from $u(0,t) = u(L,t) = 0$:
$$P(0) = 0, \qquad P(L) = 0.$$This is a simple first-order linear ODE with solution $Q(t) = C\,e^{-K\lambda t}$ (once $\lambda$ is known).
Since $u(0,t) = P(0)\,Q(t) = 0$ must hold for all $t > 0$, we need $P(0) = 0$ (otherwise $Q(t) \equiv 0$ and the solution is trivially zero). Similarly $P(L) = 0$.
So the boundary conditions migrate from the PDE to the spatial ODE. This is why the spatial problem is a boundary value problem rather than an initial value problem.
3. The Three-Case Analysis of $\lambda$
We now solve the spatial BVP
$$P''(x) + \lambda\,P(x) = 0, \qquad P(0) = 0,\quad P(L) = 0.$$The form of the general solution depends on the sign of $\lambda$. There are exactly three possibilities — $\lambda < 0$, $\lambda = 0$, or $\lambda > 0$ — and we must analyse each one. Only one of them will produce non-trivial solutions compatible with the boundary conditions.
Step 1 — General solution. The ODE becomes
$$P''(x) - \alpha^2\,P(x) = 0,$$a second-order linear ODE with constant coefficients whose characteristic equation $r^2 - \alpha^2 = 0$ has real roots $r = \pm\alpha$. The general solution is
$$P(x) = C_1\,e^{\alpha x} + C_2\,e^{-\alpha x},$$or equivalently, using hyperbolic functions,
$$P(x) = A\,\cosh(\alpha x) + B\,\sinh(\alpha x).$$Step 2 — Apply $P(0) = 0$.
$$P(0) = A\,\cosh(0) + B\,\sinh(0) = A\cdot 1 + B\cdot 0 = A.$$So $A = 0$ and $P(x) = B\,\sinh(\alpha x)$.
Step 3 — Apply $P(L) = 0$.
$$P(L) = B\,\sinh(\alpha L) = 0.$$Since $\alpha > 0$ and $L > 0$, we have $\alpha L > 0$, and $\sinh(\alpha L) > 0$ (it is zero only at zero). Therefore the only way to satisfy this is $B = 0$.
Step 1 — General solution. The ODE becomes
$$P''(x) = 0,$$which we integrate twice to get
$$P(x) = C_1\,x + C_2.$$Step 2 — Apply $P(0) = 0$.
$$P(0) = C_1\cdot 0 + C_2 = C_2 = 0,$$so $P(x) = C_1\,x$.
Step 3 — Apply $P(L) = 0$.
$$P(L) = C_1\,L = 0 \implies C_1 = 0.$$Step 1 — General solution. The ODE becomes
$$P''(x) + \alpha^2\,P(x) = 0,$$whose characteristic equation $r^2 + \alpha^2 = 0$ has complex roots $r = \pm i\alpha$. The general real solution is
$$P(x) = A\,\cos(\alpha x) + B\,\sin(\alpha x).$$Step 2 — Apply $P(0) = 0$.
$$P(0) = A\,\cos(0) + B\,\sin(0) = A\cdot 1 + B\cdot 0 = A.$$So $A = 0$ and $P(x) = B\,\sin(\alpha x)$.
Step 3 — Apply $P(L) = 0$.
$$P(L) = B\,\sin(\alpha L) = 0.$$Here we have a choice: either $B = 0$ (trivial) or
$$\sin(\alpha L) = 0.$$We insist on a non-trivial solution, so we demand $\sin(\alpha L) = 0$. This happens precisely when
$$\alpha L = m\pi, \qquad m = 1,\,2,\,3,\,\ldots$$Hence $\alpha_m = \dfrac{m\pi}{L}$, and the eigenvalues are
$$\boxed{\;\lambda_m = \alpha_m^2 = \left(\frac{m\pi}{L}\right)^2,\quad m = 1, 2, 3, \ldots\;}$$The corresponding non-trivial solutions (the eigenfunctions) are
$$\boxed{\;P_m(x) = \sin\!\left(\frac{m\pi x}{L}\right),\quad m = 1, 2, 3, \ldots\;}$$| Case | General Solution of $P$ | Result under $P(0)=P(L)=0$ |
|---|---|---|
| I: $\lambda < 0$ | $A\cosh(\alpha x)+B\sinh(\alpha x)$ | Trivial only |
| II: $\lambda = 0$ | $C_1\,x + C_2$ | Trivial only |
| III: $\lambda > 0$ | $A\cos(\alpha x)+B\sin(\alpha x)$ | $\sin(m\pi x/L)$ for $m=1,2,\ldots$ |
4. Solving the Temporal ODE
Now that we know $\lambda = \lambda_m = (m\pi/L)^2$, the temporal equation becomes
$$Q'(t) + K\lambda_m\,Q(t) = 0,$$which is first-order linear and separable. Its solution is
$$Q_m(t) = C\,e^{-K\lambda_m t} = C\,\exp\!\left[-K\left(\frac{m\pi}{L}\right)^2 t\right].$$The decay rate $K(m\pi/L)^2$ is larger for higher modes ($m$). High-frequency (wiggly) components of the temperature profile die out fastest, while low-frequency (smooth) components persist. This is why heat conduction always smooths out an initial temperature profile over time.
5. Building the General Solution
For each $m = 1, 2, 3, \ldots$ we have a product solution:
$$u_m(x,t) = P_m(x)\,Q_m(t) = C_m\,\sin\!\left(\frac{m\pi x}{L}\right)\,\exp\!\left[-K\left(\frac{m\pi}{L}\right)^2 t\right].$$Because the heat equation is linear and homogeneous (and the boundary conditions are zero), any linear combination of solutions is again a solution. This is the principle of superposition. We therefore write the general solution as an infinite sum over all modes:
The constants $C_m$ are chosen to match the initial condition $u(x,0) = f(x)$.
Applying the Initial Condition — Fourier Sine Series
Setting $t = 0$ in the general solution:
$$u(x,0) = \sum_{m=1}^{\infty} C_m\,\sin\!\left(\frac{m\pi x}{L}\right) = f(x).$$This is exactly the Fourier sine series of $f(x)$ on the interval $[0, L]$. Using the orthogonality relation
$$\int_0^L \sin\!\left(\frac{m\pi x}{L}\right)\sin\!\left(\frac{n\pi x}{L}\right)dx = \begin{cases}0 & m \neq n\\ L/2 & m = n\end{cases}$$we can extract the coefficients: multiply both sides by $\sin(n\pi x/L)$ and integrate from $0$ to $L$:
If $f(x)$ is already written as a finite sine series — e.g., $f(x) = 3\sin(2\pi x/L) - 5\sin(7\pi x/L)$ — you can read the coefficients off directly by matching: $C_2 = 3$, $C_7 = -5$, all others zero. No integration needed.
6. Method Summary (The 5-Step Procedure)
- Separate variables. Assume $u(x,t) = P(x)Q(t)$ and substitute into $u_t = K u_{xx}$. Divide by $KPQ$ to obtain $Q'/(KQ) = P''/P = -\lambda$.
- Write the two ODEs with the spatial boundary conditions inherited from the PDE's BCs.
- Solve the spatial BVP by analysing all three cases $\lambda < 0$, $\lambda = 0$, $\lambda > 0$. For homogeneous Dirichlet BCs, only $\lambda > 0$ yields non-trivial solutions with eigenvalues $\lambda_m = (m\pi/L)^2$ and eigenfunctions $\sin(m\pi x/L)$.
- Solve the temporal ODE using the known $\lambda_m$: $Q_m(t) = C_m\,e^{-K\lambda_m t}$.
- Superpose and fit the initial condition: write $u = \sum C_m P_m Q_m$ and determine $C_m$ from $u(x,0) = f(x)$, either by comparison (if $f$ is already a sine sum) or by the Fourier sine coefficient formula.
Worked Examples
Step 1 — Read parameters. $K = 7$, $L = \pi$. The general solution is
$$u(x,t) = \sum_{m=1}^{\infty} C_m\,\sin(mx)\,e^{-7 m^2 t}.$$(Note that $m\pi/L = m\pi/\pi = m$, which is why the arguments of the sines are just $mx$.)
Step 2 — Apply IC by comparison. At $t=0$:
$$\sum_{m=1}^{\infty} C_m\,\sin(mx) = 3\sin(2x) - 6\sin(5x).$$Matching coefficients: $C_2 = 3$, $C_5 = -6$, and $C_m = 0$ for all other $m$.
Step 1 — General form. With $K=4$, $L=4$:
$$u(x,t) = \sum_{m=1}^{\infty} C_m\,\sin\!\left(\frac{m\pi x}{4}\right)\,e^{-4(m\pi/4)^2 t} = \sum_{m=1}^{\infty} C_m\,\sin\!\left(\frac{m\pi x}{4}\right)\,e^{-(m\pi)^2 t/4}.$$Step 2 — Match the IC. We need $\sum C_m \sin(m\pi x/4) = 5\sin(\pi x)$. Setting $m\pi/4 = \pi$ gives $m = 4$, so $C_4 = 5$, all other $C_m = 0$.
The initial condition is a polynomial, not a sine sum, so we must compute the Fourier sine coefficients by integration.
Step 1 — Set up the coefficient formula. With $L = 4$:
$$C_m = \frac{2}{4}\int_0^4 (x-1)\,\sin\!\left(\frac{m\pi x}{4}\right)\,dx = \frac{1}{2}\int_0^4 (x-1)\,\sin\!\left(\frac{m\pi x}{4}\right)\,dx.$$Step 2 — Integration by parts. Let $u = x - 1$, $dv = \sin(m\pi x/4)\,dx$, so $du = dx$, $v = -\dfrac{4}{m\pi}\cos(m\pi x/4)$. Then
$$\int_0^4 (x-1)\sin\!\left(\frac{m\pi x}{4}\right)dx = \left[-\frac{4(x-1)}{m\pi}\cos\!\left(\frac{m\pi x}{4}\right)\right]_0^4 + \frac{4}{m\pi}\int_0^4 \cos\!\left(\frac{m\pi x}{4}\right)dx.$$The remaining integral is
$$\frac{4}{m\pi}\cdot\left[\frac{4}{m\pi}\sin\!\left(\frac{m\pi x}{4}\right)\right]_0^4 = 0$$because $\sin(m\pi) = 0$ and $\sin(0) = 0$.
Evaluating the boundary term:
$$\left[-\frac{4(x-1)}{m\pi}\cos\!\left(\frac{m\pi x}{4}\right)\right]_0^4 = -\frac{4\cdot 3}{m\pi}\cos(m\pi) + \frac{4\cdot(-1)}{m\pi}\cdot 1 = -\frac{12(-1)^m}{m\pi} - \frac{4}{m\pi}.$$Therefore
$$C_m = \frac{1}{2}\left[-\frac{12(-1)^m + 4}{m\pi}\right] = -\frac{2}{m\pi}\left[1 + 3(-1)^m\right].$$For $m$ even: $(-1)^m = 1$, so $C_m = -\dfrac{2}{m\pi}(1+3) = -\dfrac{8}{m\pi}$.
For $m$ odd: $(-1)^m = -1$, so $C_m = -\dfrac{2}{m\pi}(1-3) = \dfrac{4}{m\pi}$.
All non-zero, as expected for a non-symmetric initial condition.
Step 1 — Fourier sine coefficients.
$$C_m = \frac{2}{L}\int_0^L 20\,\sin\!\left(\frac{m\pi x}{L}\right)dx = \frac{40}{L}\cdot\left[-\frac{L}{m\pi}\cos\!\left(\frac{m\pi x}{L}\right)\right]_0^L = \frac{40}{m\pi}\left[1 - (-1)^m\right].$$Step 2 — Simplify.
For $m$ even: $C_m = 0$.
For $m$ odd: $C_m = \dfrac{80}{m\pi}$.
Physical interpretation: Starting from a uniform temperature $20$, the wire is held at zero at both ends. Heat flows out through the boundaries and the interior cools down, approaching zero everywhere as $t \to \infty$. The odd-$m$ eigenfunctions (symmetric about $x = L/2$) survive because they match the symmetry of the constant initial data.
📝 Exam-Style Practice Problems
These problems match the style and difficulty of past exam questions on separation of variables for the heat equation. Every problem below states its PDE, its boundary conditions and its initial condition — you need all three. Click a problem to reveal the full solution.
Solution
Step 1: Write the general solution. Here $K = 3$ and $L = 2$, so the eigenvalues are $\lambda_m = (m\pi/2)^2 = m^2\pi^2/4$ and
$$u(x,t) = \sum_{m=1}^{\infty} C_m \sin\!\left(\frac{m\pi x}{2}\right)e^{-3m^2\pi^2 t/4}.$$Step 2: Identify the mode index of each term in $f$. The eigenfunctions are $\sin(m\pi x/2)$.
- $\sin(\pi x/2)$ needs $\dfrac{m\pi}{2} = \dfrac{\pi}{2} \Rightarrow m = 1$.
- $\sin(3\pi x)$ needs $\dfrac{m\pi}{2} = 3\pi \Rightarrow m = 6$.
Step 3: Read off the coefficients (comparison method). No integration is required because $f$ is already a finite sine sum:
$$C_1 = 4, \qquad C_6 = -2, \qquad C_m = 0 \text{ otherwise.}$$Step 4: Attach the correct decay factors.
$m = 1$: $\;3\lambda_1 = 3\cdot\dfrac{\pi^2}{4} = \dfrac{3\pi^2}{4}$. $m = 6$: $\;3\lambda_6 = 3\cdot\dfrac{36\pi^2}{4} = 27\pi^2$.
Final Solution:
$$\boxed{u(x,t) = 4\,e^{-3\pi^2 t/4}\sin\!\left(\frac{\pi x}{2}\right) - 2\,e^{-27\pi^2 t}\sin(3\pi x)}$$Solution
Step 1: General solution. With $K = 2$, $L = 1$:
$$u(x,t) = \sum_{m=1}^{\infty} C_m \sin(m\pi x)\,e^{-2m^2\pi^2 t}.$$Step 2: Set up the Fourier sine coefficients. $f$ is a polynomial, not a finite sine sum, so we must integrate:
$$C_m = \frac{2}{1}\int_0^1 x(1-x)\sin(m\pi x)\,dx = 2\int_0^1 (x - x^2)\sin(m\pi x)\,dx.$$Step 3: Integrate by parts twice. With $u = x - x^2$, $dv = \sin(m\pi x)dx$, $v = -\dfrac{\cos(m\pi x)}{m\pi}$:
$$\int_0^1 (x-x^2)\sin(m\pi x)dx = \underbrace{\left[-\frac{(x-x^2)\cos(m\pi x)}{m\pi}\right]_0^1}_{=\,0\ \text{since } x-x^2 = 0 \text{ at both ends}} + \frac{1}{m\pi}\int_0^1 (1-2x)\cos(m\pi x)\,dx.$$A second integration by parts on the remaining integral gives
$$\int_0^1 (1-2x)\cos(m\pi x)\,dx = \left[\frac{(1-2x)\sin(m\pi x)}{m\pi}\right]_0^1 + \frac{2}{m\pi}\int_0^1 \sin(m\pi x)\,dx = 0 + \frac{2}{m^2\pi^2}\bigl[1 - (-1)^m\bigr].$$Step 4: Assemble.
$$C_m = 2\cdot\frac{1}{m\pi}\cdot\frac{2\bigl[1-(-1)^m\bigr]}{m^2\pi^2} = \frac{4\bigl[1 - (-1)^m\bigr]}{m^3\pi^3}.$$So $C_m = 0$ for even $m$ and $C_m = \dfrac{8}{m^3\pi^3}$ for odd $m$.
Final Solution:
$$\boxed{u(x,t) = \sum_{\substack{m=1\\ m\ \text{odd}}}^{\infty}\frac{8}{m^3\pi^3}\,\sin(m\pi x)\,e^{-2m^2\pi^2 t}}$$Solution
Step 1: Simplify $f$ with the double-angle identity.
$$\sin(x)\cos(x) = \tfrac{1}{2}\sin(2x).$$Step 2: General solution. With $K = 1$ and $L = \pi$, the eigenfunctions are $\sin(mx)$ and $\lambda_m = m^2$:
$$u(x,t) = \sum_{m=1}^{\infty} C_m \sin(mx)\,e^{-m^2 t}.$$Step 3: Compare. Matching $\sum C_m\sin(mx) = \tfrac{1}{2}\sin(2x)$ gives $C_2 = \tfrac{1}{2}$ and every other $C_m = 0$.
Step 4: Attach the decay factor $e^{-\lambda_2 t} = e^{-4t}$.
Final Solution:
$$\boxed{u(x,t) = \tfrac{1}{2}\,e^{-4t}\,\sin(2x)}$$Practice Problems
Test your understanding with these multiple-choice questions. Click a choice to see if you're correct.
Q1: For $P''(x) + \lambda P(x) = 0$ with $P(0) = P(L) = 0$, which case of the separation constant produces non-trivial solutions?
Answer: (C). For $\lambda < 0$ the solution is a combination of $\cosh$ and $\sinh$, which can only vanish at two distinct points if it is identically zero. For $\lambda = 0$ the solution is a straight line through both $(0,0)$ and $(L,0)$, hence zero. Only $\lambda > 0$ gives $\sin(\alpha x)$ with $\alpha L = m\pi$.
Q2: For homogeneous Dirichlet BCs on $0 < x < 3$, what are the eigenvalues?
Answer: (B). $\lambda_m = \left(\dfrac{m\pi}{L}\right)^2$ with $L = 3$, giving $\lambda_m = \dfrac{m^2\pi^2}{9}$. Choice (A) is $\alpha_m$, not $\lambda_m = \alpha_m^2$.
Q3: Solve $u_t = 5u_{xx}$ on $0 < x < \pi$ with $u(0,t) = u(\pi,t) = 0$ and $u(x,0) = 7\sin(3x)$.
Answer: (D). With $L = \pi$ the mode is $m = 3$, so $\lambda_3 = 3^2 = 9$ and the decay rate is $K\lambda_3 = 5 \cdot 9 = 45$. Check: $u_t = -45\cdot 7e^{-45t}\sin 3x$ and $5u_{xx} = 5(-9)\cdot 7e^{-45t}\sin 3x = -45\cdot 7e^{-45t}\sin 3x$ ✓
Q4: Which formula gives the coefficients $C_m$ in $u(x,t) = \sum C_m \sin(m\pi x/L)e^{-K(m\pi/L)^2 t}$ when $u(x,0) = f(x)$?
Answer: (C). Orthogonality gives $\int_0^L \sin^2(m\pi x/L)dx = L/2$, so dividing by $L/2$ — i.e. multiplying by $2/L$ — produces the sine coefficient. Choice (B) is the cosine formula, which belongs to Neumann problems.
Q5: For $u_t = K u_{xx}$ with fixed zero ends, which statement about the modes is correct as $t$ grows?
Answer: (C). The decay factor is $e^{-K(m\pi/L)^2 t}$, whose exponent grows like $m^2$. The $m=10$ mode decays $100$ times faster than the $m=1$ mode, so wiggles die first and the temperature profile smooths. Choice (D) describes the wave equation, whose temporal ODE is second order.
Q6: For the constant initial temperature $f(x) = 1$ on $0 < x < L$ with homogeneous Dirichlet BCs, which sine coefficients are non-zero?
Answer: (B). $C_m = \dfrac{2}{L}\displaystyle\int_0^L \sin\!\left(\frac{m\pi x}{L}\right)dx = \dfrac{2\bigl[1-(-1)^m\bigr]}{m\pi}$. For even $m$ the bracket is $0$; for odd $m$ it is $2$, giving $C_m = 4/(m\pi)$.