AnyLearn
All lessons
Mathadvanced

Stiff Equations, Stability Regions, and Adaptive Step Size

Why an ODE solver can blow up at step sizes accuracy would never demand. Learn stability regions on the test equation, what makes a problem stiff, how implicit methods and A-stability fix it at the cost of Newton solves, how BDF and Radau escape Dahlquist's barrier, and how adaptive solvers choose each step.

Updated · AI-authored, review-gated · how lessons are made

Progress1 / 12

Two different limits on the step size

The lesson What a Differential Equation Says compared Euler and RK4 on a spring and found RK4 far more accurate for the same step. That comparison was about accuracy. A step size can be limited by something else entirely.

First, the accuracy vocabulary. A method of order pp makes a local error of order hp+1h^{p+1} in one step; over a fixed time interval those add up across about 1/h1/h steps to a global error of order hph^p, the standard result in Hairer, Nørsett and Wanner's Solving Ordinary Differential Equations I.

MethodOrder ppLocal errorGlobal errorff evaluations per step
Forward Euler1O(h2)O(h^2)O(h)O(h)1
Heun (RK2)2O(h3)O(h^3)O(h2)O(h^2)2
Classical RK44O(h5)O(h^5)O(h4)O(h^4)4

Key idea: order tells you how error shrinks as h→0h \to 0. It says nothing about what happens at the hh you actually use. For some equations, the method blows up at step sizes far smaller than accuracy would ever demand. That second limit is stability, and it is what this lesson is about.

Sign in free to save your progress and earn certificates.

Full lesson text

All 12 steps on one page, for reading, reference, and search.

Show

1. Two different limits on the step size

The lesson What a Differential Equation Says compared Euler and RK4 on a spring and found RK4 far more accurate for the same step. That comparison was about accuracy. A step size can be limited by something else entirely.

First, the accuracy vocabulary. A method of order pp makes a local error of order hp+1h^{p+1} in one step; over a fixed time interval those add up across about 1/h1/h steps to a global error of order hph^p, the standard result in Hairer, Nørsett and Wanner's Solving Ordinary Differential Equations I.

MethodOrder ppLocal errorGlobal errorff evaluations per step
Forward Euler1O(h2)O(h^2)O(h)O(h)1
Heun (RK2)2O(h3)O(h^3)O(h2)O(h^2)2
Classical RK44O(h5)O(h^5)O(h4)O(h^4)4

Key idea: order tells you how error shrinks as h→0h \to 0. It says nothing about what happens at the hh you actually use. For some equations, the method blows up at step sizes far smaller than accuracy would ever demand. That second limit is stability, and it is what this lesson is about.

2. The test equation and the stability region

Stability is analysed on the simplest decaying equation, y′=λyy' = \lambda y with Re⁡λ<0\operatorname{Re}\lambda < 0, whose exact solution shrinks every step. Near any equilibrium, a smooth system behaves like a set of these, one per eigenvalue of its Jacobian. Forward Euler gives

yn+1=yn+hλ yn=R(hλ) yn,R(z)=1+zy_{n+1} = y_n + h\lambda\, y_n = R(h\lambda)\, y_n, \qquad R(z) = 1 + z

The numerical solution decays only if ∣R(hλ)∣≤1|R(h\lambda)| \le 1. For forward Euler that is the disc of radius 1 centred at −1-1 in the complex plane, so for real negative λ\lambda:

h≤2∣λ∣h \le \frac{2}{|\lambda|}

Definition: the stability function R(z)R(z) is the factor one step multiplies yy by on the test equation with z=hλz = h\lambda. The stability region is the set of zz with ∣R(z)∣≤1|R(z)| \le 1. Every eigenvalue of the problem, times hh, must lie inside it.

Every explicit method has a bounded stability region, because its R(z)R(z) is a polynomial and polynomials grow without limit. Classical RK4's region reaches only to about z=−2.79z = -2.79 on the real axis, per Hairer and Wanner's Solving Ordinary Differential Equations II: bigger than Euler's, still bounded.

3. Stiffness: when stability, not accuracy, sets the step

