2.5. Derivation of a fourth-order explicit Runge-Kutta method#
In the previous section we derived the rooted-tree order conditions for an explicit Runge-Kutta method. We now use these conditions to construct a fourth-order method. Unlike the derivation of RK2, which could be done using Taylor series expansions directly, the rooted-tree approach allows us to derive higher-order methods systematically without lengthy algebraic calculations.
For a fourth-order method we require all rooted trees of order up to 4. There are eight such trees. For each tree we determine its elementary weight \(\Phi(\tau)\), density \(\gamma(\tau)\), and then apply the condition
So to derive the order conditions for a fourth-order explicit method we consider all of the rooted trees up to and including order 4 which are tabulated below along with their elementary weights and densities.
\(\tau\) |
||||||||
|---|---|---|---|---|---|---|---|---|
\(r(\tau)\) |
1 |
2 |
3 |
3 |
4 |
4 |
4 |
4 |
\(\Phi(\tau)\) |
\(\displaystyle\sum_i b_i\) |
\(\displaystyle\sum_i b_ic_i\) |
\(\displaystyle\sum_i b_ic_i^2\) |
\(\displaystyle\sum_{i,j} b_ia_{ij}c_j\) |
\(\displaystyle\sum_i b_ic_i^3\) |
\(\displaystyle\sum_{i,j} b_ia_{ij}c_ic_j\) |
\(\displaystyle\sum_{i,j} b_ia_{ij}c_j^2\) |
\(\displaystyle\sum_{i,j,k} b_ia_{ij}a_{jk}c_k\) |
\(\gamma(\tau)\) |
1 |
2 |
3 |
6 |
4 |
8 |
12 |
24 |
The minimum number of stages for explicit Runge-Kutta method of different orders are shown in the table below [Hairer and Wanner, 1993].
Order |
1st |
2nd |
3rd |
4th |
5th |
6th |
7th |
|---|---|---|---|---|---|---|---|
Minimum stages required |
1 |
2 |
3 |
4 |
6 |
7 |
9 |
Therefore we seek a 4-stage ERK method, so \(s=4\) and the order conditions are
Since we are deriving the order conditions for an explicit method we know that \(c_1=0\) and \(a_{ij} = 0\) where \(i \leq j\), and we have the Butcher tableau
So we can omit any terms in the summations where the values of the \(c_1\) and \(a_{ij}\) coefficients are zero (i.e., the upper triangular elements of \(A\)). For example
since for an ERK method, \(a_{ij} = 0\) for \(i \le j\) and \(c_1 = 0\), then this simplifies to
So the first four order conditions from equation (2.15) simplify to
For the next 3 order conditions, the \(a_{ij}c_j\) term is only non-zero when \(i = 3, 4\) and \(j = 2, 3\), so we have
For the final order condition from equation (2.15), the \(a_{ij}a_{jk}c_j\) term is only non-zero when \(i=4\), \(j=3\) and \(k=2\) so we have
We have now derived the order conditions for a fourth-order explicit Runge-Kutta method which are combined with the row sum conditions. Using rooted trees to do this is much easier than expanding out the Taylor series for the ODE \(y'=f(t, y)\) and the general form of a 4-stage Runge-Kutta method which would require several pages of complicated calculus and algebra.
Definition 2.1 (Order conditions for a fourth-order explicit Runge-Kutta method)
The method contains 14 coefficients, but the row-sum conditions relate the \(c_i\) values to the \(a_{ij}\) coefficients. Consequently the system possess three degrees of freedom, allowing infinitely many fourth-order ERK methods. So to derive a method we need to select values for at least three of the unknown coefficients and solve for the remaining ones.
Example 2.6
Derive a fourth-order Runge-Kutta method where \(c_2 = c_3 = \frac12\), \(c_4 = 1\) and \(b_2 = b_3\).
Solution
Substituting \(c_2 = c_3 = \frac12\) and \(c_4 = 1\) into the first four order conditions gives
Subtracting \(\frac12\) times the third equation from the second
so \(b_4 = \frac16\) and the second equation is
Since in this case we want \(b_2\) and \(b_3\) to be the same we have \(b_2 = b_3 = \frac13\). Substituting \(b_2\), \(b_3\) and \(b_4\) into the first equation gives \(b_1 = \frac16\).
Substituting the values of \(b_i\) and \(c_i\) into the fifth, sixth and seventh order conditions gives
Subtracting \(\frac{1}{2}\) times the first equation from the second
so \(a_{42} = 1 - a_{43}\). Substituting \(b_4\) and \(c_2\) into the eighth order condition gives
so \(a_{32} = \frac{1}{2a_{43}}\). Substituting \(a_{32}\) and \(a_{42}\) into the first equation from (2.17) gives
So \(a_{43} = 1\) and \(a_{32} = \frac{1}{2}\). Entering in the known values of \(a_{ij}\), \(b_i\) and \(c_i\) into the Butcher tableau we have
The remaining values of \(a_{21}\), \(a_{31}\) and \(a_{41}\) are found using the row-sum condition
so \(a_{21} = \frac{1}{2}\), \(a_{31} = 0\) and \(a_{41} = 0\) and the Butcher tableau is
or alternatively
This fourth-order explicit Runge-Kutta method is often referred to as the Runge-Kutta method or RK4 for short. It is simple, robust and accurate and has become the standard go to method for solving ODEs.
2.5.1. Code#
We saw in the example derivation of the RK4 method that solving the order conditions can be quite an involved process. In practice, we utilise mathematical software to do the algebra for us.
import sympy as sp
# Declare symbolic variables
a21, a31, a32, a41, a42, a43, b1, b2, b3, b4 \
= sp.symbols("a21, a31, a32, a41, a42, a43, b1, b2, b3, b4")
c2, c3, c4 = sp.Rational(1,2), sp.Rational(1,2), 1
# Define order conditions
eq1 = b1 + b2 + b3 + b4 - 1
eq2 = b2 * c2 + b3 * c3 + b4 * c4 - sp.Rational(1,2)
eq3 = b2 * c2**2 + b3 * c3**2 + b4 * c4**2 - sp.Rational(1,3)
eq4 = b2 * c2**3 + b3 * c3**3 + b4 * c4**3 - sp.Rational(1,4)
eq5 = b3 * a32 * c2 + b4 * a42 * c2 + b4 * a43 * c3 - sp.Rational(1,6)
eq6 = b3 * a32 * c2 * c3 + b4 * a42 * c2 * c4 + b4 * a43 * c3 * c4 - sp.Rational(1,8)
eq7 = b3 * a32 * c2**2 + b4 * a42 * c2**2 + b4 * a43 * c3**2 - sp.Rational(1,12)
eq8 = b4 * a43 * a32 * c2 - sp.Rational(1,24)
eq9 = a21 - c2
eq10 = a31 + a32 - c3
eq11 = a41 + a42 + a43 - c4
# Choose b2 = b3 (this is an additional condition for the RK4 method)
eq12 = b2 - b3
# Solve the order conditions
sp.solve((eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10, eq11, eq12))
Output
{a31: 0,
a32: 1/2,
a41: 0,
a42: 0,
a43: 1,
b1: 1/6,
b2: 1/3,
b3: 1/3,
b4: 1/6,
a21: 1/2}
% Define symbolic variables
syms a21 a31 a32 a41 a42 a43 b1 b2 b3 b4
% Define known coefficients
c2 = 1/2;
c3 = 1/2;
c4 = 1;
% Define order conditions
eq1 = b1 + b2 + b3 + b4 == 1;
eq2 = b2 * c2 + b3 * c3 + b4 * c4 == 1/2;
eq3 = b2 * c2^2 + b3 * c3^2 + b4 * c4^2 == 1/3;
eq4 = b2 * c2^3 + b3 * c3^3 + b4 * c4^3 == 1/4;
eq5 = b3 * a32 * c2 + b4 * a42 * c2 + b4 * a43 * c3 == 1/6;
eq6 = b3 * a32 * c2 * c3 + b4 * a42 * c2 * c4 + b4 * a43 * c3 * c4== 1/8;
eq7 = b3 * a32 * c2^2 + b4 * a42 * c2^2 + b4 * a43 * c3^2 == 1/12;
eq8 = b4 * a43 * a32 * c2 == 1/24;
eq9 = a21 == c2;
eq10 = a31 + a32 == c3;
eq11 = a41 + a42 + a43 == c4;
% Solve the order conditions
solve(eq1, eq2, eq3, eq4, eq5, eq6, eq7, eq8, eq9, eq10, eq11)
Output:
ans = struct with fields:
a21: 1/2
a31: 0
a32: 1/2
a41: 0
a42: 0
a43: 1
b1: 1/6
b2: 1/3
b3: 1/3
b4: 1/6