Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

2026-11-18 Runge-Kutta

Last time

  • Implicit methods

  • AA- and LL-stability

  • Advection and diffusion

Today

  • Advection-diffusion

  • Exploring stiffness

  • Runge-Kutta methods

using Plots
default(linewidth=3)
using LinearAlgebra
using SparseArrays

function plot_stability(Rz, method; xlim=(-3, 2), ylim=(-1.5, 1.5))
    x = xlim[1]:.02:xlim[2]
    y = ylim[1]:.02:ylim[2]
    plot(title="Stability: $method", aspect_ratio=:equal, xlim=xlim, ylim=ylim)
    heatmap!(x, y, (x, y) -> abs(Rz(x + 1im*y)), c=:bwr, clims=(0, 2))
    contour!(x, y, (x, y) -> abs(Rz(x + 1im*y)), color=:black, linewidth=2, levels=[1.])
    plot!(x->0, color=:black, linewidth=1, label=:none)
    plot!([0, 0], [ylim...], color=:black, linewidth=1, label=:none)
end

function ode_theta_linear(A, u0; forcing=zero, tfinal=1, h=0.1, theta=.5)
    u = copy(u0)
    t = 0.
    thist = [t]
    uhist = [u0]
    while t < tfinal
        tnext = min(t+h, tfinal)
        h = tnext - t
        rhs = (I + h*(1-theta)*A) * u .+ h*forcing(t+h*theta)
        u = (I - h*theta*A) \ rhs
        t = tnext
        push!(thist, t)
        push!(uhist, u)
    end
    thist, hcat(uhist...)
end

Rz_theta(z, theta) = (1 + (1 - theta)*z) / (1 - theta*z)

function advdiff_matrix(n; kappa=1, wind=1, upwind=0.)
    dx = 2 / n
    rows = [1]
    cols = [1]
    vals = [0.]
    wrap(j) = (j + n - 1) % n + 1
    for i in 1:n
        append!(rows, [i, i, i])
        append!(cols, wrap.(i-1:i+1))
        diffuse = [-1, 2, -1] * kappa / dx^2
        advect_upwind = [-1, 1, 0] * wind / dx
        advect_center = [-1, 0, 1] * wind / 2dx
        stencil = -diffuse - upwind * advect_upwind - (1 - upwind) * advect_center
        append!(vals, stencil)
    end
    sparse(rows, cols, vals)
end
advdiff_matrix(5, kappa=.1)
5×5 SparseMatrixCSC{Float64, Int64} with 15 stored entries: -1.25 -0.625 ⋅ ⋅ 1.875 1.875 -1.25 -0.625 ⋅ ⋅ ⋅ 1.875 -1.25 -0.625 ⋅ ⋅ ⋅ 1.875 -1.25 -0.625 -0.625 ⋅ ⋅ 1.875 -1.25

Stability classes and the θ\theta method

Definition: AA-stability

A method is AA-stable if the stability region

{z:∣R(z)∣≤1}\{ z : |R(z)| \le 1 \}

contains the entire left half plane

ℜ[z]≤0.\Re[z] \le 0 .

This means that the method can take arbitrarily large time steps without becoming unstable (diverging) for any problem that is indeed physically stable.

Definition: LL-stability

A time integrator with stability function R(z)R(z) is LL-stable if

lim⁡z→∞R(z)=0.\lim_{z\to\infty} R(z) = 0 .

For the θ\theta method, we have

lim⁡z→∞1+(1−θ)z1−θz=1−θ−θ.\lim_{z\to \infty} \frac{1 + (1-\theta)z}{1 - \theta z} = \frac{1-\theta}{-\theta} .

Evidently only θ=1\theta=1 is LL-stable.

Heat equation as linear ODE

  • How do different θ∈[0,1]\theta \in [0, 1] compare in terms of stability?

  • Are there artifacts even when the solution is stable?

using SparseArrays

function heat_matrix(n)
    dx = 2 / n
    rows = [1]
    cols = [1]
    vals = [0.]
    wrap(j) = (j + n - 1) % n + 1
    for i in 1:n
        append!(rows, [i, i, i])
        append!(cols, wrap.([i-1, i, i+1]))
        append!(vals, [1, -2, 1] ./ dx^2)
    end
    sparse(rows, cols, vals)
