Runge-Kutta integration

Runge-Kutta schemes are more complex than the Euler scheme, but they pay off in terms of considerably greater accuracy. If accuracy is critical for your simulation, you should seriously consider Runge-Kutta. It does come at a performance price, though, especially if you opt for the higher-order schemes. We'll describe two of the most popular Runge-Kutta schemes.

Second-order Runge-Kutta scheme (RK2)

The second-order Runge-Kutta method (RK2) is also known as Heun's method or the improved Euler method. It is a two-stage predictor-corrector method that uses the explicit Euler's method as predictor and a so-called trapezoidal method as corrector. Here are the equations defining the method:

The temporary variables p1, v1

Get The Essential Guide to Physics for Flash Games, Animation, and Simulations now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.