Académique Documents
Professionnel Documents
Culture Documents
page 6-1
Objectives:
zar97/09/03
page 6-2
6.0 Introduction
For most practical cases in engineering and sciences, God creates the systems in such a
way that the equations describing the relationships depend on unknown functions and their
derivatives . In general, an ordinary differential equation of nth order has the form
dny
y ( n) f ( x , y , y ', y '', y ( 3) , . . . , y ( n 2 ) , y ( n 1) )
n
dx
(6.0-1)
dy
f (x, y)
dx
(6.0-2)
The numerical solution of the ODE will be in the tabular form of x and y values i.e. (xi , yi ),
i=0,1,2,..., n where yi is an estimate of the exact solution y(x) . In particular we will look at
the numerical solution of the ODE when it satisfies the initial condition y(x0) = y0. We may
write the initial-value ODEs as
dy
f ( x , y ),
dx
y ( x0 ) y0
(6.0-3)
There is no single numerical technique that is best for all first-order initial-value problems.
Therefore, we consider several approaches to obtain the solution of eq.(6.0-3).
zar97/09/03
page 6-3
yi 1 yi h
(6.1-1)
where the estimated slope is used to predict the new value yi+1 using the old value yi
over a distance h. The procedure can be implemented step by step to compute a set of
new values ys and hence, trace out the trajectory of the solution.
Remark: All one-step methods can be expressed in this general form. The only difference
is the way in which the slope is estimated.
f ( xi , yi )
where f(xi , yi ) is the differential equation evaluated at xi and yi which can be substituted
into eq.(6.1-1):
yi 1 yi f ( xi , yi ) h
i = 0,1,2, . . .
(6.1-2)
zar97/09/03
page 6-4
Use Eulers method to numerically integrate the function given below from x
= 0 to x = 2 with h = 0.5.
dy
1 x 1
f ( x, y) (
)
dx
4 y
y(0) = 1
Solution:
y ( 0.5) y1 y ( 0) f ( 0,1)( 0.5)
1 0 1
1.0 ( 0.5) (
)
4 1
1125
.
y (1.0) y2 y ( 0.5) f ( 0.5,1125
. )( 0.5)
1 0.5 1
1125
.
( 0.5) (
)
.
4 1125
129167
.
The remaining computations are shown in table below,
x
0.0
0.5
1.0
1.5
2.0
yEuler
1.00000
1.12500
1.29167
1.48522
1.69563
ytrue
1.00000
1.14564
1.32288
1.52069
1.73205
t %
1.80
2.36
2.33
2.10
zar97/09/03
page 6-5
Worksheet 6.1-1:
dy
xe y x
dx
y(0) = 0
Solution:
0 (0.5) (0) e0 0
0.0
y (10
. ) y2 y(0.5) f (0.5,0.0)(0.5)
yEuler
0.00000
0.00000
0.50000
1.30326
2.25699
3.36165
4.65500
ytrue
0.00000
0.23610
0.83180
1.64102
2.62308
3.79593
5.18758
t %
100
39.89
20.58
13.96
11.44
10.27
zar97/09/03
page 6-6
Error Analysis In Eulers Method. In the single-step methods, the truncation error is
due to two sources: local truncation error and the propagated truncation error that is
carried over from the previous step. The sum of these two sources is called the total or
global truncation error.
We may gain insight of the truncation error associated with the Eulers method by deriving
the formula directly from Taylors series expansion. If the function has continuous
derivatives, TS can be expanded about a starting point (xi , yi ),
yi 1 yi yi ' h
yi '' 2 yi( 3) 3
y (n)
h
h . . . i h n Rn
2
3!
n!
where h xi 1 xi
(6.1-3)
y ( n 1) ( ) n 1
Rn
h
( n 1)!
where xi xi 1
(6.1-4)
yi 1
f ' (xi , yi ) 2
f
yi f ( xi , yi )h
h ...
2
( n 1)
(xi , yi ) n
h ( h n 1 )
n!
(6.1-5)
Comparison of eq.(6.1-2) and eq.(6.1-5), we conclude that the truncation error is due to the
remaining terms in the TSE. Therefore, the true local truncation error is given by
Et
f ' (xi , yi ) 2
f
h ...
2
( n 1)
(xi , yi ) n
h ( h n 1 )
n!
(6.1-6)
For sufficiently small h, higher-order terms would decrease appreciably. The approximate
local truncation error can then be written as
Ea
f ' ( xi , yi ) 2
h
2
or
Ea ( h 2 )
(6.1-7)
zar97/09/03
page 6-7
Estimate the true and the approximate local truncation error associated with
the Eulers method in the first step to solve the following initial-value problem
Example 6.1-2:
y ' 2x 3 x 2 5x 2
y(0) = 0
Et
f ' ( xi , yi ) 2
f
h ...
2
Ea
f ' ( xi , yi ) 2
h
2
( n 1)
( xi , yi ) n
h ( h n 1 )
n!
f ' ( x , y ) 6x 2 2 x 5
f ' ' (x , y ) 12x 2
f ' ' ' ( x , y ) 12
f '( 0,0) 5
Et
5
(2 )
12
( 0.5) 2
( 0.5) 3
(0.5)4 0.61458
2
6
24
Ea
5
( 0.5) 2 0.625
2
zar97/09/03
page 6-8
Remark:
Higher-order term in Taylor series expansion may be included to improve the
accuracy of the Eulers method. However, the inclusion may not be trivial especially when
the ODE is more complicated i.e. ODE that is a function of both the dependent and
independent variables as in the case of example 6.1-1 which require chain-rule
differentiation. An alternative way is developed by modifying the one-step methods.
Two
simple
Heuns Method. The average of the derivatives at the initial and end points of the interval
is used as an improved estimate of the slope. Slope at the initial point,
yi ' f ( xi , yi )
(6.1-8)
yi01 yi f (xi , yi ) h
Predictor equation
(6.1-9)
which may then be used to estimate the slope at the end point,
y 'i 1 f ( xi 1 , y 0i 1 )
(6.1-10)
yi 1
Corrector equation
(6.1-11)
(b)
(a)
x
Figure 6.1-2: Heuns modification-(a) predictor and (b) Corrector.
zar97/09/03
page 6-9
Note that eq.(6.1-11) is in an iterative form. So, we can iteratively obtain the improved
estimate of yi+1 until it converge to prespecified tolerance. Note also, however, that the
convergence is not necessarily to the true solution. The termination criterion of the
corrector equation is given by
old
yinew
1 yi 1
a
100%
yinew
1
(6.1-12)
dy
1 x 1
f ( x, y) (
)
dx
4 y
y(0) = 1
from x = 0 to x = 2 with h = 0.5. Compare the results with the true solutions.
Solution:
Predictor equation,
y11 y0
zar97/09/03
y12
page 6-10
f ( x0 , y0 ) f (x1 , y11 )
y0
h
2
0.25 0.32727
1.0
( 0.5)
2
114432
.
f (x0 , y0 ) f (x1 , y12 )
h
2
0.25 0.32771
1.0
( 0.5)
2
114443
.
y13 y0
Predictor equation,
4 114443
1.30827
Corrector equation,
f (x1 , y1 ) f (x2 , y20 )
h
2
0.32767 0.38218
114443
.
( 0.5)
2
1.32189
The remaining results are shown in table below,
y12 y1
x
0.0
0.5
1.0
1.5
2.0
yHeun
1.00000
1.14443
1.32091
ytrue
1.00000
1.14564
1.32288
t %
0.11
0.15
zar97/09/03
page 6-11
Improved Polygon Method. The slope at the mid-point of the interval is used to
extrapolate the solution at the end of the interval. The value of the unknown function at the
mid-point of the interval is
yi 1/ 2 yi f (xi , yi )
h
2
(6.1-13)
This value is used to estimate the value of the slope over the interval,
f ( xi 1/2 , yi 1/ 2 )
(6.1-14)
yi 1 yi f (xi 1/ 2 , yi 1/2 ) h
(6.1-15)
(b)
(a)
Figure 6.1-3: Improved Polygon Method (a) value at mid-point (b) improved formula.
zar97/09/03
page 6-12
dy
1 x 1
f ( x, y) (
)
dx
4 y
y(0) = 1
from x = 0 to x = 2 with h = 0.5. Compare the results with the true solutions.
Solution:
zar97/09/03
page 6-13
y1 1/ 2 y1 f (x1 , y1 )(0.25)
y1 1/ 2 y (0.75) y (0.5) f (0.5,114706
.
)(0.25)
1 0.5 1
114706
.
(0.25) (
)
.
4 114706
1.22879
y2 y1 f ( x11/2 , y11/2 )(0.5)
y2 y (10
. ) y (0.5) f (0.75,1.22879 )(0.5)
1 0.75 1
114706
.
(0.5) (
)
4 1.22879
1.32508
yHeun
1.00000
1.14706
1.32508
ytrue
1.00000
1.14564
1.32288
t %
0.12
0.17
zar97/09/03
page 6-14
yi 1 yi ( xi , yi , h)h
(6.1-16)
where = (xi , yi , h) is called the increment or slope function or the Runge-Kutta slope
and is defined as
n
( xi , yi , h) a1k1 a2 k2 . . . an k n ai ki
(6.1-17)
i 1
where
ai constants
i 1,2,..., n.
k1 f ( xi , yi )
k2 f ( xi p1h, yi q11k1h)
k3 f ( xi p2h, yi [q21k1 q22 k 2 ]h)
(6.1-18)
n 1
kn f ( xi pn 1h, yi [ qn 1, j k j ]h)
j 1
The parameters as , ps , and qs are evaluated by setting the terms in eq.(6.1-16) equal to
the terms in the Taylor series expansion.
Remark:
zar97/09/03
page 6-15
yi 1 yi [ a1k1 a2 k2 ]h
(6.1-19)
k1 f ( xi , yi )
k2 f ( xi p1h, yi q11k1h)
(6.1-20)
where
By equating eq.(6.1-19) and the TSE, the following relationships among parameters are
obtained
a1 a2 1
1
a2 p1
2
1
a2q11
2
(6.1-21)
Since we have four unknowns and only three equations, we may assume the value for one
of the parameters, for example, we may assume the value for a2, then solve for the other
three unknowns. An infinite number of 2nd-order versions are obtained as a result of this.
Remark:
Eventhough there are infinitely many versions exists, they yield exactly the
same results if the solution of the ODEs is a constant, a linear, or a
quadratic.
a1 = 1/2,
p1 = 1, and
q11 = 1
k k2
yi 1 yi 1
h
2
(6.1-22)
where
k1 f ( xi , yi )
k 2 f ( xi h, yi k1h)
(6.1-23)
zar97/09/03
page 6-16
a1 = 0,
p1 = 1/2,
and
q11 = 1/2
yi 1 yi k2h
(6.1-24)
where
k1 f ( xi , yi )
(6.1-25)
k 2 f ( xi 21 h, yi 21 k1h)
. Ralstons method (a2 = 2/3). ). Eq.(6.1-21) gives
a1 = 1/3,
p1 = 3/4,
and
q11 = 3/4
k 2k2
yi 1 yi 1
h
3
(6.1-22)
where
k1 f ( xi , yi )
k 2 f ( xi 34 h, yi 43 k1h)
Remark:
(6.1-23)
This last method provides a minimum bound on the local truncation errors
for the 2nd-order RK methods.
problem
dy
1 x 1
f ( x, y) (
)
y(0) = 1
dx
4 y
from x = 0 to x = 2 with h = 0.5. Compare the results with the true solutions.
Solution:
zar97/09/03
For i = 0,
page 6-17
step1:
k1 f ( x0 , y0 )
1 0 1
0.25
4 1
k 2 f ( x0 0.375, y0 0.09375)
1 0.375 1
0.31429
4 1.09375
step2:
k1 2 k2
(0.5)
3
0.25 2 ( 0.31429 )
y1 1.0 (0.5)
y1 y0
114643
.
For i = 1,
step1:
k1 f ( x1 , y1 )
1 0.5 1
0.32710
4 114643
.
k 2 f ( x1 0.375, y1 012266
.
)
1 0.875 1
0.36936
4 1.26909
step2:
k1 2 k2
( 0.5)
3
0.32710 2 ( 0.36936)
y2 114643
.
(0.5)
y2 y1
1.32407
yRalston
1.00000
1.14643
1.32407
ytrue
1.00000
1.14564
1.32288
1.52069
1.73205
t %
0.07
0.09
zar97/09/03
page 6-18
Worksheet 6.1-2:
dy
xe y x
dx
y(0) = 0
Solution:
i = 0, step1:
k1 f ( xi , yi ):
k1 f ( x0 , y0 ) 0
k 2 f ( xi 43 h, yi 34 k1h):
k2 f (0 0.375,0 0)
0.375(e 0 1)
0.75
step2:
k 2k2
y1 y (0.5) y0 1
h
3
0 0.75
0.0 (0.5)
3
0.25
yRalston
0.00000
0.25000
0.85263
1.95365
ytrue
0.00000
0.23610
0.83180
1.64102
2.62308
t %
5.89
2.50
19.05
zar97/09/03
page 6-19
yi 1 yi [a1k1 a2 k2 a3k 3 ]h
(6.1-24)
k1 f ( xi , yi )
k2 f ( xi p1h, yi q11k1h)
k 3 f ( xi p2h, yi [q21k1 q22 k 2 ]h)
(6.1-25)
where
which have eight unknowns. By equating eq.(6.1-19) and the TSE, we obtain six equations.
Thus, we must specify two of them in order to determine the remaining six parameters.
Remark:
1. Eventhough there are infinitely many versions exists, they yield exactly
the same results if the solution of the ODEs is a cubic.
4
3
2. The local and global truncation errors are (h ) and (h ), respectively.
k 4k 2 k 3
yi 1 yi 1
h
6
(6.1-26)
where
k1 f ( xi , yi )
k 2 f ( xi 21 h, yi 21 k1h)
(6.1-27)
k 3 f ( xi h, yi [ k1 2 k2 ]h)
Remark:
zar97/09/03
page 6-20
Example 6.1-7:
Solution:
For i = 0,
step1:
k1 f ( x0 , y0 )
1 0 1
0.25
4 1
k 2 f ( x0 0.25, y0 0.0625)
1 0.25 1
0.29412
4 1.0625
k 3 f ( x0 0.5, y0 0.16912)
1 0.5 1
0.32075
4 116912
.
step2:
k 4 k2 k 3
y1 y0 1
(0.5)
6
For i = 1,
step1:
k1 f ( x1 , y1 )
1 0.5 1
0.32734
4 114560
.
k 2 f ( x1 0.25, y1 0.08184)
k 3 f ( x1 0.5, y1 019276
.
)
1 0.75 1
0.35643
4 1.22744
1 10
. 1
0.37359
4 1.33836
zar97/09/03
page 6-21
step2:
k 4 k2 k 3
y2 y1 1
(0.5)
6
For i = 2,
step1:
k1 f ( x2 , y2 )
1 1.0 1
0.37798
4 1.32282
k 2 f ( x2 0.25, y2 0.09450)
k 3 f ( x2 0.5, y2 0.41577)
1 1.25 1
0.39688
4 1.41732
1 15
. 1
0.35949
4 1.73859
step2:
k 4 k 2 k3
y3 y2 1
(0.5)
6
y3rd-order
1.00000
1.14560
1.32282
1.51657
1.72843
ytrue
1.00000
1.14564
1.32288
1.52069
1.73205
t %
0.003
0.005
0.271
0.209
zar97/09/03
page 6-22
Fourth-order Runge-Kutta Methods. This is the most widely used RK method. Similar
to the previous order, there are an infinite number of versions.
The most common one is called the classical fourth-order RK method and is given by
k 2 k2 2 k 3 k 4
yi 1 yi 1
h
6
(6.1-28)
where
k1 f ( xi , yi )
k 2 f ( xi 12 h, yi 12 hk1 )
(6.1-29)
k 3 f ( xi 21 h, yi 12 hk 2 )
k 4 f ( xi h, yi hk 3 )
Remark:
Example 6.1-8:
Solution:
For i = 0,
step1:
k1 f ( x0 , y0 )
1 0 1
0.25
4 1
k 2 f ( x0 0.25, y0 0.0625)
1 0.25 1
0.29412
4 1.0625
k 3 f ( x0 0.25, y0 0.0.07353)
k 4 f ( x0 0.5, y0 0.14555)
1 0.25 1
0.29110
4 1.07353
1 0.5 1
0.32735
4 114555
.
zar97/09/03
page 6-23
step2:
k 2 k2 2 k 3 k 4
y1 y0 1
(0.5)
6
For i = 1, step1:
k1 f ( x1 , y1 )
1 0.5 1
0.32733
4 114565
.
k 2 f ( x1 0.25, y1 0.08183)
1 0.75 1
0.35642
4 1.22748
k 3 f ( x1 0.25, y1 0.08911)
1 0.75 1
0.35432
4 1.23476
k 4 f ( x1 0.5, y1 0.17716)
1 1.0 1
0.37798
4 1.32281
step2:
k 2 k2 2 k 3 k 4
y1 y0 1
(0.5)
6
y4th-order
1.00000
1.14565
1.32288
ytrue
1.00000
1.14564
1.32288
1.52069
1.73205
t %
0.0009
0.0002
zar97/09/03
page 6-24
Worksheet 6.1-3:
dy
xe y x
dx
Solution:
For i = 0,
y(0) = 0
step1:
k1 f ( x0 , y0 ) (0)( e0 1) 0
k 2 f ( x0 0.25, y0 0) (0.25)( e0 1) 0.5
k 3 f ( x0 0.25, y0 0125
. ) (0.25)( e0.125 1) 0.47062
k 4 f ( x0 0.5, y0 0.23531) (0.5)( e0.23531 1) 0.89516
step2:
k 2 k2 2 k 3 k 4
y1 y0 1
(0.5)
6
yRalston
0.00000
0.23637
ytrue
0.00000
0.23610
0.83180
1.64102
2.62308
t %
0.11
zar97/09/03
page 6-25
Higher-order Runge-Kutta Methods. The fifth- or higher-order versions are used when
more accurate results are needed. However, the gain in accuracy is usually offset by the
added computational effort and complexity. Reader may refer textbook page 604.
y '1 f1 ( x , y1 , y2 , . . ., yn )
y '2 f 2 ( x , y1 , y2 , . . ., yn )
y ' n f n ( x , y1 , y2 , . . ., yn )
(6.1-30a)
y1 ( x0 ) y1,0
y1 ( x0 ) y2,0
(6.1-31a)
yn ( x0 ) yn,0
where x0 is a starting value of x.
Eq.(6.1-30) and eq.(6.1-31) can be represented in a vector form as
y f ( x , y)
or
y ' f ( x, y )
(6.1-30b)
y( x0 ) y0
or
y ( x0 ) y0
(6.1-31b)
and
All the methods discussed early for a single differential equation can be used to solve the
system of differential equations. This is achieved by applying the one-step method for
every equation at each step before proceeding to the next step.
Note: There may be cases when several hundred simultaneous differential equations
occurred in engineering and scientific applications.
zar97/09/03
page 6-26
y '1 0.4 y1 0
y '2 0.2 y1 0.3y2 5 0
y1 (0) 6
y2 ( 0) 4
y '1 0.4 y1
y ' 2 5 0.2 y1 0.3y2
Then applying Eulers method at each step,
y1
6
4.8
3.84
3.072
2.4576
y2
4
5.7
6.64
7.76
8.7888
zar97/09/03
page 6-27
Solution:
y '1 f 1 ( x , y1 , y2 ) 0.4 y1
y ' 2 f 2 ( x , y1 , y2 ) 5 0.2 y1 0.3y2
Step1: calculate all the k1 s,
y1 12 hk 2 ,1 6 12 (0.5)(2.16) 5.46
y2 12 hk 2 ,2 4 12 (0.5)( 2.525) 4.63125
Step5: calculate all the k3 s,
zar97/09/03
page 6-28
step6: calculate the values of y1 and y2 needed for the calculation of the k4 s,
k 2k 2 2 k 3 k 4
yk ,1 yk ,0 1
( 0.5)
6
(0.5)
y1,1 6.0
2.4 2(2.16) 2(2.184 ) 1.9632 4.9124
6
( 0.5)
y2 ,1 4.0
2.6 2(2.525) 2( 2.51863) 2.44061 5.26066
6
and the remaining solutions are
x
0.0
0.5
1.0
1.5
2.0
y1
6
4.9124
y2
4
5.26066
zar97/09/03
page 6-29
dny
y (n ) ( x ) f (x , y , y ', y '' , y ( 3) , . . . , y ( n 2 ) , y (n 1) )
n
dx
(6.1-32)
y ( k ) (x0 ) y0( k )
for
k 0,1,2, . . ., n 1
(6.1-33)
where k represents the kth derivative of the function and both y and f are real-valued
functions.
Eq.(6.1-32) may be reduced to a system of 1st-order simultaneous equations by
introducing the new variables in the following manner
y1 (x ) y (x )
y2 ( x ) y ' ( x ) y '1
y3 ( x ) y ' ' ( x ) y ' 2
(6.1-34)
yn ( x ) y (n 1) (x ) y 'n 1 (x )
and
f ( x , y1 , y2 , . . ., yn 1 ) y 'n ( x )
y '1 y2 ( x )
y '2 y3 (x )
y 'n 1 ( x ) yn ( x )
y 'n ( x ) f (x , y1 , y2 , . . ., yn 1 )
(6.1-34)
zar97/09/03
page 6-30
y1 ( x ) y (x )
and
y2 ( x ) y ' (x )
y '1 (x ) y2 (x )
y1 (0) 5
y ' 2 ( x ) y1 (x ) y2 (x ) x 2 1
y2 ( 0) 2
x
0.0
0.5
2.0
y1
5.0
7.0
20.0
y2
2.0
13.0
106.0
zar97/09/03
page 6-31
expressed as
3
d 2y
dy
dy
0.3 0.3 3y 0 with i.cs: y ( 0) y '( 0) 1
2
dx
dx
dx
Convert the problem into simultaneous first-order equations and solve by Eulers method from
x = 0 to x = 2 with h = 1.
3
Solution:
y1 ( x ) y (x )
and
y2 ( x ) y ' (x )
y '1 (x ) y2 (x )
y1 ( 0) 1
y ' 2 ( x ) 01
. y2 01
. ( y2 ) 3 y1
y2 (0) 1
x
0.0
0.5
2.0
y1
1.0
2.0
2.0
y2
1.0
0.0
-2.0