TExcelTAD
Home › Numerical Methods › Stiff Equations and Implicit Methods

Stiff Equations

Some ODEs contain processes on very different time scales: a fast reaction that settles in microseconds next to a slow one that evolves over hours. Once the fast part has decayed, the solution is smooth, yet explicit methods are still forced to take tiny steps, because larger ones are unstable. Such problems are called stiff, and they need implicit methods.

A simple stiff problem

u′=−1000(u−cos⁡t)−sin⁡tu' = -1000(u - \cos t) - \sin t, u(0)=0u(0) = 0. The solution is u=cos⁡t−e−1000tu = \cos t - e^{-1000t}: after a fast transient of a few milliseconds it simply follows cos⁡t\cos t. Euler's method needs h<21000h < \frac{2}{1000} for stability no matter how smooth the solution is.

python · try it yourself
import numpy as np

lam = 1000.0
f = lambda t, u: -lam * (u - np.cos(t)) - np.sin(t)
exact = lambda t: np.cos(t) - np.exp(-lam * t)

for h in (0.0019, 0.0021, 0.01):
    n = int(round(2 / h)); u = 0.0
    with np.errstate(over="ignore", invalid="ignore"):
        for i in range(n):
            u = u + h * f(i * h, u)
    print(f"explicit Euler, h = {h}: u(2) = {u:.4e}, exact {exact(n * h):.4f}")

# backward Euler: u_{i+1} = u_i + h f(t_{i+1}, u_{i+1}); f is linear in u, so solve directly
for h in (0.01, 0.1, 0.5):
    n = int(round(2 / h)); u = 0.0
    for i in range(n):
        t1 = (i + 1) * h
        u = (u + h * (lam * np.cos(t1) - np.sin(t1))) / (1 + h * lam)
    print(f"backward Euler, h = {h}: u(2) = {u:.4f}, exact {exact(n * h):.4f}")
explicit Euler, h = 0.0019: u(2) = -4.1678e-01, exact -0.4168
explicit Euler, h = 0.0021: u(2) = -2.5459e+39, exact -0.4154
explicit Euler, h = 0.01: u(2) = -7.0551e+190, exact -0.4161
backward Euler, h = 0.01: u(2) = -0.4161, exact -0.4161
backward Euler, h = 0.1: u(2) = -0.4161, exact -0.4161
backward Euler, h = 0.5: u(2) = -0.4161, exact -0.4161

Backward Euler is accurate with steps 250 times larger than explicit Euler's stability limit.

Stiffness and eigenvalues

For a system u′=f(u)\mathbf{u}' = \mathbf{f}(\mathbf{u}) the local behaviour is governed by the eigenvalues of the Jacobian J=∂f∂uJ = \frac{\partial\mathbf{f}}{\partial\mathbf{u}}. A problem is stiff when some eigenvalues have large negative real parts (fast, decayed modes) while the solution itself varies slowly. The stiffness ratio max⁡∣Re⁡λ∣min⁡∣Re⁡λ∣\frac{\max\lvert\operatorname{Re}\lambda\rvert}{\min\lvert\operatorname{Re}\lambda\rvert} can be 10610^6 or more in chemistry and circuit simulation.

A-stability

Applied to u′=λuu' = \lambda u, backward Euler gives ui+1=11−hλuiu_{i+1} = \frac{1}{1 - h\lambda}u_i, which decays for every h>0h > 0 when Re⁡λ<0\operatorname{Re}\lambda < 0. A method with this property is A-stable. No explicit method is A-stable; backward Euler, the trapezoid rule and BDF2 are. (Dahlquist's barrier: A-stable linear multistep methods have order at most 2; BDF3 to BDF6 are stable in large wedges, enough in practice.)

Implicit methods need nonlinear solves

For nonlinear f\mathbf{f}, each implicit step solves ui+1−hf(ti+1,ui+1)−ui=0\mathbf{u}_{i+1} - h\mathbf{f}(t_{i+1}, \mathbf{u}_{i+1}) - \mathbf{u}_i = \mathbf{0} by Newton's method (Newton's Method for Systems), with the Jacobian I−hJI - hJ. Production codes reuse Jacobians and factorizations across steps to keep this cheap.

The Robertson chemical kinetics problem

