Second Order Runge-Kutta Integration

Required Reading

The Midpoint Method

We will now take the lessons from the derivation of Euler's method to develop a higher-order integrator. Consider a first order ordinary differential equation in the form

\begin{equation} \frac{df}{dx} = g(x). \label{ode3} \end{equation}

To advance the solution using Euler's method, take the derivative at the beginning of the interval:

\begin{equation} f(x + \Delta x) = f(x) + g(x) \Delta x. \label{euler_gx} \end{equation}

To discover a second order integration scheme, consider what happens when the derivative is taken as the middle of the interval instead:

\begin{equation} f(x + \Delta x) = f(x) + \Delta x \frac{df}{dx}\Biggr\rvert_{x + {\Delta x}/2.} \label{midpoint} \end{equation}

Once again take the Taylor expansion of $\frac{df}{dx}$:

\begin{equation} \eqalign{ f(x + \Delta x) &= f(x) + \Delta x \frac{df}{dx}\Biggr\rvert_{x + {\Delta x}/2} \cr &= f(x) + \Delta x (\frac{df}{dx}\Biggr\rvert_x + \frac{\Delta x}{2}\frac{d^2f}{dx^2}\Biggr\rvert_x + \frac{\Delta x^2}{8}\frac{d^3f}{dx^3}\Biggr\rvert_x) \cr &= f(x) + \Delta x \frac{df}{dx}\Biggr\rvert_x + \frac{\Delta x^2}{2}\frac{d^2f}{dx^2}\Biggr\rvert_x + \frac{\Delta x^3}{8}\frac{d^3f}{dx^3}\Biggr\rvert_x \cr &= f(x) + \Delta x \frac{df}{dx}\Biggr\rvert_x +\frac{\Delta x^2}{2}\frac{d^2f}{dx^2}\Biggr\rvert_x + O(x^3). } \label{midpoint_expansion} \end{equation}

By taking the derivative at the middle of the interval instead of the beginning, a scheme of second order accuracy is achieved.

Equation \eqref{rungekutta} shows the steps involved in the integration scheme known as the Midpoint method or the second order Runge-Kutta method:

\begin{equation} \eqalign{ f(x_{i+1/2}) & = f(x_i) + \frac{\Delta x}{2} \cdot g(x_{i}, f(x_{i})) \cr f(x_{i+1}) & = f(x_{i}) + \Delta x \cdot g(x_{i+1/2}, f(x_{i+1/2})). } \label{rungekutta} \end{equation}

If $g$ depends only on $x$ and not $f$, the scheme can be simplified to one step:

\begin{equation} f(x_{i+1}) = f(x_{i}) + \Delta x \cdot g(x_{i+1/2})). \label{rungekutta2} \end{equation}