Stiff ODE solvers: Rosenbrock and BDF
| Problem | Solve when the system mixes very fast and slow time scales, so that explicit methods are forced into tiny steps |
| Devised by | Stiffness: Charles Curtiss and Joseph Hirschfelder (1952). Backward differentiation formulas: Curtiss and Hirschfelder (1952), C. William Gear (1971). Rosenbrock methods: Howard Rosenbrock (1963); the 2(3) pair of Lawrence Shampine and Mark Reichelt (1997) |
| Accuracy | Rosenbrock 2(3): order 2 with an order-3 error estimate. BDF: orders 1 to 5, chosen by the user |
| Cost | Per step, one Jacobian and one LU factorisation of an matrix, plus a few function evaluations (Rosenbrock) or Newton iterations (BDF) |
| Read first | Runge-Kutta methods, Newton’s method and the secant method |
| API | rosenbrock23, bdf, OdeOptions |
Overview
Many systems contain processes on very different time scales: chemical reactions with fast and slow steps, electrical circuits with small and large time constants, the diffusion term of a discretised partial differential equation. After the fast components have decayed, the solution changes slowly and should be easy to follow. Yet explicit Runge-Kutta methods must keep taking tiny steps, because a larger step would make the long-dead fast components grow explosively. Such problems are called stiff.
Implicit methods evaluate the derivative at the end of the step, which makes them stable for any step size on decaying components. Their step is then limited by accuracy alone. The price is a system of equations to solve at every step, involving the Jacobian . The library offers two families. Rosenbrock methods linearise the implicit equations, so each step needs one LU factorisation and a few linear solves; they are robust at loose tolerances. Backward differentiation formulas (BDF) use several previous steps and solve the implicit equation by Newton’s method; at higher orders they are the most efficient choice for large stiff systems at moderate to tight tolerances.
Where it is used
Stiff solvers keep a simulation from taking absurdly tiny steps.
- Chemistry and combustion. Radicals that react in nanoseconds coexist with products that change over seconds.
- Electronics. Circuits mixing fast switching and slow thermal or battery dynamics.
- Process engineering and pharmacokinetics. Drug concentration models with fast absorption and slow elimination.
- Method-of-lines PDEs. Discretising diffusion in space produces large stiff systems.
History
Stiffness was recognised by Charles Curtiss and Joseph Hirschfelder in 1952, working on the equations of chemical kinetics at the University of Wisconsin. They observed that standard methods required absurdly small steps, coined the term “stiff”, and proposed the backward differentiation formulas as a remedy. In 1963 Germund Dahlquist laid the theoretical foundation with the concept of A-stability and the famous second Dahlquist barrier: no A-stable linear multistep method can have order greater than two.
C. William Gear’s book Numerical Initial Value Problems in Ordinary Differential Equations (1971)
and his program DIFSUB made variable-step, variable-order BDF methods practical; their descendants
(LSODE, DASSL, CVODE, MATLAB’s ode15s) remain the workhorses of stiff integration. In parallel,
the chemical engineer Howard Rosenbrock proposed in 1963 to avoid Newton iterations by building the
Jacobian into the method itself. Lawrence Shampine and Mark Reichelt’s 2(3) Rosenbrock pair (1997),
the method of MATLAB’s ode23s, is the one implemented here.
The idea
What makes a problem stiff
Near a solution, the system behaves like its linearisation , and each eigenvalue of the Jacobian contributes a component . Apply an explicit method to the scalar test equation : each step multiplies by a polynomial (for Euler, ), and the numerical solution stays bounded only if . For a polynomial this holds only in a bounded region of the complex plane, so a decaying component with forces , even when that component is negligible and the rest of the solution changes on a time scale of seconds. A problem is stiff when this stability limit, rather than accuracy, governs the step.
The Van der Pol oscillator with illustrates this. Its solution drifts slowly, then jumps:
Figure 2.21. Van der Pol oscillator.
During the slow drift a large step would be accurate, but the Jacobian has an eigenvalue of size , up to about , so an explicit method must keep :
Figure 2.22. Step sizes on the Van der Pol oscillator.
The Dormand-Prince step hovers around throughout, constantly rejected and retried at its stability limit. The implicit methods take steps as large as the accuracy allows, and shrink them only at the jumps, where the solution really does change quickly.
Implicit methods and A-stability
The backward Euler method evaluates the slope at the end of the step. On the test equation it gives , and whenever , for every . A method with this property is A-stable. Backward Euler is moreover L-stable: as its amplification factor tends to zero, so infinitely stiff components are damped completely in one step. The price is that appears on both sides, so every step requires solving a nonlinear system.
Backward differentiation formulas
A BDF method of order fits a polynomial through the new point and the previous points, and requires its derivative at to equal :
where the are the derivatives at of the Lagrange basis polynomials on the nodes. For order 1 this is backward Euler; with equal steps, order 2 is . Because the coefficients are computed from the actual node positions, the step can change freely.
Orders 1 and 2 are A-stable. Orders 3 to 6 are only stable in a wedge around the negative real axis, which still contains the eigenvalues of most dissipative problems; beyond order 6 the formulas are unstable altogether. The implicit equation is solved by Newton’s method, starting from the polynomial through the previous points extrapolated to (the predictor). Each Newton step solves a linear system with the matrix , factorised once per step. The difference between the corrected and the predicted solution estimates the local error.
Rosenbrock methods
Newton iterations are costly and need a convergence test. A Rosenbrock method replaces them by exactly one linear solve per stage, with the Jacobian built into the method’s coefficients. The 2(3) pair of Shampine and Reichelt, with and , computes
and a third stage at gives the error estimate . The method is L-stable and of order 2, with a single LU factorisation per step. Its low order makes it most efficient at loose tolerances, and its robustness makes it a good first try on a problem whose character is unknown.
Comparing the solvers
The library’s three solvers on three classic problems, all at relative tolerance (Jacobians formed by finite differences, which costs extra evaluations each):
Table 2.19. Steps taken by stiff and non-stiff solvers on stiff problems.
| problem | solver | steps | rejected | evaluations of | Jacobians | error in |
|---|---|---|---|---|---|---|
| on | Dormand-Prince | 381 | 0 | 2287 | 0 | 7.5e-8 |
| Rosenbrock 2(3) | 616 | 0 | 2465 | 616 | 1.4e-7 | |
| BDF, orders 1–5 | 114 | 5 | 477 | 119 | 6.5e-10 | |
| Van der Pol, , on | Dormand-Prince | 11953 | 591 | 75265 | 0 | 3.3e-7 |
| Rosenbrock 2(3) | 5298 | 2 | 26501 | 5300 | 1.8e-5 | |
| BDF, orders 1–5 | 878 | 42 | 4601 | 920 | 4.7e-6 | |
| Robertson kinetics on | Dormand-Prince | 34560 | 1207 | 214603 | 0 | 5.6e-11 |
| Rosenbrock 2(3) | 537 | 0 | 3223 | 537 | 2.5e-8 | |
| BDF, orders 1–5 | 134 | 6 | 841 | 140 | 1.3e-6 |
The first problem is only mildly stiff ( on an interval of length 1), and Dormand-Prince is competitive: its stability limit of about 300 steps is not much below what accuracy demands. On Van der Pol and above all on Robertson’s chemical kinetics, whose rate constants span nine orders of magnitude, the explicit method needs tens of thousands of steps while BDF needs hundreds. Note also that the error in the final value can exceed the tolerance: the tolerance controls the error committed in each step, not its accumulation.
Algorithm
Rosenbrock 2(3), per step: form (supplied, or by forward differences) and (by a forward difference); factorise ; solve for with three function evaluations; accept if the weighted error is at most 1; scale by , between 0.1 and 5.
BDF of maximum order , per step:
- Use order , so the order rises from 1 as history accumulates.
- Predict by extrapolating the last points; compute the coefficients for the actual nodes.
- Factorise at the predictor and apply up to 8 Newton iterations. If they fail to converge, quarter the step and retry.
- Estimate the error from the corrector minus the predictor; accept if it is at most 1; scale by , allowing at most a factor 2 (orders 1–2) or 1.3 (higher orders) of growth.
Implementation
The Rosenbrock step:
let jac = sys.jacobian(t, &y, &f0)?;
let dt = f64::EPSILON.sqrt() * t.abs().max(1.0);
let f_t = sys.eval(t + dt, &y)?;
let dfdt: Vec<f64> = (0..n).map(|i| (f_t[i] - f0[i]) / dt).collect();
let w: Vec<Vec<f64>> = (0..n).map(|i| (0..n).map(|k| if i == k { 1.0 } else { 0.0 } - hs * d * jac[i][k]).collect()).collect();
let lu = Lu::new(w)?;
let k1 = lu.solve(&(0..n).map(|i| f0[i] + hs * d * dfdt[i]).collect::<Vec<_>>());
let y_half: Vec<f64> = (0..n).map(|i| y[i] + 0.5 * hs * k1[i]).collect();
let f1 = sys.eval(t + 0.5 * hs, &y_half)?;
let k2: Vec<f64> = lu.solve(&(0..n).map(|i| f1[i] - k1[i]).collect::<Vec<_>>()).iter().zip(&k1).map(|(a, b)| a + b).collect();
let y_new: Vec<f64> = (0..n).map(|i| y[i] + hs * k2[i]).collect();
let f2 = sys.eval(t + hs, &y_new)?;
let rhs: Vec<f64> = (0..n).map(|i| f2[i] - e32 * (k2[i] - f1[i]) - 2.0 * (k1[i] - f0[i]) + hs * d * dfdt[i]).collect();
let k3 = lu.solve(&rhs);
let err: Vec<f64> = (0..n).map(|i| hs / 6.0 * (k1[i] - 2.0 * k2[i] + k3[i])).collect();
let error = weighted_max(&err, &y, &y_new, &options);
The BDF corrector:
// Corrector: α₀ y + Σ α_j y_{n+1−j} = f(t_new, y), solved by Newton's method.
let mut nodes = vec![t_new];
nodes.extend(history.iter().rev().take(order).map(|p| p.0));
let alpha = lagrange_derivative_at_first(&nodes);
let past: Vec<f64> = (0..n).map(|i| history.iter().rev().take(order).enumerate().map(|(j, p)| alpha[j + 1] * p.1[i]).sum()).collect();
let f_pred = sys.eval(t_new, &y_pred)?;
let jac = sys.jacobian(t_new, &y_pred, &f_pred)?;
let lu = Lu::new((0..n).map(|i| (0..n).map(|k| if i == k { alpha[0] } else { 0.0 } - jac[i][k]).collect()).collect())?;
let mut y_new = y_pred.clone();
let mut f_new = f_pred;
let mut converged = false;
for _ in 0..8 {
let residual: Vec<f64> = (0..n).map(|i| alpha[0] * y_new[i] + past[i] - f_new[i]).collect();
let delta = lu.solve(&residual);
y_new.iter_mut().zip(&delta).for_each(|(v, d)| *v -= d);
f_new = sys.eval(t_new, &y_new)?;
if !y_new.iter().all(|v| v.is_finite()) {
break;
}
if weighted_max(&delta, &y, &y_new, &options) < 1e-3 {
converged = true;
break;
}
}
if !converged {
solution.rejected_steps += 1;
h *= 0.25;
if h < 1e-14 * t.abs().max(1.0) {
return Err(ErrorsJSL::RuntimeError("Newton iteration failed at the minimum step size."));
}
continue;
}
- Supplying the Jacobian, when it is known in closed form, saves evaluations of per step and improves robustness; both solvers accept it as an optional argument.
- The linear systems are dense and solved by LU factorisation with partial pivoting. For large systems from discretised PDEs, whose Jacobians are sparse or banded, a sparse factorisation would be far cheaper; that is outside the library’s scope.
- Limiting the growth of the step at higher BDF orders keeps the variable-coefficient formulas stable when the step changes.
In practice
//! A stiff chemical reaction (Robertson's problem) with explicit and implicit solvers.
//!
//! Run with `cargo run --release -p lib_jsl_integration --example ode_stiff`.
use lib_jsl_integration::dormand_prince::dormand_prince_solve;
use lib_jsl_integration::stiff_ode::{OdeOptions, bdf, rosenbrock23};
/// Three species reacting at rates spanning nine orders of magnitude.
fn robertson(_t: f64, y: &[f64]) -> Vec<f64> {
vec![
-0.04 * y[0] + 1e4 * y[1] * y[2],
0.04 * y[0] - 1e4 * y[1] * y[2] - 3e7 * y[1] * y[1],
3e7 * y[1] * y[1],
]
}
/// The Jacobian ∂f/∂y, which saves the solvers from estimating it by differences.
fn jacobian(_t: f64, y: &[f64]) -> Vec<Vec<f64>> {
vec![
vec![-0.04, 1e4 * y[2], 1e4 * y[1]],
vec![0.04, -1e4 * y[2] - 6e7 * y[1], -1e4 * y[1]],
vec![0.0, 6e7 * y[1], 0.0],
]
}
fn main() {
let options = OdeOptions { relative_tolerance: 1e-6, absolute_tolerance: 1e-10, max_steps: 1_000_000, ..Default::default() };
let start = [1.0, 0.0, 0.0];
for t_end in [40.0, 4e5] {
println!("t = {t_end}:");
let s = bdf(robertson, Some(jacobian), 0.0, &start, t_end, 5, options).unwrap();
println!(" BDF: {:>7} steps, y = {:.6e}", s.t.len() - 1, s.last()[0]);
let s = rosenbrock23(robertson, Some(jacobian), 0.0, &start, t_end, options).unwrap();
println!(" Rosenbrock: {:>7} steps, y = {:.6e}", s.t.len() - 1, s.last()[0]);
match dormand_prince_solve(robertson, 0.0, &start, t_end, options) {
Ok(s) => println!(" Dormand-Prince: {:>7} steps, y = {:.6e}", s.t.len() - 1, s.last()[0]),
Err(e) => println!(" Dormand-Prince: failed ({e:?})"),
}
}
}
Integrated to , where the slow reaction is nearly complete, Robertson’s problem defeats the explicit method entirely, while BDF needs about 300 steps.
Strengths
- Step sizes set by accuracy alone, however stiff the problem.
- Rosenbrock: no Newton iteration, robust, a good first choice at loose tolerances.
- BDF: high order with few function evaluations per step; the standard for large stiff systems.
Weaknesses
- Each step needs a Jacobian and an factorisation, wasteful for non-stiff problems.
- BDF of order above 2 is not A-stable: for lightly damped oscillations (eigenvalues near the imaginary axis) use orders 1–2 or the Rosenbrock method.
- For non-stiff problems, an explicit method such as Dormand-Prince is cheaper.
Exercises
- Show that backward Euler applied to gives , and that the trapezoid rule is A-stable but not L-stable. What happens to a very stiff component under the trapezoid rule?
- Derive the coefficients of the constant-step BDF2 formula from the Lagrange polynomial through three equally spaced points.
- Solve with BDF of maximum order 1, 2 and 5 at several tolerances. Which order is most efficient, and when?
- Find the eigenvalues of the Robertson Jacobian at (near the quasi-steady state). Use them to estimate the largest stable step of Dormand-Prince.
- Integrate the Van der Pol oscillator with with each solver. How does the number of steps scale with for the explicit and the implicit methods?
Hints and answers
- Backward Euler: , so . The trapezoid rule has with for (A-stable) but as , so it is not L-stable: a very stiff component decays by a factor per step, oscillating with almost no damping.
- Differentiate the quadratic through , , at and set it equal to : .
- Compare the number of steps and of Jacobian evaluations at each tolerance. Higher orders pay off at tight tolerances, where larger steps are possible, while order 1 is competitive at loose ones.
- At the Jacobian has eigenvalues about , and . The stiff eigenvalue limits Dormand-Prince to , although the solution changes on a scale of a few units of time.
- The explicit solver’s step count grows in proportion to (its stability limit tracks the stiffness), while the implicit solvers’ step count grows much more slowly.
Further reading
- C. F. Curtiss and J. O. Hirschfelder, “Integration of stiff equations”, Proceedings of the National Academy of Sciences 38 (1952) 235–243.
- G. Dahlquist, “A special stability problem for linear multistep methods”, BIT 3 (1963) 27–43.
- H. H. Rosenbrock, “Some general implicit processes for the numerical solution of differential equations”, The Computer Journal 5 (1963) 329–330.
- C. W. Gear, Numerical Initial Value Problems in Ordinary Differential Equations, Prentice-Hall, 1971.
- L. F. Shampine and M. W. Reichelt, “The MATLAB ODE suite”, SIAM Journal on Scientific Computing 18 (1997) 1–22.
- E. Hairer and G. Wanner, Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems, 2nd ed., Springer, 1996.