2.3. Derivation of Explicit Runge-Kutta Methods#
The derivation of an explicit Runge-Kutta method is achieved by comparing the Taylor series for the first-order ODE \(y'=f(t,y)\) to that of the general Runge-Kutta method and ensuring the coefficients \(a_{ij}\), \(b_i\) and \(c_i\) match.
For example, consider the second-order Taylor series expansion of \(y_{n+1}\)
We wish to solve the ODE \(y' = f(t,y)\), applying the chain rule to differentiate \(y\) we have
where the subscript notation \(f_y\) denotes the partial derivative of \(f\) with respect to \(y\).
So the Taylor series in equation (2.4) becomes
This is the second-order Taylor series expansion for the ODE \(y' = f(t,y)\). To be able to solve this ODE we need the Taylor series expansion of a Runge-Kutta method to be equivalent to equation (2.5). The general form of a 2-stage explicit Runge-Kutta method is
Using the bivariate Taylor series which is
then replacing \(h\) and \(k\) with \(c_2h\) and \(h_{a21}k_1\) respectively, then we can rewrite \(k_2\) as
Substituting \(k_1\) and \(k_2\) into the equation for \(y_{n+1}\) in equation (2.6) gives
We need equation (2.7) to be equal to equation (2.5). Equating the coefficients of \(f\) we have (the \(h\)’s cancel out)
Equating the coefficients of \(f_t\) we have
and equating the coefficients of \(ff_y\) we have
From equation (2.9) we know that \(b_2 = \dfrac{1}{2c_2}\) so
So we have the three equations (2.8), (2.9) and (2.10) expressed in four unknowns (\(a_{21}\), \(b_1\), \(b_2\), \(c_2\)). Any set of values that satisfy these this system of equations give a valid second-order explicit Runge-Kutta method. These conditions are known as the order conditions for a method. Since we have an underdetermined system to get a unique solution we choose a value for one of the unknowns and solve for the others.
(Order conditions for a second-order explicit Runge-Kutta method)
Derive two second-order Runge-Kutta ERK methods where
(i) \(c_2 = 1\);
Solution (click to show)
Substituting \(c_2 = 1\) into the order conditions gives \(b_2 = \frac{1}{2}\), \(b_1 = \frac{1}{2}\) and \(a_{21} = 1\). So this second-order ERK method is
or expressed using a Butcher tableau
This method is known as Heun’s method.
(ii) \(b_2 = 1\).
Solution (click to show)
Substituting \(b_2=1\) into the order conditions gives \(b_1=0\), \(c_2 = \frac{1}{2}\) and \(a_{21} = \frac{1}{2}\) so this second-order ERK method is
or expressed using a Butcher tableau
This method is known as the midpoint method.
Note
There are an infinite number of combinations for the values of \(a_{ij}\), \(b_i\) and \(c_i\) which satisfy the order conditions for a Runge-Kutta method. All of the possible Runge-Kutta methods of a particular order will the same solutions (computational rounding permitted).
2.3.1. Using Python and MATLAB to solve the order conditions#
The algebra used to solve the order conditions in Example 2.2 is quite simple but for higher order methods it can soon get more complicated (see the derivation of a fourth-order explicit Runge-Kutta method for an example) and it is useful to use software to help with the algebra. The following code shows how Python and MATLAB can be used to solve the order conditions for Example 2.2.
There is a Python library SymPy (short for Symbolic Python) that has functions that can solve algebraic equations. After importing SymPy we need to declare each of the coefficients \(a_{21}\), \(b_1\), \(b_2\) and \(c_2\) as symbolic variables using the sp.symbols()
command before setting \(c_2=1\). Each order condition is then defined using these symbolic variables. Note that SymPy assumes that equations are equal to zero which is why we have subtracted the right-hand side. We have also used the sp.Rational(1,2)
command for the fraction \(\frac{1}{2}\) so that SymPy will output any fractional values as fractions rather than decimals. The system of three equations eq1
, eq2
and eq3
is then solved using the sp.solve
command.
import sympy as sp
# Declare symbolic variables
a21, b1, b2, c2 = sp.symbols("a21, b1, b2, c2")
c2 = 1
# Define order conditions
eq1 = b1 + b2 - 1
eq2 = b2 * c2 - sp.Rational(1,2)
eq3 = a21 - c2
# Solve order conditions
sp.solve((eq1, eq2, eq3))
We first declare each of the coefficients \(a_{21}\), \(b_1\), \(b_2\) and \(c_2\) as symbolic variables using the syms
command before setting \(c_2=1\). Each order condition is then defined using these symbolic variables. Note that the ==
command is used for the equals sign in each order condition. The system of three equations eq1
, eq2
and eq3
is then solved using the solve
command.
% Declare symbolic variables
syms a21 b1 b2 c2
c2 = 1;
% Define order conditions
eq1 = b1 + b2 == 1;
eq2 = b2 * c2 == 1/2;
eq3 = a21 == c2;
% Solve order conditions
solve(eq1, eq2, eq3)