A classic stiff test: three species with rate constants spanning nine orders of magnitude.

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp

def robertson(t, y):
    y1, y2, y3 = y
    return [-0.04 * y1 + 1e4 * y2 * y3,
            0.04 * y1 - 1e4 * y2 * y3 - 3e7 * y2**2,
            3e7 * y2**2]

for method in ("RK45", "BDF", "Radau", "LSODA"):
    sol = solve_ivp(robertson, (0, 100), [1, 0, 0], method=method, rtol=1e-6, atol=1e-10)
    print(f"{method:6s}: success {sol.success}, steps {len(sol.t) - 1:5d}, evaluations {sol.nfev:6d}, y1(100) = {sol.y[0, -1]:.6f}")
RK45  : success True, steps 104142, evaluations 729668, y1(100) = 0.617235
BDF   : success True, steps   163, evaluations    431, y1(100) = 0.617236
Radau : success True, steps    88, evaluations    726, y1(100) = 0.617235
LSODA : success True, steps   240, evaluations    496, y1(100) = 0.617234

The explicit RK45 takes over 100,000 steps (all dictated by stability, not accuracy), while BDF, Radau and LSODA need between about 90 and 240.

In software

  • solve_ivp(method="BDF"), "Radau" (implicit Runge-Kutta, order 5), "LSODA" (detects stiffness and switches). Supplying jac= (or a sparsity pattern jac_sparsity=) speeds them up greatly.
  • If an explicit solver takes absurdly many steps on a smooth-looking solution, suspect stiffness and switch methods.
  • Stiff ODEs arise from discretizing diffusion: the semi-discrete heat equation is stiff, which is why implicit time stepping is used for it (The Heat Equation: Implicit Methods).

Exercises

Exercise 1: Stability limit

The Jacobian of a system has eigenvalues −1-1, −10-10 and −105-10^5. What is the largest stable step for explicit Euler?

Answer

h<2×10−5h < 2 \times 10^{-5}.

Solution

The fastest mode sets the limit: h<2105h < \frac{2}{10^5}. To reach t=10t = 10, explicit Euler needs over 500,000 steps.

Exercise 2: Backward Euler's amplification factor

What is the amplification factor of backward Euler for hλ=−100h\lambda = -100? Of explicit Euler?

Answer

1101\frac{1}{101} and −99-99.

Solution

Backward: 11−hλ=1101\frac{1}{1 - h\lambda} = \frac{1}{101} (strong damping, correct qualitatively). Explicit: 1+hλ=−991 + h\lambda = -99 (explosive oscillation).

Exercise 3: Trapezoid versus backward Euler (code)

For u′=−106(u−1)u' = -10^6(u - 1), u(0)=0u(0) = 0, take 10 steps of h=0.1h = 0.1 with backward Euler and with the trapezoid rule ui+1=ui+h2(fi+fi+1)u_{i+1} = u_i + \frac{h}{2}(f_i + f_{i+1}). What happens to the transient?

Answer

Backward Euler reaches 11 at once; the trapezoid rule's error flips sign every step and decays only very slowly (factor about −1-1).

Solution
python · try it yourself
lam, h = -1e6, 0.1
ube = utr = 0.0
for _ in range(10):
    ube = (ube - h * lam) / (1 - h * lam)                        # f = lam (u - 1)
    utr = (utr * (1 + h * lam / 2) - h * lam) / (1 - h * lam / 2)
print(f"backward Euler error {ube - 1:.2e}, trapezoid error {utr - 1:.6f}")
backward Euler error 0.00e+00, trapezoid error -0.999600

The trapezoid rule is A-stable but its amplification factor tends to −1-1 for very stiff modes (it is not L-stable), so transients ring. Backward Euler and BDF damp them.

Test yourself

A problem is stiff when…

  1. the solution blows up
  2. fast decaying modes force an explicit method to take steps far smaller than accuracy needs
  3. the equation is nonlinear
  4. the solution oscillates

Which method is A-stable?

  1. explicit Euler
  2. RK4
  3. backward Euler
  4. Adams-Bashforth 2

Implicit methods for nonlinear systems need at each step…

  1. nothing extra
  2. a nonlinear solve, usually by Newton's method
  3. a matrix exponential
  4. an FFT