Parabolic partial differential equations govern many natural and financial systems, from the flow of heat through turbine blades and chemical concentration gradients to the diffusion of probability density in the Black-Scholes option pricing model.
The canonical 1D diffusion equation is formulated as:
where is the field variable and is the thermal diffusivity coefficient.
While explicit time integration methods (such as Forward Euler) are computationally straightforward, they suffer from a crippling stability constraint: any time step exceeding a tiny fraction of the spatial grid size causes exponential numerical explosion.
The Crank-Nicolson method, formulated by John Crank and Phyllis Nicolson in 1947, resolves this by employing a centered implicit-explicit finite difference scheme that is unconditionally stable for all step sizes.
1. Mathematical Formulation
Standard explicit schemes evaluate spatial derivatives exclusively at time step . Fully implicit backward schemes evaluate them exclusively at time step .
Crank-Nicolson computes the average of the central differences at time and :
Defining the dimensionless mesh ratio , we rearrange terms into unknowns at time on the left, and known values at time on the right:
2. Comparison of Finite Difference Schemes
| Scheme | Time Discretization | Truncation Error | Stability Criterion | Matrix Solve Required |
|---|---|---|---|---|
| Forward Euler (FTCS) | Explicit () | Conditionally stable () | No ( vector update) | |
| Backward Euler (BTCS) | Implicit () | Unconditionally stable () | Yes ( tridiagonal) | |
| Crank-Nicolson | Implicit Average () | Unconditionally stable () | Yes ( tridiagonal) |
3. Von Neumann Stability Analysis
To prove stability, we assume Fourier mode errors of the form , where is the amplification factor and is the spatial wave number.
Substituting into the Crank-Nicolson relation yields:
Using the trigonometric identity :
Because and , the denominator is strictly greater than or equal to the numerator. Therefore:
The amplification factor never exceeds unity regardless of the time step , mathematically proving unconditional stability.
4. Solving the Tridiagonal System in Time
Because each row depends only on nodes , , and , the coefficient matrix forms a tridiagonal system:
b_1 & c_1 & 0 & \dots & 0 \\ a_1 & b_2 & c_2 & \dots & 0 \\ 0 & a_2 & b_3 & \dots & 0 \\ \vdots & & \ddots & \ddots & \vdots \\ 0 & \dots & 0 & a_{N-1} & b_N \end{pmatrix} \begin{pmatrix} u_1^{n+1} \\ u_2^{n+1} \\ \vdots \\ u_N^{n+1} \end{pmatrix} = \begin{pmatrix} d_1 \\ d_2 \\ \vdots \\ d_N \end{pmatrix}$$ Rather than performing general Gaussian elimination which scales as $O(N^3)$, the **Thomas algorithm** (specialized tridiagonal Gaussian elimination) computes the forward sweep and back substitution in strictly $O(N)$ operations and $O(N)$ memory. <Callout type="tip" title="High-Performance Spatial Grids"> Because the tridiagonal matrix entries $a$, $b$, and $c$ are constant across time iterations for uniform meshes, the forward sweep coefficients $c'_i$ can be precomputed once, reducing every subsequent time step to a minimal linear-time memory streaming pass. </Callout> --- ## 5. Dual-Language Implementation <TabbedCodeBlock client:load title="Crank-Nicolson Tridiagonal Solvers" snippets={pdeSnippets} defaultFilenamePrefix="pde_solver" /> --- ## 6. Architectural Guidance - Use **Forward Euler** only for educational prototypes or when physical constraints naturally enforce $r \le 1/2$ without penalizing performance. - Use **Crank-Nicolson** whenever second-order temporal accuracy is required without worrying about artificial numerical oscillations on coarse spatial grids. - When solving non-linear diffusion equations (e.g. Navier-Stokes advection-diffusion), combine Crank-Nicolson with Newton-Raphson or Picard linearization per time step.