end
heat_matrix(5)
5×5 SparseMatrixCSC{Float64, Int64} with 15 stored entries: -12.5 6.25 ⋅ ⋅ 6.25 6.25 -12.5 6.25 ⋅ ⋅ ⋅ 6.25 -12.5 6.25 ⋅ ⋅ ⋅ 6.25 -12.5 6.25 6.25 ⋅ ⋅ 6.25 -12.5
n = 160
A = heat_matrix(n)
x = LinRange(-1, 1, n+1)[1:end-1]
u0 = exp.(-200 * x .^ 2)
@time thist, uhist = ode_theta_linear(A, u0, h=.01, theta=0.5, tfinal=1);
nsteps = size(uhist, 2)
plot(x, uhist[:, 1:8])
  2.111023 seconds (7.53 M allocations: 377.785 MiB, 9.69% gc time, 99.76% compilation time)
Loading...

Advection as a linear ODE

function advect_matrix(n; upwind=false)
    dx = 2 / n
    rows = [1]
    cols = [1]
    vals = [0.]
    wrap(j) = (j + n - 1) % n + 1
    for i in 1:n
        append!(rows, [i, i])
        if upwind
            append!(cols, wrap.([i-1, i]))
            append!(vals, [1., -1] ./ dx)
        else
            append!(cols, wrap.([i-1, i+1]))
            append!(vals, [1., -1] ./ 2dx)
        end
    end
    sparse(rows, cols, vals)
end
advect_matrix(5)
5×5 SparseMatrixCSC{Float64, Int64} with 11 stored entries: 0.0 -1.25 ⋅ ⋅ 1.25 1.25 ⋅ -1.25 ⋅ ⋅ ⋅ 1.25 ⋅ -1.25 ⋅ ⋅ ⋅ 1.25 ⋅ -1.25 -1.25 ⋅ ⋅ 1.25 ⋅
n = 50
A = advect_matrix(n, upwind=true)
x = LinRange(-1, 1, n+1)[1:end-1]
u0 = exp.(-9 * x .^ 2)
@time thist, uhist = ode_theta_linear(A, u0, h=.04/2, theta=0.5, tfinal=1.);
nsteps = size(uhist, 2)
plot(x, uhist[:, 1:(nsteps÷8):end])
  0.030902 seconds (6.53 k allocations: 4.421 MiB, 94.31% gc time)
Loading...

Spectrum of operators

theta=0.
h = .1
plot_stability(z -> Rz_theta(z, theta), "\$\\theta=$theta, h=$h\$")
ev = eigvals(Matrix(h*advect_matrix(20, upwind=true)))
scatter!(real(ev), imag(ev))
Loading...
theta=1
h = .02/4
plot_stability(z -> Rz_theta(z, theta), "\$\\theta=$theta, \
    h=$h\$", xlim=(-10, 1))
ev = eigvals(Matrix(h*heat_matrix(40)))
scatter!(real(ev), imag(ev), label=:none)
Loading...

Stiffness

Stiff equations are problems for which explicit methods don’t work. (Hairer and Wanner, 2002)

  • “stiff” dates to Curtiss and Hirschfelder (1952)

k = 400
thist, uhist = ode_theta_linear(-k, [0.0], forcing=t -> k*cos(t), tfinal=5, h=.1, theta=0.5)
scatter(thist, uhist[1,:])
plot!(cos)
Loading...
function mms_error(h; theta=.5, k=10)
    u0 = [.2]
    thist, uhist = ode_theta_linear(-k, u0, forcing=t -> k*cos(t), tfinal=3, h=h, theta=theta)
    T = thist[end]
    u_exact = (u0 .- k^2/(k^2+1)) * exp(-k*T) .+ k*(sin(T) + k*cos(T))/(k^2 + 1)
    uhist[1,end] .- u_exact
end
mms_error (generic function with 1 method)
hs = .5 .^ (1:9)
errors = mms_error.(hs, theta=0.0, k=400)
plot(hs, norm.(errors), marker=:circle, xscale=:log10, yscale=:log10)
plot!(hs, hs, label="\$h\$", legend=:topleft)
plot!(hs, hs.^2, label="\$h^2\$")
Loading...

Discuss: is advection-diffusion stiff?