A problem is stiff when it contains a component that decays much faster than the behaviour you care about. The fast component dies out almost immediately, but its eigenvalue still sits in the problem, and an explicit method must keep hλh\lambda inside its stability region for the rest of the run.

Take y′=−1000 (y−cos⁡t)y' = -1000\,(y - \cos t), y(0)=0y(0) = 0. The solution leaps onto the curve cos⁡t\cos t within a few thousandths of a time unit, then follows it smoothly. Describing cos⁡t\cos t accurately would need perhaps tens of steps per unit time. Forward Euler, with λ=−1000\lambda = -1000, is unstable for any h>2/1000=0.002h > 2/1000 = 0.002, for the entire interval, long after the transient is gone.

Typical sources of stiffness:

  • Chemical kinetics, with reactions whose rates differ by many orders of magnitude.
  • Spatially discretised diffusion, where the fastest eigenvalue grows like 1/Δx21/\Delta x^2 as the grid is refined.
  • Circuits mixing fast and slow time constants, and control systems with high-gain feedback.

Stiffness is a property of the problem together with the time span: integrate only over the transient and it is not stiff at all.

4. Crossing the stability boundary

Forward Euler against backward Euler, which evaluates the slope at the new point instead of the old one:

Predict first

Forward Euler on y′=−1000(y−cos⁡t)y' = -1000(y - \cos t) has stability limit h=0.002h = 0.002. The exact value at t=0.2t = 0.2 is about 0.98. What does it return with h=0.0016h = 0.0016, and with h=0.0025h = 0.0025?

# y' = -1000 (y - cos t), y(0) = 0: a fast decay onto a slow curve
import numpy as np
lam, T = -1000.0, 0.2

def euler(h, implicit):
    y, t = 0.0, 0.0
    for _ in range(int(round(T / h))):
        if implicit:   # backward Euler: solve y1 = y + h*lam*(y1 - cos(t+h))
            y = (y - h * lam * np.cos(t + h)) / (1 - h * lam)
        else:          # forward Euler
            y = y + h * lam * (y - np.cos(t))
        t += h
    return y

exact = (lam**2 * np.cos(T) - lam * np.sin(T)) / (lam**2 + 1)   # transient long gone
print(f"exact y(0.2) = {exact:.6f}")
for h in (0.0016, 0.0025, 0.02):
    print(f"h = {h}:  forward {euler(h, False):12.4e}   backward {euler(h, True):.6f}")
exact y(0.2) = 0.980264
h = 0.0016:  forward   9.8027e-01   backward 0.980263
h = 0.0025:  forward  -1.2226e+14   backward 0.980263
h = 0.02:  forward  -6.1311e+12   backward 0.980254

Backward Euler stays accurate at every step size, including h=0.02h = 0.02, ten times beyond forward Euler's limit. Nothing about the smooth solution changed between the rows; only the method's stability did.

5. Implicit methods and A-stability

Backward Euler defines the new value implicitly, yn+1=yn+hf(tn+1,yn+1)y_{n+1} = y_n + h f(t_{n+1}, y_{n+1}). On the test equation that gives

R(z)=11−z,∣R(z)∣<1 for every z with Re⁡z<0R(z) = \frac{1}{1 - z}, \qquad |R(z)| < 1 \text{ for every } z \text{ with } \operatorname{Re} z < 0

Definition: a method is A-stable if its stability region contains the whole left half-plane, so no decaying component can ever blow up, whatever hh. It is L-stable if, in addition, R(z)→0R(z) \to 0 as z→−∞z \to -\infty, so very fast components are damped out in a single step.

MethodR(z)R(z)A-stableL-stableOrder
Forward Euler1+z1 + zNoNo1
Classical RK4degree-4 polynomialNoNo4
Backward Euler1/(1−z)1/(1 - z)YesYes1
Trapezoidal rule(1+z/2)/(1−z/2)(1 + z/2)/(1 - z/2)YesNo2

The trapezoidal rule's R(z)R(z) tends to −1-1 for very stiff components, so they are not damped but flip sign every step, which shows up as persistent small oscillations. That is why L-stable methods are preferred for strongly stiff problems.

