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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.