
The most popular of the fixed step size methods is the fourth-order Runge-Kutta method. This is the default method in many integrators. The algorithm involves four evaluations of the right-hand sides and gives accracy that is O(h4). The algorithm is :
Note that this is very similar to Simpsons rule for integration as the Heun method is analogous to the trapezoidal rule and Euler to the Riemann sum.
While it seems that higher order rules require more work and more
evaluations of the right-hand sides, for the same accuracy
requirements, they are much more efficient. For example to get an
error of 0.0001 requires h=0.0001 for Eulers method and h=0.1 for
RK4. Thus to advance one time step requires 10000 evaluations of the
right-hand side using Euler and 10 setps of 4 evaluations or 40
evaluations for Runge-Kutta. To see this, consider the example:
# harmonic oscillator
x'=y
y'=-x
x(0)=1
y(0)=0
aux true=cos(t)
done
of the harmonic oscillator. Use Euler's method and set the
Total to 1.000001. Set Dt=.0005 and integrate the
equations. Using the Data Browser compare columns 2 and 4. The fourth
column is the true solution ans the second is the approximate. 2000
function evaluations were required and you still get agreement only to
3 decimals. Now set Dt=.1 and set the method to
Runge-Kutta. Integrate again and you will see that you have 4 place
accuracy! This was only 40 function evaluations. It is much more
efficient and more accurate. Moral: Sometimes the increased
expenditure in coding pays you back with dramatic results.