Академический Документы
Профессиональный Документы
Культура Документы
“The best among you is the one who has highest piety.”- Meaning of Al-Ayat.
Scope and Preview: In this part, we will study numerical solutions of ordinary
differential equations (ODEs). Three main sections will be covered: the one-step methods,
the adaptive step size control, and the boundary and eigenvalue problems.
5.1 One-step methods. The one-step methods, namely Runge-Kutta techniques which
has a constant step size, will be employed for solving a single ODE. We will also solve
systems of ODEs using the same methods.
5.2 Adaptive step size control. The section is devoted to an adaptive step size method
as opposed to the constant step size methods. The techniques automatically adjust the
step size in order to minimize the truncation error. This is done in two ways: to include an
adaptive step size in the one-step methods and to introduce multistep methods. The
algorithms retain information of the previous steps in order to apply correction in
subsequent steps
5.3 Boundary value and Eigenvalue problems. Two fundamental approaches will be
used: shooting and finite-difference. For the latter problems, the polynomial and the power
methods will be covered.
zar97/09/03 Numerical Methods For Engineers 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
n
y ( n) f ( x , y , y ', y '', y ( 3) , . . . , y ( n 2 ) , y ( n 1) ) (6.0-1)
dx
dy
f (x, y) (6.0-2)
dx
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 ), y ( x0 ) y0 (6.0-3)
dx
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 Numerical Methods For Engineers page 6-3
or, mathematically
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 y’s 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.
I). Euler’s Method. In Euler’s method, the slope in eq.(6.1-1) is estimated directly
using the first derivative at xi :
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)
Example 6.1-1:
Use Euler’s 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) ( ) y(0) = 1
dx 4 y
Solution:
y ( 0.5) y1 y ( 0) f ( 0,1)( 0.5)
1 0 1
1.0 ( 0.5) ( )
4 1
1125
.
x yEuler ytrue t %
0.0 1.00000 1.00000 -
0.5 1.12500 1.14564 1.80
1.0 1.29167 1.32288 2.36
1.5 1.48522 1.52069 2.33
2.0 1.69563 1.73205 2.10
zar97/09/03 Numerical Methods For Engineers page 6-5
dy
xe y x y(0) = 0
dx
Solution:
y (0.5) y1 y(0) f (0,0)(0.5)
0 (0.5) (0) e0 0
0.0
. ) y2 y(0.5) f (0.5,0.0)(0.5)
y (10
0.0 (0.5) (0.5) e0 0.5
0.5
x yEuler ytrue t %
0.0 0.00000 0.00000 -
0.5 0.00000 0.23610 100
1.0 0.50000 0.83180 39.89
1.5 1.30326 1.64102 20.58
2.0 2.25699 2.62308 13.96
2.5 3.36165 3.79593 11.44
3.0 4.65500 5.18758 10.27
zar97/09/03 Numerical Methods For Engineers page 6-6
Error Analysis In Euler’s 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 Euler’s method by deriving
the formula directly from Taylor’s series expansion. If the function has continuous
derivatives, TS can be expanded about a starting point (xi , yi ),
y ( n 1) ( ) n 1
Rn h where xi xi 1 (6.1-4)
( n 1)!
( n 1)
f ' (xi , yi ) 2 f (xi , yi ) n
yi 1 yi f ( xi , yi )h h ... h ( h n 1 ) (6.1-5)
2 n!
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
( n 1)
f ' (xi , yi ) 2 f (xi , yi ) n
Et h ... h ( h n 1 ) (6.1-6)
2 n!
For sufficiently small h, higher-order terms would decrease appreciably. The approximate
local truncation error can then be written as
f ' ( xi , yi ) 2
Ea h or Ea ( h 2 ) (6.1-7)
2
zar97/09/03 Numerical Methods For Engineers page 6-7
Example 6.1-2: Estimate the true and the approximate local truncation error associated with
the Euler’s method in the first step to solve the following initial-value problem
y ' 2x 3 x 2 5x 2 y(0) = 0
Solution:
( n 1)
f ' ( xi , yi ) 2 f ( xi , yi ) n
Et h ... h ( h n 1 )
2 n!
f ' ( xi , yi ) 2
Ea h
2
f ' ( x , y ) 6x 2 2 x 5
f ' ' (x , y ) 12x 2
f ' ' ' ( x , y ) 12
5 (2 ) 12
Et ( 0.5) 2 ( 0.5) 3 (0.5)4 0.61458
2 6 24
5
Ea ( 0.5) 2 0.625
2
zar97/09/03 Numerical Methods For Engineers page 6-8
Remark: Higher-order term in Taylor series expansion may be included to improve the
accuracy of the Euler’s 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.
Heun’s 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)
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)
y y
(a) (b)
x x
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
yinew old
1 yi 1
a 100% (6.1-12)
yinew
1
Example 6.1-4: Use Heun’s method to solve the following initial-value 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.
f (x0 , y0 ) f ( x1 , y10 )
y11 y0 h
2
0.25 0.33333
1.0 (0.5)
2
114583
.
zar97/09/03 Numerical Methods For Engineers page 6-10
f ( x0 , y0 ) f (x1 , y11 )
y12 y0 h
2
0.25 0.32727
1.0 ( 0.5)
2
114432
.
x yHeun ytrue t %
0.0 1.00000 1.00000 -
0.5 1.14443 1.14564 0.11
1.0 1.32091 1.32288 0.15
1.5
2.0
zar97/09/03 Numerical Methods For Engineers 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
h
yi 1/ 2 yi f (xi , yi ) (6.1-13)
2
This value is used to estimate the value of the slope over the interval,
y y
(a) (b)
x x
Figure 6.1-3: Improved Polygon Method (a) value at mid-point (b) improved formula.
zar97/09/03 Numerical Methods For Engineers page 6-12
Example 6.1-5: Use improved polygon method to solve the following initial-value 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:
y1/2 y0 f (x0 , y0 )(0.25)
y1/2 y (0.25) y (0) f (0,1)(0.25)
1 0 1
1.0 (0.25) ( )
4 1
1.0625
x yHeun ytrue t %
0.0 1.00000 1.00000 -
0.5 1.14706 1.14564 0.12
1.0 1.32508 1.32288 0.17
1.5
2.0
zar97/09/03 Numerical Methods For Engineers page 6-14
iv) Runge-Kutta Methods. The Runge-Kutta methods have the accuracy of the
Taylor series approach without having to evaluate the higher derivatives. The methods can
be generalized in the form
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
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 a’s , p’s , and q’s are evaluated by setting the terms in eq.(6.1-16) equal to
the terms in the Taylor series expansion.
Remark: 1. There exists an infinite number of versions of the RK methods since one
of the parameters such as a’s can be selected infinitely.
2. When n = 1, the first-order RK is basically the Euler’s method.
n +1
3. For lower order versions, the local truncation error is of order h and the
n
global truncation error is of order h .
zar97/09/03 Numerical Methods For Engineers page 6-15
yi 1 yi [ a1k1 a2 k2 ]h (6.1-19)
where
k1 f ( xi , yi )
(6.1-20)
k2 f ( xi p1h, yi q11k1h)
By equating eq.(6.1-19) and the TSE, the following relationships among parameters are
obtained
a1 a2 1
1
a2 p1 (6.1-21)
2
1
a2q11
2
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.
k k2
yi 1 yi 1 h (6.1-22)
2
where
k1 f ( xi , yi )
(6.1-23)
k 2 f ( xi h, yi k1h)
zar97/09/03 Numerical Methods For Engineers page 6-16
yi 1 yi k2h (6.1-24)
where
k1 f ( xi , yi )
(6.1-25)
k 2 f ( xi 21 h, yi 21 k1h)
k 2k2
yi 1 yi 1 h (6.1-22)
3
where
k1 f ( xi , yi )
(6.1-23)
k 2 f ( xi 34 h, yi 43 k1h)
Remark: This last method provides a minimum bound on the local truncation errors
for the 2nd-order RK methods.
Example 6.1-6: Use Ralston’s (2nd-order RK) method to solve the following initial-value
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 Numerical Methods For Engineers page 6-17
For i = 0, step1:
1 0 1
k1 f ( x0 , y0 ) 0.25
4 1
1 0.375 1
k 2 f ( x0 0.375, y0 0.09375) 0.31429
4 1.09375
step2:
k1 2 k2
y1 y0 (0.5)
3
0.25 2 ( 0.31429 )
y1 1.0 (0.5)
3
114643
.
For i = 1, step1:
1 0.5 1
k1 f ( x1 , y1 ) 0.32710
4 114643
.
1 0.875 1
k 2 f ( x1 0.375, y1 012266
. ) 0.36936
4 1.26909
step2:
k1 2 k2
y2 y1 ( 0.5)
3
0.32710 2 ( 0.36936)
y2 114643
. (0.5)
3
1.32407
x yRalston ytrue t %
0.0 1.00000 1.00000 -
0.5 1.14643 1.14564 0.07
1.0 1.32407 1.32288 0.09
1.5 1.52069
2.0 1.73205
zar97/09/03 Numerical Methods For Engineers page 6-18
dy
xe y x y(0) = 0
dx
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
x yRalston ytrue t %
0.0 0.00000 0.00000 -
0.5 0.25000 0.23610 5.89
1.0 0.85263 0.83180 2.50
1.5 1.95365 1.64102 19.05
2.0 2.62308
zar97/09/03 Numerical Methods For Engineers page 6-19
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.1-26)
6
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: If the derivative function depends only on the independent variable x, the
3rd-order RK method is equivalent to the Simpson’s 1/3 rule.
zar97/09/03 Numerical Methods For Engineers page 6-20
Example 6.1-7: Use 3rd-order RK method to solve the following initial-value 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:
For i = 0, step1:
1 0 1
k1 f ( x0 , y0 ) 0.25
4 1
1 0.25 1
k 2 f ( x0 0.25, y0 0.0625) 0.29412
4 1.0625
1 0.5 1
k 3 f ( x0 0.5, y0 0.16912) 0.32075
4 116912
.
step2:
k 4 k2 k 3
y1 y0 1 (0.5)
6
0.25 4(0.29412) 0.32075
y1 1.0 (0.5) 114560
.
6
For i = 1, step1:
1 0.5 1
k1 f ( x1 , y1 ) 0.32734
4 114560
.
1 0.75 1
k 2 f ( x1 0.25, y1 0.08184) 0.35643
4 1.22744
1 10. 1
k 3 f ( x1 0.5, y1 019276
. ) 0.37359
4 1.33836
zar97/09/03 Numerical Methods For Engineers page 6-21
step2:
k 4 k2 k 3
y2 y1 1 (0.5)
6
0.32734 4(0.35643) 0.37359
y2 114560
. (0.5) 1.32282
6
For i = 2, step1:
1 1.0 1
k1 f ( x2 , y2 ) 0.37798
4 1.32282
1 1.25 1
k 2 f ( x2 0.25, y2 0.09450) 0.39688
4 1.41732
1 15. 1
k 3 f ( x2 0.5, y2 0.41577) 0.35949
4 1.73859
step2:
k 4 k 2 k3
y3 y2 1 (0.5)
6
0.37798 4(0.39688) 0.35949
y3 1.32282 (0.5) 151657
.
6
x y3rd-order ytrue t %
0.0 1.00000 1.00000 -
0.5 1.14560 1.14564 0.003
1.0 1.32282 1.32288 0.005
1.5 1.51657 1.52069 0.271
2.0 1.72843 1.73205 0.209
zar97/09/03 Numerical Methods For Engineers 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.1-28)
6
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: If the derivative function depends only on the independent variable x, the
4th-order RK method is also equivalent to the Simpson’s 1/3 rule.
Example 6.1-8: Use 4th-order RK method to solve the following initial-value 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:
For i = 0, step1:
1 0 1
k1 f ( x0 , y0 ) 0.25
4 1
1 0.25 1
k 2 f ( x0 0.25, y0 0.0625) 0.29412
4 1.0625
1 0.25 1
k 3 f ( x0 0.25, y0 0.0.07353) 0.29110
4 1.07353
1 0.5 1
k 4 f ( x0 0.5, y0 0.14555) 0.32735
4 114555
.
zar97/09/03 Numerical Methods For Engineers page 6-23
step2:
k 2 k2 2 k 3 k 4
y1 y0 1 (0.5)
6
0.25 2(0.29412) 2(0.29110) 0.32735
y1 1.0 (0.5) 114565
.
6
For i = 1, step1:
1 0.5 1
k1 f ( x1 , y1 ) 0.32733
4 114565
.
1 0.75 1
k 2 f ( x1 0.25, y1 0.08183) 0.35642
4 1.22748
1 0.75 1
k 3 f ( x1 0.25, y1 0.08911) 0.35432
4 1.23476
1 1.0 1
k 4 f ( x1 0.5, y1 0.17716) 0.37798
4 1.32281
step2:
k 2 k2 2 k 3 k 4
y1 y0 1 (0.5)
6
0.32733 2(0.35642) 2(0.35432) 0.37798
y1 114565
. (0.5) 1.32288
6
x y4th-order ytrue t %
0.0 1.00000 1.00000 -
0.5 1.14565 1.14564 0.0009
1.0 1.32288 1.32288 0.0002
1.5 1.52069
2.0 1.73205
zar97/09/03 Numerical Methods For Engineers page 6-24
dy
xe y x y(0) = 0
dx
Solution:
For i = 0, step1:
k1 f ( x0 , y0 ) (0)( e0 1) 0
k 2 f ( x0 0.25, y0 0) (0.25)( e0 1) 0.5
. ) (0.25)( e0.125 1) 0.47062
k 3 f ( x0 0.25, y0 0125
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
0 2(0.5) 2(0.47062) 0.89516
y1 0.0 (0.5) 0.23637
6
x yRalston ytrue t %
0.0 0.00000 0.00000 -
0.5 0.23637 0.23610 0.11
1.0 0.83180
1.5 1.64102
2.0 2.62308
zar97/09/03 Numerical Methods For Engineers 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 )
(6.1-30a)
y ' n f n ( x , y1 , y2 , . . ., yn )
y1 ( x0 ) y1,0
y1 ( x0 ) y2,0
(6.1-31a)
yn ( x0 ) yn,0
and
y( x0 ) y0 or y ( x0 ) y0 (6.1-31b)
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 Numerical Methods For Engineers page 6-26
Example 6.1-8: Solve the following set of differential equations using Euler’s method
y '1 0.4 y1
y ' 2 5 0.2 y1 0.3y2
Note that the old value of y1 is used in the computation of y2 instead of the new value.
Continuing in the same manner yields
x y1 y2
0.0 6 4
0.5 4.8 5.7
1.0 3.84 6.64
1.5 3.072 7.76
2.0 2.4576 8.7888
zar97/09/03 Numerical Methods For Engineers page 6-27
Example 6.1-9: Solve the problem in example 6.1-9 using the 4th-order RK method.
Solution:
y '1 f 1 ( x , y1 , y2 ) 0.4 y1
y ' 2 f 2 ( x , y1 , y2 ) 5 0.2 y1 0.3y2
step2: calculate the values of y1 and y2 needed for the calculation of the k2 ’s,
step4: calculate the values of y1 and y2 needed for the calculation of the k3 ’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
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
6
2.4 2(2.16) 2(2.184 ) 1.9632 4.9124
( 0.5)
y2 ,1 4.0
6
2.6 2(2.525) 2( 2.51863) 2.44061 5.26066
x y1 y2
0.0 6 4
0.5 4.9124 5.26066
1.0
1.5
2.0
zar97/09/03 Numerical Methods For Engineers page 6-29
dny
n
y (n ) ( x ) f (x , y , y ', y '' , y ( 3) , . . . , y ( n 2 ) , y (n 1) ) (6.1-32)
dx
where k represents the kth derivative of the function and both y and f are real-valued
functions.
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 )
Example 6.1-10: Convert the following problem into simultaneous first-order equations and
solve using Euler’s method
d 2y dy
2
y x 2 1 with initial conditions y ( 0) 5, y ' (0) 2
dx dx
from x = 0 to x = 2 with h = 1.
y '1 (x ) y2 (x ) y1 (0) 5
y ' 2 ( x ) y1 (x ) y2 (x ) x 2 1 y2 ( 0) 2
x y1 y2
0.0 5.0 2.0
0.5 7.0 13.0
2.0 20.0 106.0
zar97/09/03 Numerical Methods For Engineers page 6-31
Worksheet 6.1-4: For a nonlinear self-sustained oscillation, the Vanderpol’s equation can be
expressed as
3
d 2y dy dy
3 2
0.3 0.3 3y 0 with i.c’s: y ( 0) y '( 0) 1
dx dx dx
Convert the problem into simultaneous first-order equations and solve by Euler’s method from
x = 0 to x = 2 with h = 1.
y1 ( x ) y (x ) and y2 ( x ) y ' (x )
y '1 (x ) y2 (x ) y1 ( 0) 1
y ' 2 ( x ) 01 . ( y2 ) 3 y1
. y2 01 y2 (0) 1
x y1 y2
0.0 1.0 1.0
0.5 2.0 0.0
2.0 2.0 -2.0