6. What one implicit step actually does

An implicit step is a root-finding problem whose Newton iterations need linear solves: the first three lessons of this path, nested inside one time step.

sequenceDiagram
  participant Integrator
  participant Newton
  participant LinearSolver
  Integrator->>Newton: find Y with Y minus y_n minus h f(Y) equal to zero
  Newton->>LinearSolver: factor I minus h J once
  loop until the update is small
    Newton->>LinearSolver: solve for the correction
    LinearSolver-->>Newton: correction
  end
  Newton-->>Integrator: converged Y, or failure
  Integrator->>Integrator: estimate the error, accept or shrink h

7. The price of implicitness, and how solvers pay it

For a nonlinear system y′=f(y)\mathbf{y}' = \mathbf{f}(\mathbf{y}) in nn unknowns, each backward Euler step must solve Y−yn−h f(Y)=0\mathbf{Y} - \mathbf{y}_n - h\,\mathbf{f}(\mathbf{Y}) = \mathbf{0}. Newton's method on it needs the matrix

I−hJ,J=∂f∂yI - hJ, \qquad J = \frac{\partial \mathbf{f}}{\partial \mathbf{y}}

and an O(n3)O(n^3) dense factorisation, or a sparse or iterative solve when nn is large. Production codes cut this cost in three ways:

  1. Simplified Newton. Factor I−hJI - hJ once and reuse it for every Newton iteration, and for many steps, refactoring only when hh changes a lot or convergence slows.
  2. Reuse the Jacobian. JJ changes slowly along a smooth solution, so it is recomputed rarely.
  3. Accept slower convergence. Simplified Newton converges linearly instead of quadratically, which is cheaper overall than refactoring every iteration.

SciPy's solve_ivp reports this bookkeeping directly: its documentation defines nfev as evaluations of the right-hand side, njev as Jacobian evaluations and nlu as LU decompositions.

In practice: pass the Jacobian through the jac argument, and its sparsity pattern through jac_sparsity for large systems. Otherwise it is approximated by finite differences, at the cost of extra evaluations of ff.

8. Dahlquist's barrier, BDF, and Radau

Higher order and A-stability pull against each other. Dahlquist's second barrier (1963) states that an A-stable linear multistep method has order at most 2, and among those the trapezoidal rule has the smallest error constant, as presented in Hairer and Wanner's Solving Ordinary Differential Equations II. Practical stiff solvers get around it in two ways.

FamilyTypeOrdersStability, per Hairer and Wanner IISciPy
BDFLinear multistep1 to 5 in SciPyOrders 1 and 2 A-stable; orders 3 to 6 stable in a wedge around the negative real axis (about 86, 73, 52 and 18 degrees)method="BDF"
Radau IIAImplicit Runge-Kutta5A-stable and L-stablemethod="Radau"

BDF accepts a slightly smaller region in exchange for high order at one function evaluation per Newton iteration. Most stiff eigenvalues lie near the negative real axis, where the wedge covers them. SciPy documents its BDF as variable order, 1 to 5.

Radau IIA is not a multistep method, so the barrier does not apply. It keeps A- and L-stability at order 5, paying with a larger nonlinear system per step, three stages solved together.

9. Measured: explicit against implicit on a stiff problem

Three of SciPy's solvers on the stiff test problem, integrated to t=10t = 10 with the same tolerances:

import numpy as np
from scipy.integrate import solve_ivp

lam = -1000.0
f = lambda t, y: lam * (y - np.cos(t))
T = 10.0
exact = (lam**2 * np.cos(T) - lam * np.sin(T)) / (lam**2 + 1)

for method in ("RK45", "Radau", "BDF"):
    sol = solve_ivp(f, (0, T), [0.0], method=method, rtol=1e-6, atol=1e-9)
    err = abs(sol.y[0, -1] - exact)
    print(f"{method:5s} steps {sol.t.size - 1:5d}  nfev {sol.nfev:6d}  "
          f"njev {sol.njev:3d}  nlu {sol.nlu:4d}  error {err:.1e}")