theta=0
n = 80
dx = 2 / n
kappa = .005 * 5 * 5
lambda_min = -4 * kappa / dx^2
cfl = 1
h = min(-2 / lambda_min, cfl * dx)

plot_stability(z -> Rz_theta(z, theta),
    "\$\\theta=$theta, h=$h, Pe_h = $(h/kappa)\$")
ev = eigvals(Matrix(h*advdiff_matrix(n, kappa=kappa, wind=1)))
scatter!(real(ev), imag(ev))
Loading...

Cost scaling

  • Spatial discretization with error O((Δx)p)O((\Delta x)^p)

  • Time discretization with error O((Δt)q)O((\Delta t)^q)

p = 2   # spatial order of accuracy
q = 2   # temporal order of accuracy
Pe = 100 # Peclet number with wind=1

dt_accuracy(dx) = dx .^ (p/q)
dt_stability(dx) = min(dx, Pe * dx ^ 2)

n = 2 .^ (1:10); dx = 1 ./ n
plot(dx, [dt_accuracy.(dx) dt_stability.(dx)],
    label=["accuracy" "stability"], 
    xscale=:log10, yscale=:log10, legend=:bottomright,
    xlabel="\$\\Delta x\$", ylabel="\$\\Delta t\$")
Loading...
function error((dx, dt))
    dt <= dt_stability(dx) ? dx ^ p + dt ^ q : 10
end
plot(n, [error.(zip(dx, dt_accuracy.(dx))) error.(zip(dx, dt_stability.(dx))) dx.^p],
    label=["accuracy" "stability" "spatial only"],
    marker=:circle, xscale=:log10, yscale=:log10,
    xlabel="number of grid points", ylabel="error")
Loading...

Work-precision (error vs cost)

p = 2
q = 2
Pe = 10
dt = [dt_accuracy.(dx) dt_stability.(dx) dt_accuracy.(dx)]
c = [n./dt[:,1] n./dt[:,2] (n.^1.5)./dt[:,3]] # O(n^1.5 solve cost)
e = [error.(zip(dx, dt[:,1])) error.(zip(dx, dt[:,2])) dx.^p+dt[:,3].^q]
plot(c, e, xscale=:log10, yscale=:log10,
  label=["explicit_accuracy" "explicit_stable" "implicit"], xlabel="cost", ylabel="error")
Loading...
  • Stability can be an extreme demand for explicit methods

  • Order of accuracy matters; usually balance spatial order pp and temporal order qq

  • Actual cost depends heavily on solver efficiency: O(n) vs O(n^2)

  • “Constants matter”

Runge-Kutta methods

The methods we have considered thus far can all be expressed as Runge-Kutta methods, which are expressed in terms of ss “stage” equations (possibly coupled) and a completion formula. For the ODE

u˙=f(t,u)\dot u = f(t, u)

the Runge-Kutta method is

Yi=u(t)+h∑jaijf(t+cjh,Yj)u(t+h)=u(t)+h∑jbjf(t+cjh,Yj)\begin{split} Y_i = u(t) + h \sum_j a_{ij} f(t+c_j h, Y_j) \\ u(t+h) = u(t) + h \sum_j b_j f(t+c_j h, Y_j) \end{split}

where cc is a vector of abscissa, AA is a table of coefficients, and bb is a vector of completion weights.

These coefficients are typically expressed in a Butcher Table

[cAbT]=[c0a00a01c1a10a11b0b1].\left[ \begin{array}{c|c} c & A \\ \hline & b^T \end{array} \right] = \left[ \begin{array}{c|cc} c_0 & a_{00} & a_{01} \\ c_1 & a_{10} & a_{11} \\ \hline & b_0 & b_1 \end{array} \right] .

We will see that, for consistency, the abscissa cc are always the row sums of AA and that ∑ibi=1\sum_i b_i = 1.

If the matrix AA is strictly lower triangular, then the method is explicit (does not require solving equations).

Past methods as Runge-Kutta

  • Forward Euler

    [001],\left[ \begin{array}{c|cc} 0 & 0 \\ \hline & 1 \end{array} \right] ,
  • Backward Euler

    [111],\left[ \begin{array}{c|c} 1 & 1 \\ \hline & 1 \end{array} \right] ,
  • Midpoint

    [12121].\left[ \begin{array}{c|c} \frac 1 2 & \frac 1 2 \\ \hline & 1 \end{array} \right].

