Chapter 12
Chapter 12
Chapter 12
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)
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.
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.
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).
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
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
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]
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
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.
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
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
y( x ) 2 y (n ) ( x ) n
y( x h) y( x ) y( x ) h h ... h ...
2! n!
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 .
Estimate
True
h
x
xi xi+1
Figure 12.1
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.
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
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
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
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
h2 h3 (3) h4 (4)
y(x h) y(x) hy(x) y(x) y (x) y (x) ........
2! 3! 4!
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!
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
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
Solution
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
f ( x, y ) y 2x
f ( x, y ) 2x
Identify x i , y i and h
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
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
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
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
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
(0.1)2
y(0.1) y(0) (0.1)(-1) (6)
2!
1 - 0.1 0.03
0.93
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
215
Part 7 NUMERICAL SOLUTION OF ODE MAT 575
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 )
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.
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