RK45  steps  3587  nfev  21548  njev   0  nlu    0  error 4.5e-07
Radau steps    81  nfev    624  njev   3  nlu   76  error 2.1e-08
BDF   steps   209  nfev    478  njev   7  nlu   47  error 2.1e-09
Right-hand-side evaluations to integrate y' = -1000(y - cos t) to t = 10
evaluations of f05k10k15k20k25k21.55k624478RK45 (explicit)Radau (implicit)BDF (implicit)
Source: Computed with the code in this lesson, SciPy 1.17 solve_ivp, rtol=1e-6, atol=1e-9

RK45's average step, 10/3587≈0.002810/3587 \approx 0.0028, is pinned near the edge of its stability region the whole way, even though the solution is a smooth cosine. Its error is no better for all that work. The implicit methods take 81 and 209 steps, set by accuracy alone, and use 35 to 45 times fewer function evaluations. SciPy's documentation gives the matching rule: explicit Runge-Kutta methods for non-stiff problems, Radau or BDF for stiff ones.

10. Adaptive step size: estimate the error you just made

A fixed step wastes work wherever the solution is easy and loses accuracy wherever it is hard. Adaptive solvers choose hh every step from an estimate of the local error.

The standard estimate comes from an embedded pair: two Runge-Kutta formulas of orders pp and p−1p-1 that share the same stages, so the second answer is nearly free. Their difference estimates the local error of the lower-order one. SciPy's documentation for RK45 says the error is controlled assuming the accuracy of the fourth-order method while steps are taken with the fifth-order formula, citing Dormand and Prince. The estimate is compared against a per-component scale, which the solve_ivp documentation gives as atol + rtol * abs(y), to form a scaled error err\text{err}, with err≤1\text{err} \le 1 meaning acceptable.

The next step size then follows the controller described in Hairer, Nørsett and Wanner, Solving Ordinary Differential Equations I, section II.4, with qq the lower order of the pair:

hnew=h⋅min⁡ ⁣(facmax⁡,  max⁡ ⁣(facmin⁡,  fac⋅err−1/(q+1)))h_{\text{new}} = h \cdot \min\!\left(\text{fac}_{\max},\; \max\!\left(\text{fac}_{\min},\; \text{fac}\cdot \text{err}^{-1/(q+1)}\right)\right)

If err>1\text{err} > 1 the step is rejected and retried with the smaller hh. The safety factor fac\text{fac}, typically about 0.9, and the clamps keep hh from oscillating.

11. Adaptivity at work: an eccentric orbit

A planet on an orbit with eccentricity 0.9 crawls at its far point and whips around the near point. A fixed step would have to be small enough for the whip everywhere.

import numpy as np
from scipy.integrate import solve_ivp

def kepler(t, s):                     # planar two-body problem, GM = 1
    x, y, vx, vy = s
    r3 = (x*x + y*y) ** 1.5
    return [vx, vy, -x / r3, -y / r3]

e = 0.9                               # eccentric orbit, start at the far point
s0 = [1 + e, 0.0, 0.0, np.sqrt((1 - e) / (1 + e))]
period = 2 * np.pi                    # semi-major axis 1
sol = solve_ivp(kepler, (0, period), s0, rtol=1e-8, atol=1e-10)

h = np.diff(sol.t)
r = np.hypot(sol.y[0], sol.y[1])[:-1]
print(f"steps {h.size}, nfev {sol.nfev}")
print(f"largest step {h.max():.3f} at r = {r[h.argmax()]:.2f}")
print(f"smallest step {h.min():.5f} at r = {r[h.argmin()]:.2f}")
print(f"return error {np.linalg.norm(sol.y[:, -1] - s0):.1e}")
steps 146, nfev 968
largest step 0.178 at r = 1.74
smallest step 0.00140 at r = 0.10
return error 4.6e-08

The step varies by a factor of about 127 around the orbit, small near the sun where the acceleration changes quickly, large far out. A fixed step of 0.0014 would need about 2π/0.0014≈45002\pi / 0.0014 \approx 4500 steps for one orbit, roughly 30 times the 146 taken.