Indeed, the θ\theta method is

[θθ1]\left[ \begin{array}{c|c} \theta & \theta \\ \hline & 1 \end{array} \right]

and an alternative “endpoint” variant of θ\theta (a generalization of the trapezoid rule) is

[00011−θθ1−θθ].\left[ \begin{array}{c|cc} 0 & 0 & 0 \\ 1 & 1-\theta & \theta \\ \hline & 1-\theta & \theta \end{array} \right].

Stability function for Runge-Kutta

To develop an algebraic expression for stability in terms of the Butcher Table, we consider the test equation

u˙=λu\dot u = \lambda u

and apply the RK method to yield

Yi=u(0)+h∑jaijλYju(h)=u(0)+h∑jbjλYj\begin{split} Y_i = u(0) + h \sum_j a_{ij} \lambda Y_j \\ u(h) = u(0) + h \sum_j b_j \lambda Y_j \end{split}

or, in matrix form,

Y=1u(0)+hλAYu(h)=u(0)+hλbTY\begin{split} Y = \mathbb 1 u(0) + h \lambda A Y \\ u(h) = u(0) + h \lambda b^T Y \end{split}

where 1\mathbb 1 is a column vector of length ss consisting of all ones. This reduces to

u(h)=(1+hλbT(I−hλA)−11)⏟R(hλ)u(0).u(h) = \underbrace{\Big( 1 + h\lambda b^T (I - h \lambda A)^{-1} \mathbb 1 \Big)}_{R(h\lambda)} u(0) .

Plotting stability

u(h)=(1+hλbT(I−hλA)−11)⏟R(hλ)u(0)u(h) = \underbrace{\Big( 1 + h\lambda b^T (I - h \lambda A)^{-1} \mathbb 1 \Big)}_{R(h\lambda)} u(0)
struct RKTable
    A::Matrix
    b::Matrix
    c::Vector
    function RKTable(A, b)
        s = size(b, 2)
        A = reshape(A, s, s)
        c = vec(sum(A, dims=2))
        new(A, b, c)
    end
end

function rk_stability(z, rk; brow=1)
    s = size(rk.b, 2)
    1 + z * rk.b[1,:]' * ((I - z*rk.A) \ ones(s))
