In pure mathematics courses, a lot of attention is paid to the properties of differential equations and analytical techniques for solving them. Unfortunately, many differential equations, including nearly all non-linear ones, encountered in the real world are not amenable to analytic solution. Even the apparently simple task of solving the problem
![]()
involves considerable effort before the unwieldy solution
![]()
is obtained. Even then a lot more effort is required to extract the value of y, corresponding to one value of x. In such situations, it is preferable to use a numerical approach from the start!
Partial differential equations are beyond the scope of this text, but in this and the next Step we shall take a brief look at some methods for solving the single first-order ordinary differential equation
![]()
for a given initial value y(x0) = y0. The first-order differential equation and the given initial value constitute a first-order initial value problem. The numerical solution of this problem involves an estimation of the values of y(x) at, as a rule, equidistant points x1, x2,..., xN. For the sake of convenience, we shall assume that these points are indeed equidistant and use h to denote the constant step length. In practice, it is sometimes desirable to adjust the step length as the numerical method proceeds. For instance, one may wish to use a smaller step length when a point is reached at which the derivative is especially large.
The numerical methods for first-order initial value problems may be used (in a slightly modified form) to solve higher-order differential equations. A simple (optional) introduction to this topic is given in STEP 35.
We have already encountered one technique available for this problem; we can estimate the value of y(x1) by means of a Taylor sequence of order p, the particular value of p depending on the magnitude of h and the accuracy required:
,
where y(x0) is given and y'(x0) can be found by substitution of x = x0 and y = y0 into the differential equation, while the evaluation of y"(x0), . . . , y(p)(x0) requires differentiation of f(x,y), which can be messy. Note that y1, y2,.. , yN will be used to denote the estimates of y(x1), y(x2),..., y(xN2).
Once yl has been computed, we can estimate y(x2) by a Taylor series, based either on x1, when the error in y1 will be propagated, or on x0, when p may have to be increased. In the local approach, yn+1 is computed from a Taylor series, based on xn, while in the global approach yl, y2, . . ., yN are all computed from the Taylor series based on x0. The local approach is more commonly used in practice. The Taylor series method based on the local approach is referred to as a single-step method, since yn+1 depends only on the preceding approximation yn. Only single-step methods will be discussed in this Step; multi-step methods are the topic of the next Step.
One way of avoiding differentiation of f(x, y) is to fix p = 1 and compute:
.
This is Euler's method. However, unless the step length h is very small, the truncation error will be large and the results inaccurate.
A popular way of avoiding differentiation of f(x, y) without sacrificing accuracy involves estimation of yn+1 from yn and weighted averaging of values of f (x, y), chosen so that the truncation error is comparable to that of a Taylor series of order p. Details of the derivation of this approach lie beyond the scope of this book, but we will quote two of the simpler Runge-Kutta methods, which are suitable for computer implementation.( PSEUDO-CODE).
The first has the same order of accuracy as the Taylor series method with p = 2 and is usually presented in three steps:
.
The second is the fourth-order method:
.
We see that neither method involves evaluations of derivatives of f(x, y); instead, f(x, y) itself is evaluated twice in the second-order method, four times in the fourth-order method.
It is instructive to compare some of the methods given above by application to a very simple problem. For example, we will estimate the value of y(0.5), given that
.
The exact solution of this problem is
whence y(0.5) = 1.797 44. We shall
use a fixed step length h = 0.1 and work to 5D:
,
whence
,
a result which is not even accurate to 1D; in fact, the error is approximately 0.08.
Since
,
we find
.
Thus,
.
which is accurate to 4D, the approximate error being 0.000 01.
![]()
and
:
.
which is accurate to 2D, the error being approximately 0.003.
As we might have expected, the fourth-order method is obviously superior, the first-order method is clearly inferior, and the second-order method lies in between.
y' = x + y with y(0) = 1,
considered in the preceding section, by performing three more steps of: