4th-order Runge-Kutta#
One of the most widely-used methods for ODE integration is 4th-order Runge-Kutta (RK4). This consists of 4 stages, each estimating the slope of the solution at a different time or with a different prediction of the state. These are then combined in a final update to advance the solution. The sequence is illustrated below:
The advance begins by estimating the derivatives (righthand side or slope) at time \(t^n\). We’ll call this \({\bf k}_1\).
We then follow the slope \({\bf k}_1\) to the midpoint in time, \(t^{n+1/2}\) and evaluate the slope there. We call the new slope \({\bf k}_2\).
We then go back to the start, but this time follow the new slope, \({\bf k}_2\) to the midpoint in time, \(t^{n+1/2}\). We again evaluate the slope here, and call it \({\bf k}_3\).
try it…
Let’s modify our orbit integration code to do RK4.