end
rk_stability (generic function with 1 method)
theta = 0.
rk_theta(theta) = RKTable([theta], [1]')
rk_theta_endpoint(theta) = RKTable([0 0;1-theta theta], [1-theta theta])
table = rk_theta_endpoint(theta)
plot_stability(z -> rk_stability(z, table), "\$\\theta = $theta\$")
Loading...

Heun’s method and RK4

heun = RKTable([0 0; 1 0], [.5 .5])
plot_stability(z -> rk_stability(z, heun), "Heun's method")
Loading...
rk4 = RKTable([0 0 0 0; .5 0 0 0; 0 .5 0 0; 0 0 1 0],
[1 2 2 1] / 6)
plot_stability(z -> rk_stability(z, rk4), "RK4")
Loading...

An explicit RK solver

Yi=u(t)+h∑jaijf(t+cjh,Yj)u(t+h)=u(t)+h∑jbjf(t+cjh,Yj)\begin{align} Y_i &= u(t) + h \sum_j a_{ij} f(t+c_j h, Y_j) & u(t+h) &= u(t) + h \sum_j b_j f(t+c_j h, Y_j) \end{align}
function ode_rk_explicit(f, u0; tfinal=1, h=0.1, table=rk4)
    u = copy(u0)
    t = 0.
    n, s = length(u), length(table.c)
    fY = zeros(n, s)
    thist = [t]
    uhist = [u0]
    while t < tfinal
        tnext = min(t+h, tfinal)
        h = tnext - t
        for i in 1:s
            ti = t + h * table.c[i]
            Yi = u + h * sum(fY[:,1:i-1] * table.A[i,1:i-1], dims=2)
            fY[:,i] = f(ti, Yi)
        end
        u += h * fY * table.b[1,:]
        t = tnext
        push!(thist, t)
        push!(uhist, u)
    end
    thist, hcat(uhist...)
end
ode_rk_explicit (generic function with 1 method)
linear_oscillator(t, u) = [0 -1; 1 0] * u
thist, uhist = ode_rk_explicit(linear_oscillator, [1., 0], tfinal=60, h=0.5)
plot(thist, uhist', marker=:auto)
plot!([sin, cos])
Loading...

Measuring convergence and accuracy

function mms_error(h, f, u_exact; table=rk4)
    u0 = u_exact(0)
    thist, uhist = ode_rk_explicit(f, u0, tfinal=3, h=h, table=table)
    T = thist[end]
    uhist[:,end] - u_exact(T)
end

hs = .5 .^ (-3:8)
linear_oscillator_exact(t) = [cos(t), sin(t)]
linear_oscillator_exact (generic function with 1 method)
heun_errors = mms_error.(hs, linear_oscillator, linear_oscillator_exact, table=heun)
rk4_errors = mms_error.(hs, linear_oscillator, linear_oscillator_exact, table=rk4)
plot(hs, [norm.(heun_errors) norm.(rk4_errors)], label=["heun" "rk4"], marker=:auto)
plot!(hs, [hs hs.^2 hs.^3 hs.^4], label=["\$h^$p\$" for p in [1 2 3 4]], legend=:topleft, xscale=:log10, yscale=:log10)
Loading...

Work-precision (or accuracy vs cost)

heun_nfeval = length(heun.c) ./ hs
rk4_nfeval = length(rk4.c) ./ hs
plot(heun_nfeval, norm.(heun_errors), marker=:auto, label="heun")
plot!(rk4_nfeval, norm.(rk4_errors), marker=:auto, label="rk4")
plot!(xscale=:log10, yscale=:log10, xlabel="number of evaluations", ylabel="error")
Loading...

Effective RK stability diagrams

function rk_eff_stability(z, rk; brow=1)
    s = size(rk.b, 2)
    fsal = rk.b[1,:] ≈ rk.A[end,:]
    z = (s - fsal) * z
    1 + z * rk.b[brow,:]' * ((I - z*rk.A) \ ones(s))
end
plot_stability(z -> rk_eff_stability(z, heun), "Heun's method")
Loading...
plot_stability(z -> rk_eff_stability(z, rk4), "RK4")
Loading...

Runge-Kutta order conditions

We consider the autonomous differential equation

u˙=f(u).\dot u = f(u) .

Higher derivatives of the exact soultion can be computed using the chain rule, e.g.,

Undefined control sequence: \dddot at position 59: … f'(u) f(u) \\
\̲d̲d̲d̲o̲t̲ ̲u(t) &= f''(u) …

\begin{align*}
\ddot u(t) &= f'(u) \dot u = f'(u) f(u) \\
\dddot u(t) &= f''(u) f(u) f(u) + f'(u) f'(u) f(u) . \\
\end{align*}

Note that if f(u)f(u) is linear, f′′(u)=0f''(u) = 0. Meanwhile, the numerical solution is a function of the time step hh,

Yi(h)=u(0)+h∑jaijf(Yj)U(h)=u(0)+h∑jbjf(Yj).\begin{split} Y_i(h) &= u(0) + h \sum_j a_{ij} f(Y_j) \\ U(h) &= u(0) + h \sum_j b_j f(Y_j). \end{split}

We will take the limit h→0h\to 0 and equate derivatives of the numerical solution. First we differentiate the stage equations,

\begin{split} Y_i(0) &= u(0) \ \dot Y_i(0) &= \sum_j a_{ij} f(Y_j) \ \ddot Y_i(0) &= 2 \sum_j a_{ij} \dot f(Y_j) \ &= 2 \sum_j a_{ij} f’(Y_j) \dot Y_j \ &= 2\sum_{j,k} a_{ij} a_{jk} f’(Y_j) f(Y_k) \ \dddot Y_i(0) &= 3 \sum_j a_{ij} \ddot f (Y_j) \ &= 3 \sum_j a_{ij} \Big( \sum_k f’‘(Y_j) \dot Y_j \dot Y_k + f’(Y_j) \ddot Y_j \Big) \ &= 3 \sum_{j,k,\ell} a_{ij} a_{jk} \Big( a_{j\ell} f’‘(Y_j) f(Y_k) f(Y_\ell) + 2 a_{k\ell} f’(Y_j) f’(Y_k) f(Y_\ell) \Big) \end{split}

where we have used Liebnitz’s formula for the mmth derivative,

(hϕ(h))(m)∣h=0=mϕ(m−1)(0).(h \phi(h))^{(m)}|_{h=0} = m \phi^{(m-1)}(0) .

Similar formulas apply for U˙(0)\dot U(0), U¨(0)\ddot U(0), and \dddot U(0), with bjb_j in place of aija_{ij}.

Order conditions are nonlinear algebraic equations

Equating terms u˙(0)=U˙(0)\dot u(0) = \dot U(0) yields

∑jbj=1,\sum_j b_j = 1,

equating u¨(0)=U¨(0)\ddot u(0) = \ddot U(0) yields

2∑j,kbjajk=1,2 \sum_{j,k} b_j a_{jk} = 1 ,

and equating \dddot u(0) = \dddot U(0) yields the two equations \begin{split} 3\sum_{j,k,\ell} b_j a_{jk} a_{j\ell} &= 1 \ 6 \sum_{j,k,\ell} b_j a_{jk} a_{k\ell} &= 1 . \end{split}

Observations

  • These are systems of nonlinear equations for the coefficients aija_{ij} and bjb_j. There is no guarantee that they have solutions.

  • The number of equations grows rapidly as the order increases.

u(1)u^{(1)}u(2)u^{(2)}u(3)u^{(3)}u(4)u^{(4)}u(5)u^{(5)}u(6)u^{(6)}u(7)u^{(7)}u(8)u^{(8)}u(9)u^{(9)}u(10)u^{(10)}
# terms112492048115286719
cumulative12481737852004861205
  • Usually the number of order conditions does not exactly match the number of free parameters, meaning that the remaining parameters can be optimized (usually numerically) for different purposes, such as to minimize the leading error terms or to maximize stability in certain regions of the complex plane. Finding globally optimal solutions can be extremely demanding.

  • Rooted trees provide a convenient notation

Trees and elementary differentials up to order 5. From Hairer, Nørsett, and Wanner.

Theorem (from Hairer, Nørsett, and Wanner)

A Runge-Kutta method is of order pp if and only if

γ(t)∑jbjΦj(t)=1\gamma(\mathcal t) \sum_{j} b_j \Phi_j(t) = 1

for all trees tt of order ≤p\le p.

For a linear autonomous equation

u˙=Au\dot u = A u

we only need one additional order condition per order of accuracy because f′′=0f'' = 0. These conditions can also be derived by equating derivatives of the stability function R(z)R(z) with the exponential eze^z. For a linear non-autonomous equation

u˙=A(t)u+g(t)\dot u = A(t) u + g(t)

or more generally, an autonomous system with quadratic right hand side,

u˙=B(u⊗u)+Au+C\dot u = B (u \otimes u) + A u + C

where BB is a rank 3 tensor, we have f′′′=0f''' = 0, thus limiting the number of order conditions.

Embedded error estimation

It is often possible to design Runge-Kutta methods with multiple completion orders, say of order pp and p−1p-1.

[cAbTb~T].\left[ \begin{array}{c|c} c & A \\ \hline & b^T \\ & \tilde b^T \end{array} \right] .

The classical RK4 does not come with an embedded method, but most subsequent RK methods do. The Bogacki-Shampine method is one such method.

bs3 = RKTable([0 0 0 0; 1/2 0 0 0; 0 3/4 0 0; 2/9 1/3 4/9 0],
    [2/9 1/3 4/9 0; 7/24 1/4 1/3 1/8])
plot_stability(z -> rk_eff_stability(z, bs3), "BS3 third order")
Loading...
plot_stability(z -> rk_eff_stability(z, bs3, brow=2), "BS3 second order")
Loading...

Properties

display(bs3.A)
display(bs3.b)
4×4 Matrix{Float64}: 0.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.0 0.75 0.0 0.0 0.222222 0.333333 0.444444 0.0
2×4 Matrix{Float64}: 0.222222 0.333333 0.444444 0.0 0.291667 0.25 0.333333 0.125
  • First same as last (FSAL): the completion formula bb is the same as the last row of AA.

    • Stage can be reused as first stage of the next time step. So this 4-stage method has a cost equal to a 3-stage method.

  • Fehlberg, a 6-stage, 5th order method for which the 4th order embedded formula has been optimized for accuracy.

  • Dormand-Prince, a 7-stage, 5th order method with the FSAL property, with the 5th order completion formula optimized for accuracy.

Adaptive step size control

Given a completion formula bTb^T of order pp and b~T\tilde b^T of order p−1p-1, an estimate of the local truncation error (on this step) is given by

eloc(h)=∥h(b−b~)Tf(Y)∥∈O(hp).e_{\text{loc}}(h) = \lVert h (b - \tilde b)^T f(Y) \rVert \in O(h^p) .

Given a tolerance ϵ\epsilon, we would like to find h∗h_* such that

eloc(h∗)<ϵ.e_{\text{loc}}(h_*) < \epsilon .

If

eloc(h)=chpe_{\text{loc}}(h) = c h^p

for some constant cc, then

ch∗p<ϵc h_*^p < \epsilon

implies

h∗<(ϵc)1/p.h_* < \left( \frac{\epsilon}{c} \right)^{1/p} .

Given the estimate with the current hh,

c=eloc(h)/hpc = e_{\text{loc}}(h) / h^p

we conclude

h∗h<(ϵeloc(h))1/p.\frac{h_*}{h} < \left( \frac{\epsilon}{e_{\text{loc}}(h)} \right)^{1/p} .

Notes

  • Usually a “safety factor” less than 1 is included so the predicted error is less than the threshold to reject a time step.

  • We have used an absolute tolerance above. If the values of solution variables vary greatly in time, a relative tolerance eloc(h)/∥u(t)∥e_{\text{loc}}(h) / \lVert u(t) \rVert or a combination thereof is desirable.

  • There is a debate about whether one should optimize the rate at which error is accumulated with respect to work (estimate above) or with respect to simulated time (as above, but with error behaving as O(hp−1)O(h^{p-1})). For problems with a range of time scales at different periods, this is usually done with respect to work.

  • Global error control is an active research area.

Diagonally Implicit Runge-Kutta methods

\left[ \begin{array}{c|c} c & A \\ \hline & b^T \end{array} \right] = \left[ \begin{array}{c|cc}
c_0 & a_{00} & 0 \\
c_1 & a_{10} & a_{11} \\
\hline
& b_0 & b_1
\end{array} \right]
# From Hairer and Wanner Table 6.5 L-stable SDIRK
dirk4 = RKTable([1/4 0 0 0 0; 1/2 1/4 0 0 0; 17/50 -1/25 1/4 0 0; 371/1360 -137/2720 15/544 1/4 0; 25/24 -49/48 125/16 -85/12 1/4],
    [24/24 -49/48 125/16 -85/12 1/4; 59/48 -17/96 225/32 -85/12 0]);
#dirk4.A
function plot_stability(Rz, title; xlims=(-3, 3), ylims=(-2, 2))
    x = LinRange(xlims[1], xlims[2], 100)
    y = LinRange(ylims[1], ylims[2], 100)
    heatmap(x, y, (x, y) -> abs(Rz(x + 1im*y)), c=:bwr, clims=(0, 2), aspect_ratio=:equal, title=title)
end
plot_stability (generic function with 1 method)
plot_stability(z -> rk_eff_stability(z, dirk4, brow=1), "DIRK fourth order")
Loading...
plot_stability(z -> rk_eff_stability(z, dirk4, brow=2), "DIRK third order")
Loading...

Fully implicit Runge-Kutta methods

\left[ \begin{array}{c|c} c & A \\ \hline & b^T \end{array} \right] = \left[ \begin{array}{c|cc}
c_0 & a_{00} & a_{01} \\
c_1 & a_{10} & a_{11} \\
\hline
& b_0 & b_1
\end{array} \right]
radau3 = RKTable([5/12 -1/12; 3/4 1/4], [3/4 1/4])
plot_stability(z -> rk_eff_stability(z, radau3), "Radau 3")
Loading...
gauss4 = RKTable([1/4 1/4-sqrt(3)/6; 1/4+sqrt(3)/6 1/4],
    [1/2 1/2])
plot_stability(z -> rk_eff_stability(z, gauss4), "Gauss 4")
Loading...

Explore benchmarks: https://benchmarks.sciml.ai/

  • Find at least one interesting figure

  • You can work in groups

Report-out/discuss next class

  • Explain something about the figure

  • Ask a question