For simplicity, the following example uses the simplest integration method, the Euler method; in practice, higher-order methods such as Runge–Kutta methods are preferred due to their superior convergence and stability properties. Consider the initial value problem where y and f may denote vectors. We are given the function f and the initial conditions, and we are interested in finding the solution at t = b. Let y denote the exact solution at b, and let yb denote the solution that we compute. We write, where is the error in the numerical solution. For a sequence of values of t, with tn = a + nh, the Euler method gives approximations to the corresponding values of y as The local truncation error of this approximation is defined by and by Taylor's theorem, it can be shown that the localtruncation error is proportional to the square of the step size: where c is some constant of proportionality. We have marked this solution and its error with a. The value of c is not known to us. Let us now apply Euler's method again with a different step size to generate a second approximation to y. We get a second solution, which we label with a. Take the new step size to be one half of the original step size, and apply two steps of Euler's method. This second solution is presumably more accurate. Since we have to apply Euler's method twice, the local error is twice the original error. Here, we assume error factor is constant over the interval. In reality its rate of change is proportional to. Subtracting solutions gives the error estimate: This local error estimate is third order accurate. The local error estimate can be used to decide how stepsize should be modified to achieve the desired accuracy. For example, if a local tolerance of is allowed, we could let h evolve like: The is a safety factor to ensure success on the next try. The minimum and maximum are to prevent extreme changes from the previous stepsize. This should, in principle give an error of about in the next try. If, we consider the step successful, and the error estimate is used to improve the solution: This solution is actually third order accurate in the local scope, but since there is no error estimate for it, this doesn't help in reducing the number of steps. This technique is called Richardson extrapolation. Beginning with an initial stepsize of, this theory facilitates our controllable integration of the ODE from point to, using an optimal number of steps given a local error tolerance. A drawback is that the step size may become prohibitively small, especially when using the low-order Euler method. Similar methods can be developed for higher order methods, such as the 4th-order Runge–Kutta method. Also, a global error tolerance can be achieved by scaling the local error to global scope.
Embedded error estimates
Adaptive stepsize methods that use a so-called 'embedded' error estimate include the Runge–Kutta–Fehlberg, Cash–Karp and Dormand–Prince methods. These methods are considered to be more computationally efficient, but have lower accuracy in their error estimates.