Whatever the underlying method for solving an ODE, a major problem lies in determining a good stepsize. Ideally, we want to choose as large as possible - but not so large as to give us an unreasonable amount of error, or worse still, to induce instability. If we choose a fixed stepsize, we can only proceed as fast as the "worst" sections of will allow. What we would like to do is to vary as we march forward in time. Whenever we can make large without incurring too much error, we should do so. When has to be reduced to avoid excessive error, we want to do that also. This is the idea of adaptive stepsizing: varying over the course of solving the ODE.
Adaptive Stepsizes - Euler Method
Here we'll be present adaptive stepsizing for Euler's method. The basic idea as follows. Lets assume we have a given stepsize , and we want to know how much we can consider changing it.
Suppose we compute two estimates for . We compute an estimate
,
by taking an Euler step of size of size from to
. We also compute
an estimate by taking two Euler steps of size , from to
. Both and differ from the true value of
by . That
means that and differ from each other by
. As a result, we can
write that a measure of the current is
Therefore, a new time step can be guessed via
A partial implementation of this idea can be found in skeleton_adaptive_euler.c
The code illustrates the calculation of a new step size and simply returns it via the calling sequence to be used in the next time step. The logic of repeating the step for wich the error was judged to be too large is not implemented for simplicity.
Documentation on this approach can be found in Lecture Notes by Professors Witkin and Baraff from Carnegie Mellon University..
Adaptive Stepsizes for Runge-Kutta 4th order method
The same logic, a single step versus two steps to reach the time can be used with whatever ODE integrator. But Numerical Recipies argues for another approach in the case of Runge-Kutta 4th order. It amounts to a comparison between the Runge-Kutta 4th order and a solution from a carefully crafted Runge-Kutta 5th order method. Please refer to Numerical Recipies Section 16.2 for a detailed explanation of this method.