# Taylors Method For Solving Ode Computer Science Essay

Published:

This essay has been submitted by a student. This is not an example of the work written by our professional essay writers.

Â The TaylorÂ Â series method is used for general applicability and it is the standard by which we can compare the accuracy of the various other numerical methods for solving an INITIAL VALUE PROBLEM.Â Â It can be devised to have any specified degree of accuracy.

TheoremÂ Â (Taylor SeriesÂ Â Method of Order n):-

Assume thatÂ Â f(t, y)Â Â is a continuous function and satisfies a Lipschits condition in the variableÂ Â y,Â Â and consider theÂ Â I. V. P. (initial value problem)

Â Â Â Â Â Â Â Â with ,Â Â over the intervalÂ Â .

## Â Â Â Â Â Â Â Â

The Taylor series method uses the formulas ,Â Â andÂ Â

Â Â Â Â Â Â Â Â Â Â Â Â Â forÂ Â Â Â

where isÂ Â Â Â evaluated atÂ Â ,Â Â as an approximate solution to the differential equation using the discrete set of pointsÂ Â .

## Algorithm (Taylor Series Method):-

To compute a numerical approximation for the solution of the initial value problemÂ Â withÂ Â Â Â over Â Â at a discrete set of points using the formulasÂ Â

Â Â Â Â ,Â Â andÂ Â ,Â Â forÂ Â Â Â

## Â Â Â Â

where isÂ Â Â Â evaluated atÂ Â .

Let us consider the example of the second order differential equation

You probably already know that the solution is given by ;

recall that this function has as its Taylor series

cos(2t) = 1 - + - +...,

and that this representation is valid for all .

computing the Taylor series expansion for a given function ,we get

where

Here y(n)(0) denotes the nth derivative of y at the point t=0.

This means that to compute the Taylor series for the solution to our differential equation, we just have to compute its derivatives. Note that the initial conditions give us a head start: y(0)=1, so a0=1. y'(0)=0, so a1=0.

We can rewrite the differential equation as

y''=-4y,

so in particular

Consequently a2=-4/2!=-2. By now, we have figured out that the solution to our differential equation has as its second degree Taylor polynomial the function 1-2t2.

Next we differentiate

y''=-4y

on both sides with respect to t, to obtain

y'''=-4y',

so in particular

y'''(0)=-4y'(0)=0,

yielding a3=0.

We can continue in this fashion as long as we like: Differentiating

y'''=-4y'

yields

y(4)=-4y'',

in particular

so a4=16/4!=2/3. At this point we have figured out that the solution to our differential equation has as its fourth degree Taylor polynomial the function

We expect that this Taylor polynomial is reasonably close to the solution y(t) of the differential equation, at least close to t=0. In the picture below, the solution is drawn in red, while the power series approximation is depicted in blue:

## Let us take another example :-

We try to find the Taylor polynomials for the solution, of the form

where

The initial conditions yield a0=0 and a1=1. To find a2, we rewrite the differential equation as

and plug in t=0:

consequently a2=0.

Next we differentiate

on both sides with respect to t, to obtain

so in particular

yielding a3=-1/3!=-1/6.

Here differentiating with respect to t, we had to use the chain rule to find the derivative of the term .

: We differentiate

to obtain

Consequently y(4)(0)=0, and thus a4=0.

Differentiating

yields

You can check that y(5)=y'(0)3-y'''(0)=1-(-1)=2 and thus a5=2/5!.

The fifth degree Taylor polynomial approximation to the solution of our differential equation has the form

We again expect that this Taylor polynomial is reasonably close to the solution y(t) of the differential equation, at least close to t=0. In the picture below, the solution, as computed by a numerical method, is drawn in red, while the power series approximation is depicted in blue:

## Runge-Kutta methods:-

Runge- Kutta method is one of the well-known numerical methods for differential

equations and the common versions are of order 4 and 5. Many researchers attempted to modify the classical Runge-Kutta method by using arithmetic mean, harmonic mean or geometric mean either in the main equation or in the stages such as Evans, D.J. & Yaakub, A.R (1993), N. Yaacob & B. Sanugi (1995) and Ahmad, R.R. & Yaacob, N. (2005), N. Razali & R. Ahmad (2008). I. Hashim et al on the other hand applied the Adomian decomposition method (ADM) to the famous Lorenz system and compare it with the fourth-order Runge-Kutta (RK4).

In numerical analysis, the Runge-Kutta methods are an important family of implicit and explicit iterative methods for the approximation of solutions of ordinary differential equations. These techniques were developed around 1900 by the German mathematicians C. Runge and M.W. Kutta.

## The common fourth-order Runge-Kutta method:-

One member of the family of Runge-Kutta methods is so commonly used that it is often referred to as "RK4", "classical Runge-Kutta method" or simply as "the Runge-Kutta method".

Let an initial value problem be specified as follows.

Then, the RK4 method for this problem is given by the following equations:

where yn + 1 is the RK4 approximation of y(tn + 1), and

Thus, the next value (yn + 1) is determined by the present value (yn) plus the product of the size of the interval (h) and an estimated slope. The slope is a weighted average of slopes:

k1 is the slope at the beginning of the interval;

k2 is the slope at the midpoint of the interval, using slope k1 to determine the value of y at the point tn + h / 2 using Euler's method;

k3 is again the slope at the midpoint, but now using the slope k2 to determine the y-value;

k4 is the slope at the end of the interval, with its y-value determined using k3.

In averaging the four slopes, greater weight is given to the slopes at the midpoint:

The RK4 method is a fourth-order method, meaning that the error per step is on the order of h5, while the total accumulated error has order h4.

Note that the above formulae are valid for both scalar- and vector-valued functions (i.e., y can be a vector and f an operator). For example one can integrate Schrödinger's equation using the Hamiltonian operator as function f. Also note that if f is independent of y, so that the differential equation is equivalent to a simple integral, then RK4 is Simpson's rule.

## Examples:-

The RK4 method falls in this framework. Its tableau is:

0

1/2

1/2

1/2

0

1/2

1

0

0

1

1/6

1/3

1/3

1/6

However, the simplest Runge-Kutta method is the (forward) Euler method, given by the formula yn + 1 = yn + hf(tn,yn). This is the only consistent explicit Runge-Kutta method with one stage. The corresponding tableau is:

0

1

An example of a second-order method with two stages is provided by the midpoint method

The corresponding tableau is:

0

1/2

1/2

0

1

Note that this 'midpoint' method is not the optimal RK2 method. An alternative is provided by Heun's method, where the 1/2's in the tableau above are replaced by 1's and the b's row is [1/2, 1/2]. If one wants to minimize the truncation error, the method below should be used (Atkinson p.Â 423). Other important methods are Fehlberg, Cash-Karp and Dormand-Prince. Also, read the article on Adaptive Stepsize.

## Usage:-

The following is an example usage of a two-stage explicit Runge-Kutta method:

0

2/3

2/3

1/4

3/4

to solve the initial-value problem

with step size h=0.025.

The tableau above yields the equivalent corresponding equations below defining the method

k1 = f(tn,yn)

t0 = 1

y0 = 1

t1 = 1.025

y0 = 1

k1 = 2.557407725

k2 = f(t0 + 2 / 3h,y0 + 2 / 3hk1)

y1 = y0 + h(1 / 4 * k1 + 3 / 4 * k2) = 1.066869388

t2 = 1.05

y1 = 1.066869388

k1 = 2.813524695

k2 = f(t1 + 2 / 3h,y1 + 2 / 3hk1)

y2 = y1 + h(1 / 4 * k1 + 3 / 4 * k2) = 1.141332181

t3 = 1.075

y2 = 1.141332181

k1 = 3.183536647

k2 = f(t2 + 2 / 3h,y2 + 2 / 3hk1)

y3 = y2 + h(1 / 4 * k1 + 3 / 4 * k2) = 1.227417567

t4 = 1.1

y3 = 1.227417567

k1 = 3.796866512

k2 = f(t3 + 2 / 3h,y3 + 2 / 3hk1)

y4 = y3 + h(1 / 4 * k1 + 3 / 4 * k2) = 1.335079087

The numerical solutions correspond to the underlined values. Note that f(ti,k1) has been calculated to avoid recalculation in the yis.

## Consider the following differential equation: -

y'=f(x,y) ,

with y(x0) = K (initial or starting value of y)

We wish to approximate the solution to this equation over the interval [a,b]. Let divide this interval into n smaller intervals of size h. A numerical approximation to the above differential equation may be obtained using the 4th order Runge Kutta method as follows.

let y0 = K

yi+1 = yi + (1/6) [k1 + 2k2 + 2k3 + k4]

for i=0,1,...,n-1

where

y0 = K (starting value)

k1 = hf(xi,yi) ,

k2 = hf(xi+h/2,yi+k1/2) ,

k3 = hf(xi+h/2,yi+k2/2) ,

k4 = hf(xi+h,yi+k3)

The local truncation error is of the order O(h5) and in principle decreases as h decreases.

The exploration is carried by changing the step size h.

Your browser is completely ignoring the <APPLET> tag!

## TUTORIAL :-

All the differential equations used in the applet have the same initial value y(0) = 1 and exact solutions for comparison.

1 - click on the button above "click here to start" and MAXIMIZE the window obtained.

2 - Select the first (left panel, top) differential equation y' = x2. At the start h = 1.25 and n = 8. Examine the exact (ex value) solution and the approximate (ap value) one on the left panel. Decrease h by increasing n, read h and n top right. Any differences?

3 - Select the second diffenrial equation y' = x4. Explore by deceasing h and compare the exact and approximate values.

4 - Select the two other differential equations and analyze the results. Compare the exact and approximate values.