Gotcha: solve_ivp defaults to rtol=1e-3 and atol=1e-6, per its documentation. That is about three digits, adequate for a plot and inadequate for anything quantitative. Set both explicitly, with atol scaled to the size of each component near zero.

12. A checklist for any ODE solve

Everything in this lesson reduces to a short set of decisions, made in order.

  1. Is it stiff? Look for widely separated time scales, or estimate the Jacobian's eigenvalues. If an explicit solver takes far more steps than the solution's shape justifies, it is stiff. When unsure, method="LSODA" detects stiffness and switches between Adams and BDF methods automatically, per SciPy's documentation.
  2. Pick the family. Non-stiff: RK45, or DOP853 for tight tolerances, which SciPy recommends for high-precision work. Stiff: Radau or BDF.
  3. Set rtol and atol deliberately. Never trust the defaults for quantitative work.
  4. Feed implicit solvers a Jacobian, and its sparsity pattern for large systems.
  5. Check the result object. sol.success and sol.status say whether integration reached the end; nfev, njev and nlu say what it cost.
  6. Verify by tightening. Rerun with tolerances ten times smaller. The digits that do not change are the ones you can report.

Key idea: across this path the same structure kept recurring. Root finding needs linear solves, linear solves need a factorisation or a Krylov method, and a stiff time step needs all of them at once. Choosing well at each layer is what makes an equation one a computer can actually handle.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. Forward Euler is applied to y' = -500 y. What is the largest step size for which the numerical solution does not grow?
    • h = 0.004
    • h = 0.002
    • h = 0.0005
    • h = 0.04
  2. What makes a problem stiff, in the practical sense used by solvers?
    • Its solution changes rapidly everywhere
    • It has no closed-form solution
    • A fast-decaying component forces an explicit method's step far below what accuracy needs
    • Its right-hand side is discontinuous
  3. The trapezoidal rule is A-stable but not L-stable. What does that mean for a very stiff component?
    • It grows without bound
    • It is not damped and flips sign each step
    • It is damped to zero in one step
    • It is integrated exactly
  4. Why can Radau IIA be both A-stable and fifth order despite Dahlquist's second barrier?
    • It uses a smaller step size
    • The barrier only applies to explicit methods
    • It is A-stable only on the real axis
    • It is an implicit Runge-Kutta method, and the barrier applies to linear multistep methods
  5. In an embedded Runge-Kutta pair such as SciPy's RK45, what is the second, lower-order solution used for?
    • Estimating the local error to choose the next step size
    • Starting the integration before enough history exists
    • Detecting stiffness and switching methods
    • Computing the Jacobian by finite differences

Related lessons

Math
advanced

Root Finding: Bisection, Newton, and Knowing When to Stop

Most equations have no formula for their solution, so computers chase roots with sequences. Compare bisection, secant, Newton and Brent's method by convergence order and guarantees, watch Newton fail, learn how accurate a root can be, and pick stopping tests that do not lie.

11 steps·~17 min
Math
intermediate

What a Differential Equation Says: Rates, Solutions, and Slope Fields

A differential equation is a local rule for change, not a formula for the answer. Learn to read and classify one, solve the exponential and logistic cases, know when a unique solution exists, turn any order into a first-order system, and step forward numerically with Euler and Runge-Kutta.

10 steps·~15 min
Math
advanced

Iterative Solvers: From Jacobi to Preconditioned Conjugate Gradient

When a matrix is too large to factor, solve Ax = b by improving a guess. See why Jacobi stalls on fine grids, how Krylov methods and conjugate gradient use the whole history, why iterations scale with the square root of the condition number, what preconditioning buys, and how to set and check tolerances.

10 steps·~15 min
Math
advanced

Solving Ax = b Directly: LU, Pivoting, and Never Inverting

How a computer actually solves a linear system: Gaussian elimination as an LU factorisation, why you factor once and never invert, how a tiny pivot wrecks a harmless problem, what partial pivoting and the growth factor guarantee, when Cholesky applies, and where fill-in ends the direct approach.

10 steps·~15 min