Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Chapter 12
Euler’s & Taylor’s
Methods
At the end of this chapter, students should be able to:
Recall ordinary differential equation and Taylor’s series
Apply Euler’s and Taylor’s series methods in solving initial value problems
12.1 Introduction
Differential equations serve as mathematical descriptions for many physical
phenomena. A few examples of commonly occurring differential equations are:
1. ay(x) + by(x) + cy(x) = F(x)
2. E l y (4) (x) w (x)
w
3. y(x) 1 (y(x))
y
Equation (1) occurs in the study of vibrating or oscillating mechanical
systems or in electrical circuits.
Equation (2) arises in the study of beam deflections.
Equation (3) deals with problems in cable suspension.
In many scientific and engineering applications, the independent variable x (or
sometimes t) normally represents time.
199
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
The numerical methods of solving initial value problems that we are going to
discuss are
Euler’s method
Taylor’s Series Method
Fourth-Order Runge-Kutta Method
For all these methods, the discussion shall focus on first order initial value
problems. However, contents of Fourth-Order Runge-Kutta Method shall also
include second order initial value problems.
12.2 Ordinary Differential Equation
For a start it will be useful to review some elementary definitions and concepts
from the theory of differential equations.
Definition
A differential equation (DE) is an equation containing one or more derivatives of
an unknown function.
dn y dn1y d2 y dy
an n
a n1 n1
a 2 2
a1 a0 y f ( x )
dx dx dx dx
Order Notation
dy
First order D y y
dx
d2 y
Second order 2
D 2 y y
dx
The order of DE is the order of the highest derivative that it contains (usually x
is used as the independent variable, and y for the dependent variable).
An ordinary differential equation of order n has the form:
y(n) f(x,y(x),y(x), y(x), y(3) (x),......, y(n-1) (x)) nth order
y f(x,y(x)) 1st order
y f(x,y(x),y(x)) 2nd order
In a first course of differential equations, students learn various techniques for
solving some selected classes of differential equations, i.e. methods of solving
200
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
separable equations, exact equations and first order linear equations. The vast
majority of equations encountered in practice however, cannot be solved
analytically or exactly. Thus, an alternative method is needed in order to solve
the equations by numerical methods (or approximations).
Let’s review an example of solving a first order differential equation the
analytical way (i.e. seeking the exact solution).
Example 1
dy
Consider a differential equation - y 0 . Find the function y that will satisfy
dx
the equation.
Solution
Applying method of variable separable in ordinary differential equation yields
1
dy dx
y
1
dy dx
y
ln y = x + c
e x c e x ec y
Hence,
y ke x (k = e c a constant)
What we can say about the above equation is that it has many solutions
depending on the value k. The function y ke x is called the general solution.
Pictorially the solutions for the differential equation will be as below:
Conditions: Particular Solution:
If y(0) = 1 : y0 1, x0 0 y ex
If y(0) = 3 : y0 3 , x0 0 y 3e x
201
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
y 3e x
y 2e x
y ex
Figure 12.1
The conditions above (i.e. x0 , y 0 ) are called initial values. Solving differential
equations with initial conditions are sometimes called initial value problems.
Thus, an initial value problem always consists of two parts:
(i) the differential equation y(x) f(x,y(x)), x defined on [a, b]
(ii) the initial condition y(a) y0 , where a is actually x 0 i.e. y(x0 ) y0
The solution obtained from initial value problem is known as particular solution.
Example 2
Solve the initial value problem.
dy
x2 6x2 y , y(0) 2
dx
Solution
dy
x2 6x2 y
dx
dy
6x2 y x2
dx
Identify p(x) 6x2
Determine Integrating Factor, I x e
6x2dx
3
e2x
Rewrite the standard form
3 3
ye2x e2x x2 dx
Let u 2x3
du 6x2 dx
1 u
6
e du
1
eu C
6
202
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
1 2x3
e C
6
Hence, the general solution is given by
1 3
y Ce2x
6
To determine the particular solution used the initial value given.
x0 ; y 2
1
2 C 1
6
11
C
6
Therefore, the particular solution is
1 11 2x3
y e
6 6
Warm up exercise
dy
(i) Given the differential equation, ( 4 x ) x 1 y .
dx
a. Separate the common terms.
b. Integrate both sides.
c. Write the equation in a general form.
dy
(ii) Given the initial value problem, x y x2 x 1 , y(1) 2 .
dx
a. Write the differential equation in a standard form of linear equation.
b. Find the Integrating Factor.
c. Find the particular solution for the differential equation.
12.3 Review of Taylor Series
The Taylor series is a representation of a function as an infinite sum of terms
calculated from the values of its derivatives at a single point. The Taylor series
are named in honour of an English mathematician, Brook Taylor.
203
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Definition
Let y(x) be a function with derivatives of all orders throughout some interval
containing c as an interior point. Then the Taylor series generated by y(x) at
x c is
y(c ) (n)
y( x ) y(c ) y(c )(x c ) x c 2 ... y (c ) x c n ...
2! n!
y n c
x c n
n0
n!
Corollary
A function y(x + c) can be expanded in a series of positive integral powers of x:
y(c ) 2 y ( n ) (c ) n
y( x c ) y(c ) y(c )x x ... x ...
2! n!
Steps
Identify the function
Identify the center
Identify the form
Differentiate f(x) and evaluate at the center
Example 3
1
Represent as a power series in
x 1
(a) x 1 (b) x
Solution
1
(a) Identify function: f (x)
x 1
Identify center: c=1
Identify form:
f (c ) (n )
f ( x ) f (c ) f (c )(x c ) x c 2 ... f (c ) x c n ...
2! n!
Differentiate f(x) and evaluate at center c = 1.
204
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Differentiate Evaluate
x 11
1 1
f ( x) f (1)
x 1 2
1 1
f ( x ) x 1 2 f (1)
x 1 2
22
f ( x ) 2x 1
3 2 2
f (1)
x 1 3
23
6 6
f ( x ) 6x 1
4
f (1)
x 1 4
24
f (iv ) ( x ) 24x 1
5 24 24
f (iv ) (1)
x 1 5
25
Plug into the identified form,
f (1) iv
f ( x ) f (1) f (1)(x 1) x 12 f (1) x 13 f (1) x 14 ...
2! 3! 4!
1 1 1
( x 1)
2
x 12 6 4 x 13 245 x 14 ...
x 1 2 2 2
2!2 3
3!2 4!2
1 x 1 x 12 x 13 x 14
1 ...
2 2 22 23 24
When determining the Taylor series in term of (x – c), do not do any
simplification. Just leave it as it is.
1
(b) Identify function: f ( x 1)
x 1
Identify center: c=1
f (c ) 2 f (n ) ( c ) n
Identify form: f ( x c ) f (c ) f (c )x x ... x ...
2! n!
Differentiate f(x) and evaluate at center c = 1
Differentiate Evaluate
1
f ( x) x 1 f (1) 1
x
1
f ( x ) x 2 f (1) 1
x2
2
f ( x ) 2x 3 f (1) 2
x3
205
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
6
f ( x ) 6x 4 f (1) 6
x4
24
f (iv ) ( x ) 24 x 5 f (iv ) (1) 24
x5
Plug into the identified form,
f (1) 2 f (1) 3 f (iv ) (1) 4
f ( x 1) f (1) f (1)x x x x ...
2! 3! 4!
1
1 x x 2 x 3 x 4 ...
x 1
Warm up exercise
Consider the following function and represent f(x) as a power series
in (x – c) and x.
(a) f ( x) x 1 ; c=1
(b) f ( x) ln( x 1) ; c = -1
12.4 Euler’s Method
Euler’s method is perhaps the simplest numerical method of solving initial value
problems. Essentially Euler’s method is derived using the first two terms of the
Taylor series (it is actually Taylor series of order 1). Due to its large truncation
error, Euler’s method is rarely used in practice.
y( x ) 2 y (n ) ( x ) n
y( x h) y( x ) y( x ) h h ... h ...
2! n!
In the first step we compute
y( x0 h) y( x0 ) y( x0 ) h
y( x1) y( x0 ) y( x0 ) h
y1 y 0 hy0
206
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
dy
Let y( x ) f ( x, y ) , then Euler’s method can be written as:
dx
y( x0 h) y( x0 ) hf ( x0, y0 )
y( x1) y( x0 ) hf ( x0, y0 )
For i = 0, 1, 2, 3, …
y( xi1) y( xi ) hf ( xi, y( xi ))
or
yi 1 y i hf(xi , y(xi ))
or, yi 1 yi hf ( xi , yi )
dy
Note that y( x ) is the first order derivatives and rewritten as function of two
dx
variables f(x, y). Hence, f(xi, yi) implies that the function is evaluated at xi and
yi. Geometrically it is an approximation of the curve y(x) by a polygon whose
side is tangent to the curve at x 0 .
y The value of y is estimated
using the slope at xi ,
extrapolated linearly over the
step size h0
Estimate
True
h
x
xi xi+1
Figure 12.1
Steps – Euler’s method
dy
Identify y( x )
dx
Rewrite y( x) f ( x, y)
Identify x 0 , y0 y( x0 ) and h
Compute f ( x0, y0 )
Apply Euler’s method
o yi1 yi hf ( xi, yi )
207
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Example 4
Given
dy
y, y(0) 1.
dx
Using h 0.01 , estimate y(0.01), y(0.02), y(0.03), y(0.04) using Euler’s
method.
Solution
dy
Identify y' ( x )
dx
dy
y
dx
Rewrite y' ( x) f ( x, y)
f ( x, y) y
Identify x 0 , y0 y( x0 ) and h
x0 0 y0 1 h 0.01
Compute f ( x0, y0 )
f ( x0, y0 ) y0
f (0,1) 1
Apply Euler’s method
yi1 yi hf ( xi, yi )
y1 y 0 hf ( x 0 , y 0 )
1 (0.01)f (0,1)
1 (0.01)(1) 1.01
Repeat for i = 1, 2, 3 :
y2 = y1 + h f(x1 , y1)
=1.01 + (0.01) (1.01)
=1.0201
y3 = y2 + h. f(x2 , y2)
=1.0201 + (0.01) (1.0201)
=1.0303
208
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
y4 = y3 + h f(x3 , y3)
=1.0303 + (0.01) (1.0303)
=1.0406
Example 5
Given y t y where y(0) = 2. Apply Euler’s method to the given initial
value problem to approximate y(1.0) using:
(a) h = 0.5.
(b) h = 0.2.
Compare with the analytical solution y(t) 3e t - t - 1. What is your
observation?
Solution
Given
y ' t y and y(0) = 2
rewrite
y ' f (t, y) t y
where
t0 0 y0 2
a) h 0.5 (2 steps)
y(0.5) = y1 = y0 + h(t0 , y0)
= 2 + (0.5) (2)
= 3
y(1.0) = y2 = y1 + h f(t1 , y1)
= 3 + (0.5) (3.5)
= 4.75
i t f(t,y) Euler Exact Error
0 0 2 3 2 1.0000
1 0.5 3.5 4.75 3.446164 1.3038
2 1 5.75 7.625 6.154845 1.4702
209
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
b) h = 0.2 (5 steps)
y(0.2) = y1 = 2.4
y(0.4) = y2 = 2.92
y(0.6) = y3 = 3.584
y(0.8) = y4 = 4.4208
y(1.0) = y5 = 5.4650
h = 0.2
i t f(t, y) Euler Exact Error
0 0 2 2.4 2 0.4000
1 0.2 2.6 2.92 2.464208 0.4558
2 0.4 3.32 3.584 3.075457 0.5085
3 0.6 4.184 4.4208 3.866456 0.5544
4 0.8 5.2208 5.46496 4.876623 0.5883
5 1.0 6.46496 6.757952 6.154845 0.6031
To increase accuracy use a smaller step size h or use more steps.
Example 6
Consider the initial value problem y 1 t sin( ty) , 0 ≤ t ≤ 2 , y(0) = 0. Use
Euler’s method to approximate y(0.2).
Solution
h = 0.1
i t f(t,y) 1 t sin( ty) Euler
0 0 1 0.1
1 0.1 1.001 0.2001
2 0.2 1.008002 0.3009
210
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Warm up exercise
dy
Consider x2 6x2 y with y(0) = -2.
dx
(i) Identify x 0 and y 0
(ii) Identify and compute f ( x0, y0 )
(iii) Approximate y(1) using h = 0.5.
12.5 Taylor’s Series Method
As stated earlier Taylor’s Series is given by:
h2 h3 (3) h4 (4)
y(x h) y(x) hy(x) y(x) y (x) y (x) ........
2! 3! 4!
Taylor’s series order
h2
y(x h) y(x) hy ' (x) y ' ' (x) 2
2!
h2 h3 (3)
y(x h) y(x) hy(x) y(x) y (x) 3
2! 3!
h2 h3 (3) h4 (4)
y(x h) y(x) hy(x) y(x) y (x) y (x)
2! 3! 4!
4
.
.
h2 hn (n)
y(x h) y(x) hy(x) y(x) .......... .. y (x) n
2! n!
Note that y(x) f(x,y(x)). By differentiation,
y(x) f (x, y(x))
and the Taylor’s series becomes
h2 h3 h4
y(x h) y(x) hf(x,y(x)) f (x,y(x)) f (x,y(x)) f (x,y(x)) ...
2! 3! 4!
where f, f , f , f are evaluated at (x, y(x)).
211
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Steps – Taylor’s method
Identify the required order of Taylor series
Identify f ( x, y )
Determine f ( x, y ) , f ( x, y) ; etc
Identify x i , y i and h
Compute f ( xi, yi ) , f ( xi , yi ) , f ( xi , yi ) ; etc
Apply relevant Taylor’s method
h2 h3
y i 1 y i hf(xi , y i ) f (xi , y i ) f (xi , y i )
2! 3!
h4
f' ' ' (xi , y i ) ........
4!
For a small value of h, the higher powers h2 , h3 , h4 , ..... will be very small and
the corresponding terms can be ignored. The omission of further terms causes
an error, which is called the truncation error. In calculating the approximation,
the more number of terms used means the more accurate is our answer.
Example 7
Use Taylor series of order 2 to estimate y(0.2) if
y' ( x) y x 2 1 and y(0) = 0.5
Solution
Identify the required order of Taylor series
h2
y i 1 y i hf(xi , y i ) f (xi , y i )
2!
Identify f ( x, y )
f ( x, y) y x2 1
Determine f ( x, y ) , f ( x, y) ; etc
f ( x, y ) y 2x
f ( x, y ) 2x
Identify x i , y i and h
x0 0 , y0 0.5 and h = 0.2
Compute f ( xi, yi ) and f ( xi , yi )
212
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
f ( x 0 , y 0 ) y 0 x 02 1
f (0, 0.5) 0.5 0 1
1.5
f ( x 0 , y 0 ) f ( x 0 , y 0 ) 2x 0
1.5
Apply relevant Taylor’s method
h2
y(0.2) y(0) hy(0) y(0)
2!
h2
y1 y 0 (0.2)f(x0 , y 0 ) f (x0 , y 0 )
2!
(0.2)2
y1 0.5 (0.2)(1.5) (1.5)
2
0.83
Hence, y(0.2) 0.83 .
Example 8
Derive the Taylor’s series method of order 4 for the ODE
dy
y et
dt
y(0) 1
and estimate y(0.1) and y(0.2).
Solution
Taylor’s series of order 4 is given by:
h2 h3 h4
y i 1 y i hf(ti , y i ) f (ti , y i ) f (ti , yi ) f (ti , y i )
2! 3! 4!
f ( t, y) y e t
f ( t, y ) y e t
f ( t, y ) e t
f ( t, y ) y e t
f ( t, y ) e t e t
f ( t, y ) 2e t
213
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
f ( t, y ) f ( t, y ) 2e t
f ( t, y ) e t 2e t
f ( t, y ) 3e t
h2 h3 h4
y i 1 y i hf(ti , y i ) f (ti , y i ) f (ti , y i ) f (ti , y i )
2! 3! 4!
h2
y i hf(ti , y i )
2!
f (ti, yi ) et i
h3
3!
f ( t i , y i ) 2e t i h4
4!
f ( t i , y i ) 3e t i
2 3
h
4 h 2 3
h ti
4
f(ti , y i )
h h h
y i h e
2! 3! 4! 2 3 8
Given
t0 0 y0 1 and h = 0.1
h 2 h3 h 4 h 2 h3 h 4 t
y i 1 y i h f(ti , y i ) e
2! 3! 4! 2 3 8
y(0.1) y 0 0.1
0.12 0.13 0.14
2!
3!
4!
t
y0 e 0
2
3
0.12 0.13 0.14 t
e 0
8
1 0.1052 1 e0 0.0053 e0
1 0.1052 2 0.0053
1.2157
y(0.2) y(0.1 0.1)
y( t1 h)
y2
y1 0.1
0.12 0.13 0.14
2!
3!
4!
t
y1 e 1 )
2
0.12 0.13 0.14 t
3
8
e 1
1.2157 0.1052 1.2157 e0.1 0.0053 e0.1
1.4657
Example 9
For the IVP
y0 1 ;
dy
2y 2 - e- 4t
dt
estimate y(0.1) using:
(i) Euler’s method.
(ii) Taylor’s method of order 2.
(iii) Taylor’s method of order 4.
214
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
e4t e2t
Compare them to the exact solution y( t ) 1 .
2 2
Solution
f (t, y) 2 - e-4t 2y y0 1
(i) Euler’s method
y( x h) y( x ) hf ( x, y )
y(0.1) y(0) (0.1)f (0,1)
1 (0.1)2 1 2(1)
1 (0.1)(1) 0.9
(ii) Taylor’s method of order two
h2
y(x h) y(x) hy(x) y(x)
2!
y( t ) f ( t, y ) 2 - e -4t 2y
f (0,1) 2 1 2 1
y( t ) f ( t, y ) 4e -4t 2y
f ' (0,1) 4 2( 1) 6
(0.1)2
y(0.1) y(0) (0.1)(-1) (6)
2!
1 - 0.1 0.03
0.93
(iii) Taylor’s method of order 4
h2 h3 h4 (4)
y(x h) y(x) hy(x) y(x) y(x) y (x)
2! 3! 4!
y( t ) f ( t, y ) 2 - e -4t 2y
f (0,1) 2 1 2 1
y( t ) f ( t, y ) 4e -4t 2y
f (0,1) 4 2( 1) 6
y( t ) f ( t, y ) 16e-4t 2y
f (0,1) 16 2(6) 28
y (iv ) ( t ) f ( t, y ) 64e-4t 2y
f (0,1) 64 2( 28) 120
215
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
(0.1)2 (0.1)3 (0.1) 4
y(0.1) y(0) (0.1)f(0,1) f (0,1) f (0,1) f (0,1)
2! 3! 4!
(0.1)2 (0.1)3 (0.1) 4
1 0.1(-1) (6) (-28) (120)
2! 3! 4!
0.9258
Exact value is
e 4(0.1) e 2(0.1)
y(0.1) 1
2 2
0.9258
Taylor's Taylor's
Exact Euler's nd th
2 4
Computation 0.9258 0.9 0.93 0.9258
Absolute
0 0.0258 0.0042 0
Error
It can be concluded that Taylor’s series method of order 4 gives the best
approximation compared to Euler’s and Taylor series method of order 2.
Warm up exercise
dy
Consider x2 6x2 y with y(0) = -2.
dx
(i) Identify f ( x, y )
(ii) Determine f ( x, y ) , f ( x, y ) , and f ( x, y)
(iii) Identify x 0 , and y 0
(iv) Compute f ( x0, y0 ) , f ( x 0 , y 0 ) , f ( x 0 , y 0 ) and f ( x 0 , y 0 ) .
(v) Approximate y(0.5).
216
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
Exercise 12
dy
1. Let 2xy with initial condition y0 2 and x0 2 . Approximate the
dx
solution at x1 2.1 by performing one iteration of Euler’s method with h = 0.1.
2. Consider the differential equation y x y with initial condition y = 1 when
x = 0, do three iterations of Euler’s method with h = 0.1.
dy
3. Use Euler’s method to determine the solution to y 2 t 2 with y(1) = 0,
dt
(i) when t =2 for h = 0.2
(ii) when t = 5 for h = 0.5
dy y
4. Let with initial condition y0 4 and t 0 0 . Approximate the solution
dt 2
at t 0.4 by performing
(i) two iterations of Taylor’s method of order two.
(ii) one iteration of Taylor’s method of order four.
5. Construct a table of x and y values for x [0, 1] with h = 0.1 for the initial value
1
problem y , y(0) = 2 using:
xy
(i) Euler’s method
(ii) Taylor’s method of order 2
dy
6. Solve the differential equation x y xy with initial condition y(0) = 0
dx
to approximate y(0. 1), y(0.2), y(0.3) and y(0.5) by
(i) Euler’s method.
(ii) Taylor’s method of order 2.
(iii) Taylor’s method of order 3.
(iv) Taylor’s method of order 4.
217