Numerical Solution of Differential Equations by Direct Taylor Expansion

A variation of the direct Taylor expansion algorithm is suggested and applied to several linear and nonlinear differential equations of interest in physics and engineering, and the results are compared with those obtained from other algorithms. It is shown that the suggested algorithm competes strongly with other existing algorithms, both in accuracy and ease of application, while demanding a shorter computation time.


Introduction
With the advent of high speed personal computers and workstations and the decrease of the cost of computer resources in general, numerical methods and computer simulation have become an integral part of the scientific method and a third approach to the study of physical problems, in addition to theoretical and experimental methods.
The problem of solving differential equations numerically had long been of interest to mathematicians and scientists alike, long before the appearance of modern computers.One of the oldest and simplest algorithms is the Euler method, also known as the Euler-Cauchy method or the polygonal method [1]- [8].
This algorithm utilizes the definition of the derivative of a function, to solve first-order differential equations of the form [9] ( ) subject to initial condition ( ) 0 0 y x y = .The method replaces the differential equation by a difference equation and, using a small enough step size x h ∆ = , advances the solution from n x to The Euler method can also be viewed as a Taylor expansion of the function about point n x and retaining only the first two terms.Thus the remaining terms, or the error in the Euler algorithm, is given by where ξ is some value of x in the interval under consideration of width h .
Consequently, the local error in the Euler method is of the order of 2 h , resulting in a global error of the order of h .The Euler algorithm is, therefore, first order [10].Achieving high accuracy with a first-order algorithm in some cases require very small intervals h (hence too many steps), increasing the total computation time and round-off error, resulting in instability of the algorithm.
An improved version of the Euler method is obtained by retaining three terms in the Taylor expansion of the function instead of two, yielding a second order algorithm [6].Alternatively, one can advance the solution from n x to 1 n x + by using the value of the derivative at the midpoint of the interval rather that at the beginning, ( ) This algorithm is known as the modified Euler method, the midpoint method, or the second-order Runge-Kutta method [1] [2] [7].It can be shown that this method is equivalent to the first three terms of the Taylor series described above.
Yet another way of improving the order of the Euler method is to use the average value of the derivative at the beginning and at the end of each interval, ( ) ( ) where 1 n y + on the right hand side is obtained from Equation (3).This algo- rithm is referred to as the Adams-Bashforth rule [6], and is second order.
The accuracy of the Euler method can be improved further by including higher terms of the Taylor expansion in the numerical calculations.Thus, by including the first five terms, one achieves a fourth-order algorithm.This approach, also referred to as the "Creeping up" process, has been mentioned in a limited number of references [7] [11], but has not received much attention.In particular, the discussion of this method in connection with the differential equations of order higher than one has been very limited in the literature [12].This is mainly due to the general concern that in all but the simplest cases the necessary higher-order derivatives tend to become quite complicated, rendering the computations extraordinarily tedious [3] [8].Thus, it is believed that the Taylor expansion method is generally not practical if derivatives of higher order P. Mohazzabi, J. L. Becker than the first are retained.It has also been stated that the method is not sufficiently accurate away from the initial point [6].
Currently the most widely used numerical algorithms for solving differential equations are the fourth-order Runge-Kutta (RK), fourth-order Adams-Bashforth-Moulton (ABM), and the fourth-order Milne methods.The RK algorithm [12] [13] is single-step, or self starting, and is the most commonly used method among the three.The ABM and the Milne algorithms are multi-steps and are not self starting [1] [14].They are normally started by using a single-step algorithm, such as the RK algorithm.
The objective of this article is to discuss a variation of the direct Taylor series (DTS) algorithm for the solution of first-and higher-order differential equations.
We show that not only this algorithm remains accurate away from the initial point, evaluation of the higher derivatives that are needed for accuracies comparable to the RK, ABM, and Milne methods are indeed quite simple.Finally, the accuracy and ease of application of the DTS method are explicitly demonstrated by considering several important second-order linear and nonlinear differential equations of mathematical physics and comparing their solutions using the fourth-order DTS, RK, ABM, and Milne methods.

A Variation of the Direct Taylor Series (DTS) Method
Consider a first-order differential equation given by (2).We expand the solution of this differential equation in a Taylor series about the initial point in each interval n x to obtain its value at the end of that interval where ( ) y x y = , this expansion can be used iteratively to solve the differential equation up to some final value of the independent variable.The higher derivatives of the function, which are required in Equation (7), can be obtained by successive differentiation of the original differential Equation (2).Thus, Although these equations look tedious, their evaluations in most cases are quite straightforward and result in fairly simple expressions.
Using terms up to and including the k -th order in Equation ( 7) (i.e., retaining 1 k + terms), results in a local error of ( ) ( ) ( ) and, thus, a global error of the order of k h .Since the commonly used high- order numerical algorithms for solving differential equations are fourth order, we restrict our attention to Taylor expansions up to and including the fourth derivative, resulting in a fourth-order algorithm for comparison.
The DTS algorithm can be extended to numerically solve a differential equation of any order.To demonstrate this, consider a second-order differential equation given by subject to the initial conditions ( ) . Of course, this equation can always be reduced to a system of two first-order differential equations.Alternatively, one can extend the Taylor algorithm as follows: From Equation ( 10) and its differentiation, the second and higher derivatives of the function are obtained and evaluated at 0 x .Then Equation ( 7) is used to advance the solution from the initial point 0 x to 1 x .To advance the solution from 1 x to 2 x , however, various derivatives of the function at 1 x are needed.These, in turn, can be obtained from the Taylor expansion of the derivatives themselves, and, using Equation ( 7), the solution is advanced from 1 x to 2 x .Iteration of these steps will eventually yield the value of the function at the desired final value of the variable.In Equation (11), the order of the highest derivative retained on the right side of each equation should be the same as the order of the numerical algorithm required.Thus, for a the numerical algorithm to be fourthorder, derivatives up to and including the fourth-order should be included in the expansions.
The suggested variation of the direct Taylor series, which we refer to as the DTS method, differs from the standard Taylor series method in the following way.In the standard method, the function is calculated at the required value of the variable x directly from the value of the function and its derivatives at the initial value 0 x [15], In the suggested variation of the algorithm (the DTS method), on the other hand, the interval [ ] 0 , x x is divided into many subintervals, each of width h .The function and its derivatives are then Taylor expanded and advanced from subinterval to subinterval until the function is evaluated at the required value of the variable x , thus resulting in a much greater accuracy.

