
# 2.10 Generic second order Runge-Kutta method

We seek to derive a generic second order Runge-Kutta method for the solution of a generic ODE (2.2) on the form: \begin{align} y_{n+1} &= y_{n} + h \left ( a_1 \, K_1 + a_2 \, K_2 \right ) \tag{2.86} \end{align}

where $$a_1$$ and $$a_2$$ are some weights to be determined and $$K_1$$ and $$K_2$$ are derivatives on the form: \begin{align} K_1 & = f(x_n,y_n) \qquad \text{and} \qquad K_2 = f(x_n + p_1\, h,y_n + p_2 \, K_1 \,h ) \tag{2.87} \end{align}

By substitution of (2.87) in (2.86) we get: \begin{align} y_{n+1} &= y_{n} + a_1 h\;f(x_n,y_n) + a_2 h \; f(x_n + p_1\, h,y_n + p_2 \, K_1 \,h ) \tag{2.88} \end{align}

Now, we may find a Taylor-expansion of $$f(x_n + p_1\, h,y_n + p_2 \, K_1 \,h )$$: \begin{align} f(x_n + p_1\, h,y_n + p_2 \, K_1 \,h ) &= f + p_1 h \; f_x + p_2 K_1 h\; f_y + \text{h.o.t.} \nonumber \\ & = f + p_1 h \; f_x + p_2 h \;f f_y + \text{h.o.t.} \tag{2.89} \end{align} where we for convenience have adopted the common notation for partial derivatives \begin{align} f_x \equiv \frac{\partial f}{\partial x} \qquad \text{and} \qquad f_y \equiv \frac{\partial f}{\partial y} \tag{2.90} \end{align}

By substitution of (2.89) in (2.88) we eliminate the implicit dependency of $$y_{n+1}$$ \begin{align} y_{n+1} &= y_{n} + a_1 h\,f(x_n,y_n) + a_2 h \left ( f + p_1 h \; f_x + p_2 h \; f f_y \right ) \nonumber \\ &= y_{n} + (a_1 + a_2)\; h f + \left ( a_2 p_1 \; f_x + a_2 p_2 \;f f_y \right ) \, h^2 \tag{2.91} \end{align}

Further, a second order derivative of the solution to (2.2) may be obtained by differentiation: \begin{align} y'' = \frac{d^2 y}{dx^2} = \frac{df}{dx} = \partial{f}{x} \; \frac{dx}{dx} + \partial{f}{y} \frac{dy}{dx} = f_x + f f_y \tag{2.92} \end{align} which may be used in a second order Taylor expansion of the solution of (2.2): \begin{align} y(x_n+h) = y_n + h y' + \frac{h^2}{2} \; y'' + O(h^3) \tag{2.93} \end{align} Substitution of (2.92) and (2.2) into (2.93) yields: \begin{align} y(x_n+h) = y_n + h f + \frac{h^2}{2} \left (f_x + f f_y \right ) + O(h^3) \tag{2.94} \end{align}

Now the idea of the generic second order Runge-Kutta method is to select $$a_1$$, $$a_2$$, $$K_1$$, and $$K_2$$ in such a way that (2.91) approximates (2.94), which will be true if: \begin{align} a_1 + a_2 = 1 \nonumber \\ a_2 \, p_1 = \frac{1}{2} \tag{2.95}\\ a_2 \, p_2 = \frac{1}{2} \nonumber \end{align}

Note, that since we have 4 unknowns ($$a_1$$, $$a_2$$, $$K_1$$, and $$K_2$$) and only 3 equations in (2.95), several methods of the kind proposed in (2.86) are possible. 2.9 Heun's method is retrieved by selecting $$a_2=1/2$$, from which we get $$a_1=1/2$$ and $$p_1=p_2=1$$ from (2.95).