We have seen that be doubling the work we do, the midpoint and trapezodial rules give higher accuracy - a factor of 2 in work, like halving the timestep, results in a factor of 4 reduction in error. Thats the beauty of higher order methods. Where is the optimum trade-off between extra work and higher (formal) order of accuracy. Experience points us to the fourth-order Runge-Kutta method.
For straight-forward equations or systems, this 4th order R-K is the method of choice. Easy to code, and very accurate.
There is a wrinkle that needs to be added. Of course.
We usually say something like `I'd like to solve this ODE to 3 digits accuracy'.
That is, we specify an absolute error we'd like to beat. We don't specify the timestep-
that is decided as necessary to reach desired error, more or less. But since we don't
know the constant in front of that
, we find ourselves in something of
a pickle. Enter the wrinkle.
Consider two numerical solutions, say
, the first
computed with a RK method of local truncation error
, the second
computed with a method of one order higher - local truncation error
.
We have a good estimate of the local truncation error
If this error is too big - say it exceeds a specified tolerance
-, then
we can change the timestep and recompute to meet the tolerance bound
A little algebra gives
A widely-used version of the above uses 4th-5th orders RK. The key to efficiency is to choose evaluation points of f in common to both calculations; thats where the savings come in and make the method worthwhile.
By using RK45, you take small steps where the solution is changing rapidly, and large steps where the solution is very well behaved. Timestep increases should be limited not to grow too rapidly; decreases in the timestep are whatever they have to be. You shouldn't try to code this one yourself. Lots of places where bugs can crop into your work. Look uphttp://www.netlib.org, and browse the repository, finding textbook/mathews/chap9.f. Down there are several higher-order codes to solve an ODE, RK45 among them. You can see that, although straightforward in principle, you need to be a little careful when codeing this one up.