The two methods described so far are conceptually simple. However, because they are of low order (that is, the errors scale as fairly low powers of the time step), they are not very efficient -- very often, to reduce the error to an acceptable level, we have to take very short timesteps, and that can cost a lot of computer time. What's more, the Euler method is not necessarily even stable!
An alternative to reducing the timestep (and increasing the cost proportionally) is to use a higher-order method. One of the most popular high-order schemes is the Fourth-Order Runge-Kutta method. It extends the idea of the Mid-point scheme -- using a low-order prediction of the solution to refine our estimate of a higher derivative -- to obtain fourth-order accuracy (i.e. the error scales as the fifth power of the timestep). Here it is:
The steps are depicted graphically below. In effect, if we used only the information on the first line, we would have the Euler method. Add the second line and we have the Mid-point scheme. The information on the next two lines, properly weighted, gives us two more orders of accuracy. If you like, you can expand out the Taylor series for f and verify for yourself that the last equation is indeed fourth-order!
The program rk4.c performs the same operations as the earlier Euler and Mid-point programs. You should perform the same tests as in the last exercise to convince yourself that Runge-Kutta-4 is indeed fourth-order accurate.