Comparison with Other Algorithms
Applications of the (direct Taylor series) method, as well as other algorithms, to numerical solutions of first-order differential equations are straightforward and will not be discussed here.Table 1 summarizes the results for several important second-order differential equations of mathematical physics.Each equation, subject to the given initial conditions, is numerically Table 1.Several linear and nonlinear differential equations of interest.Each equation, subject to the initial conditions described, is numerically evaluated at f x x = , using fourth-order Runge-Kutta (RK), Adams-Bashforth-Moulton (ABM), Milne, and the direct Taylor series (DTS) algorithms.In each cases, a step size of 0.1 h = is used.The true values are given for comparison.solved and the function is evaluated at some final value of the variable f x by the fourth-order RK (Runge-Kutta), ABM (Adams-Bashforth-Moulton), Milne, and the DTS algorithms, using a step size 0.1 h = in each case.
In Table 1, Equations (a)-(f) describe different types of oscillating systems.In each equation x is time and y represent an oscillating physical quantity.The first equation corresponds to a sinusoidally driven damped harmonic oscillator.
The second equation is the general equation of a pendulum (simple or compound), oscillating with some (not necessarily small) amplitude.The third is the differential equation of an intrinsically nonlinear oscillator, consisting of a mass tethered by two springs, oscillating in a direction perpendicular to the springs.
Equation (d) describes the motion of a Van der Pol oscillator [16] [17].Equation (e) is the Duffing's equation with damping, describing the oscillations of an externally driven hacksaw blade clamped at one end [18].Finally, (f) is the differential equation of motion of a particle oscillating under a Lennard-Jones (6-12) potential energy function [19].In each case, the final time f x at which the function is evaluated numerically, is chosen such that the oscillator undergoes approximately one-half cycle.The last column gives the "true" value of the function at f x , evaluated either by analytical solution of the differential equation when available, or by a very small step size ( 0.001 h = ), using the fourth-order RK algorithm.
Equations (g)-(j) are some of the common linear differential equations of mathematical physics, namely, Bessel, Legendre, Laguerre, and Hermite, respectively [20].They show up in a variety of physical problems, ranging from heat conduction in solids, to wave equations, to quantum mechanical systems.
In all cases studied, the DTS algorithm generated a noticeably shorter CPU time than any other algorithm.In fact, the average CPU time for the DTS programs was found to be 21%, 58%, and 68% shorter than those for the corresponding RK, Milne and ABM programs, respectively.

Discussion
Based on the results listed in Table 1, we see that in all cases studied the DTS (direct Taylor series) method provides accuracies that are essentially identical to the widely used algorithms of the same order while requiring a shorter computation time.
Evaluation of higher derivatives does not pose any serious difficulty.Indeed, higher derivatives become less problematic for differential equations of higher order.For example, with the fourth-order DTS algorithm and a second-order differential equation, only two higher derivatives should be computed from the differential equation; for a fourth-order equation, no higher-order derivatives are needed.
A striking feature of the DTS method is the ease with which its order of accuracy can be increased.For instance, to increase the order of the algorithm from four to six, one only needs to retain two additional terms in the Taylor expansion.Such an increase of the order of algorithm is not a trivial task in the RK (Runge-Kutta), ABM (Adams-Bashforth-Moulton), or Milne method.Similarly, while generalizations of the latter methods to higher-order differential equations are not trivial, in the former case, it can be accomplished by simply incorporating Taylor expansions for higher derivatives, as we shall demonstrate in the following paragraph.
Third-order differential equations are not common in physics and engineering.Fourth-order equations, on the other hand, are occasionally encountered in some such as bending of beams.As an example, we demonstrate the power of the DTS algorithm for the following simple fourth-order linear differential equation for which the analytical solution exits for comparison, With the sixth-order algorithm and the same step size, we find ( ) 1 2.0641757 y = . These compare with the true value of 2.0641759, obtained from the analytical solution of the differential equation, cosh sinh 2 The discrepancies between the true and the numerical values in the two cases are, respectively, of the order 4 h and 6 h , as they should be.

Conclusion
In conclusion, we see that the direct Taylor series (DTS) algorithm is simple, easy to use, accurate, extendable to higher accuracies by simply retaining higherorder terms in Taylor expansions while requiring noticeably less computation time.Higher-order differential equations can be solved by trivial inclusion of Taylor expansions of higher derivatives.The other algorithms, such as Runge-Kutta, Adams-Bashforth-Moulton, and Milne methods are elegant but require complete construction of their working equations, which can be quite tedious depending on the order of the algorithm.
first, second, third, and fourth derivatives of the function evaluated at n x x = .Using the initial condition of the problem, fourth-order DTS method yields ( ) 1 2.0637 y = .