$$ \newcommand{d}{\mathrm{d}} \newcommand{deriv}[2]{\frac{\d #1}{\d #2}} \newcommand{pderiv}[2]{\frac{\partial #1}{\partial #2}} $$

Implementing a Fourth Order Runge-Kutta Method for Orbit Simulation

Preface

In 2008, I wrote a small document describing how to implement a fourth order Runge-Kutta time integration method for simulating orbits in a gravity potential. At the time, I had to do this for partical work for a university course and was annoyed at how difficult this was to find on the internet. Apparently, I was not the only one: it has since been “cited” (Google Scholar is not too fussy about what it considers a citation) several times; most of its downloads coming from someone uploading it to their university's domain.

This page can be considered an interactive addendum to the previous article. Its main purpose is to provide me with a project to experiment with features of the modern web. The last time I made a website coincides with the publication of the 2008 article—a lot has happened since then. I'll try to keep the flamboyance in check.

Introduction

Goal: orbit simulation

Runge-Kutta methods are an explicit time-stepping method to solve initial value problems of the form $\Delta t$: $$ \pderiv{y}{t} = f(y, t) $$ $$ y(t_0) = y_0 $$ A time step with the fourth order Runge-Kutta method (henceforth RK4) is defined as: $$ y_{n+1} = y_n + \frac{\Delta t}{6} \left( k_1 + 2 k_2 + 2 k_3 + k_4 \right) $$ where $\Delta t$ is the time step, and the coefficients $k_{1..4}$ are defined as: $$ k_1 = f(y_n, t_n) $$ $$ k_2 = f \left( y_n + k_1 \frac{\Delta t}{2}, t_n + \frac{\Delta t}{2} \right) $$ $$ k_3 = f \left( y_n + k_2\frac{\Delta t}{2}, t_n + \frac{\Delta t}{2} \right) $$ $$ k_4 = f \left( y_n + k_3 \Delta t, t_n + \Delta t \right) $$