Вы находитесь на странице: 1из 31

zar97/09/03 Numerical Methods For Engineers page 6-1

6.0 ORDINARY DIFFERENTIAL EQUATIONS


“Engineer is one who, within his endowed power,
transforms problems into solutions.”- zar97

“The best among you is the one who has highest piety.”- Meaning of Al-Ayat.

Objectives: After completing Part Six, students should be able

1. to solve ordinary differential equation using numerical techniques.

2. to assess the reliability of the answers obtained.

3. to choose the ‘best’ method for any particular problem.

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

where y is a function of a single independent variable x and n is a positive integer. If the


function y depends on several independent variables i.e. x1, x2, . . . , xm, the equation is
called partial differential equation. In this part, we only concentrate on the ordinary
differential equations (ODEs) of the first-order which has the form

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

6.1 One-Step Methods

The solution of eq.(6.0-3) can be estimated in the form

New value = old value + slope x step size

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)

Figure 6.1-1: Graphical depiction of Euler’s method.


zar97/09/03 Numerical Methods For Engineers page 6-4

Using Euler’s method to estimate the solution of ODE.

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
.

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 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

Using Euler’s method to estimate the solution of ODE.

Use Euler’s method to solve the following initial-value problem from x = 0


Worksheet 6.1-1:
to x = 3 with h = 0.5. Compare the results with the true solutions.

dy
 xe y  x y(0) = 0
dx

Solution:
y (0.5)  y1  y(0)  f (0,0)(0.5)


 0  (0.5) (0) e0  0 
 0.0

. )  y2  y(0.5)  f (0.5,0.0)(0.5)
y (10


 0.0  (0.5) (0.5) e0  0.5 
 0.5

The remaining computations are shown in table below,

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 ),

yi '' 2 yi( 3) 3 y (n)


yi 1  yi  yi ' h  h  h  . . .  i h n  Rn where h  xi 1  xi (6.1-3)
2 3! n!

and Rn is the remainder defined as

y ( n  1) ( ) n  1
Rn  h where xi    xi 1 (6.1-4)
( n  1)!

Now, if we substitute the derivative function f(xi , yi ) into eq.(6.1-3), we obtain

( 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

Error estimate for Euler’s method in the solution of ODE.

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

from x = 0 to x = 3 with h = 0.5.

Solution:

Recall eq.(6.1-6) and eq.(6.1-7),

( 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

Derivatives of the derivative function,

f ' ( x , y )  6x 2  2 x  5
f ' ' (x , y )  12x  2
f ' ' ' ( x , y )  12

At starting point x0 = 0 , y0 = 0 and h = 0.5,

f '( 0,0)  5 f ' ' (0,0)  2 f ' ' '( 0,0)  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.

Modification and Improvements of Euler’s Method. Two simple


modifications are made: Heun’s Method and Improved Polygon Method.

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)

is used to estimate the value of yi+1 ,

yi01  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)

The average of the two slopes is

f (xi , yi )  f (xi  1 , yi01 )


yi 1  yi  h Corrector equation (6.1-11)
2

y y

(a) (b)

x x

Figure 6.1-2: Heun’s modification-(a) predictor and (b) Corrector.


zar97/09/03 Numerical Methods For Engineers 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

yinew old
1  yi 1
a  100% (6.1-12)
yinew
1

Heun’s method to solve the ODE.

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.

Solution: Predictor equation,

y 0 ( 0.5)  y10  y (0)  f ( 0,1)(0.5)


1 0  1 
 1.0  ( 0.5)  ( )
4 1 
 1125
.
Corrector equation,

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
.

f (x0 , y0 )  f (x1 , y12 )


y13  y0  h
2
0.25  0.32771
 1.0  ( 0.5)
2
 114443
.
Predictor equation,
y 0 (1.0)  y20  y ( 0.5)  f ( 0.5,114443
. )( 0.5)
 1 0.5  1 
 114443
.  (0.5) ( )
 4 114443
. 
 1.30827
Corrector equation,
f (x1 , y1 )  f (x2 , y20 )
y12  y1  h
2
0.32767  0.38218
 114443
.  ( 0.5)
2
 1.32189
The remaining results are shown in table below,

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,

  f ( xi 1/2 , yi 1/ 2 ) (6.1-14)

yi 1  yi  f (xi 1/ 2 , yi 1/2 ) h (6.1-15)

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

Improved Polygon method to solve the ODE.

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

y1  y0  f ( x1/ 2 , y1/ 2 )(0.5)


y1  y (0.5)  y (0)  f (0.25,1.0625)(0.5)
 1 0.25  1 
 1.0  (0.5) ( )
 4 1.0625 
 114706
.
zar97/09/03 Numerical Methods For Engineers 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 ( x11/2 , y11/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

The remaining results are shown in table below,

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

where ai  constants i  1,2,..., n.

and the k’s are computed recursively by

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

Second-order Runge-Kutta Method. From eq.(6.1-16), the second-order RK method is


written as

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.

Commonly used 2nd-order RK versions:


. Heun’s method with a single corrector (a2 = 1/2). Eq.(6.1-21) gives

a1 = 1/2, p1 = 1, and q11 = 1

and the solution is given by

 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

. Improved Polygon method (a2 = 1). Eq.(6.1-21) gives

a1 = 0, p1 = 1/2, and q11 = 1/2

and the solution is given by

yi 1  yi  k2h (6.1-24)

where
k1  f ( xi , yi )
(6.1-25)
k 2  f ( xi  21 h, yi  21 k1h)

. Ralston’s method (a2 = 2/3). ). Eq.(6.1-21) gives

a1 = 1/3, p1 = 3/4, and q11 = 3/4

and the solution is given by

 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.

Using 2nd-order Runge-Kutta method to solve the ODE.

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

The remaining results are shown in table below,

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

Using Euler’s method to estimate the solution of ODE.

Use Ralston’s method to solve the following initial-value problem from x =


Worksheet 6.1-2:
0 to x = 2 with h = 0.5. Compare the results with the true solutions.

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

The remaining computations are shown in table below,

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

Third-order Runge-Kutta Method. From eq.(6.1-16), the second-order RK method is


written as

yi 1  yi  [a1k1  a2 k2  a3k 3 ]h (6.1-24)


where
k1  f ( xi , yi )
k2  f ( xi  p1h, yi  q11k1h) (6.1-25)
k 3  f ( xi  p2h, yi  [q21k1  q22 k 2 ]h)

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.

One common version is given by

 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

Using 3nd-order Runge-Kutta method to solve the ODE.

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 

The remaining results are shown in table below,

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.

Using 4th-order Runge-Kutta method to solve the ODE.

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 

The remaining results are shown in table below,

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

Using the Runge-Kutta method to estimate the solution of ODE.

Use 4th-order RK method to solve the following initial-value problem from


Worksheet 6.1-3:
x = 0 to x = 2 with h = 0.5. Compare the results with the true solutions.

dy
 xe y  x y(0) = 0
dx
Solution:
For i = 0, step1:
k1  f ( x0 , y0 )  (0)( e0  1)  0
k 2  f ( x0  0.25, y0  0)  (0.25)( e0  1)  0.5
. )  (0.25)( e0.125  1)  0.47062
k 3  f ( x0  0.25, y0  0125
k 4  f ( x0  0.5, y0  0.23531)  (0.5)( e0.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 

The remaining computations are shown in table below,

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.

B. Systems of Differential Equations. There are situations when one


has to solve a system of simultaneous differential equations. The system of n first-order
differential equations can be represented in general as

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 )

with n initial conditions,

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)

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

Using one-step method to solve a system of ODE.

Example 6.1-8: Solve the following set of differential equations using Euler’s method

y '1 0.4 y1  0 y1 (0)  6


y '2 0.2 y1  0.3y2  5  0 y2 ( 0)  4

from x = 0 to x = 2 with h = 0.5.

Solution: The above equations may expressed as

y '1  0.4 y1
y ' 2  5  0.2 y1  0.3y2

Then applying Euler’s method at each step,

y1 ( 0.5)  6  [0.4 (6)]( 0.5)  4.8


y2 (0.5)  4  [5  0.2 ( 6)  0.3(4 )]( 0.5)  6.6

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

y1 (1.0)  4.8  [0.4 (4.8)](0.5)  384.


y2 (1.0)  6.6  [5  0.2 (4.8)  0.3( 6.6)](0.5)  6.64

and the remaining results are

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

Using one-step method to solve a system of ODE.

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

Step1: calculate all the k1 ’s,

k1,1  f1 (0,6,4 )  0.4 (6)  2.4


k1,2  f 2 (0,6,4 )  5  0.2 (6)  0.3(4 )  2.6

step2: calculate the values of y1 and y2 needed for the calculation of the k2 ’s,

y1  12 hk1,1  6  12 ( 0.5)(2.4 )  5.4


y2  12 hk1, 2  4  12 ( 0.5)(2.6)  4.65

Step3: calculate all the k2 ’s,

k 2 ,1  f 1 ( 0.25,5.4 ,4.65)  0.4(5.4 )  2.16


k 2 ,2  f 2 ( 0.25,5.4 ,4.65)  5  0.2 (5.4 )  0.3( 4.65)  2.525

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

Step5: calculate all the k3 ’s,

k 3,1  f 1 (0.25,5.46,4.63125)  0.4 (5.46)  2.184


k 3, 2  f 2 ( 0.25,5.46,4.63125)  5  0.2 (5.46)  0.3(4.63125)  2.51863
zar97/09/03 Numerical Methods For Engineers page 6-28

step6: calculate the values of y1 and y2 needed for the calculation of the k4 ’s,

y1  hk 3,1  6  (0.5)(2.184)  4.908


y2  hk 3, 2  4  (0.5)(2.51863)  5.25932

Step7: calculate all the k4 ’s,

k 4 ,1  f 1 ( 0.25,4.908,5.25932 )  0.4 (4.908)  1.9632


k 4 ,2  f 2 ( 0.25,4.908,5.25932 )  5  0.2 (4.908)  0.3(5.25932 )  2.44061

The values of yk(0.5) can be computed using eq.(6.1-28)

 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

and the remaining solutions are

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

Higher-order differential equations.

Higher-order differential equations may be converted into a set of first-order simultaneous


equations. The solution method is similar to the methods discussed early. In general, an
nth-order differential equation has the form

dny
n
 y (n ) ( x )  f (x , y , y ', y '' , y ( 3) , . . . , y ( n  2 ) , y (n 1) ) (6.1-32)
dx

with initial conditions,

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 )

Therefore, solving eq.(6.1-32) is equivalent to solving the following set of simultaneous


equations,
y '1  y2 ( x )
y '2  y3 (x )
 (6.1-34)
y 'n 1 ( x )  yn ( x )
y 'n ( x )  f (x , y1 , y2 , . . ., yn 1 )
zar97/09/03 Numerical Methods For Engineers page 6-30

Using one-step method to solve a system of ODE.

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.

Solution: Rearranging the above equation into the form of eq.(6.1-32),

y ' '  f (x , y , y ' )  yy ' x 2  1

Introducing new variables,


y1 ( x )  y (x ) and y2 ( x )  y ' (x )

we obtain two simultaneous equations as

y '1 (x )  y2 (x ) y1 (0)  5
y ' 2 ( x )  y1 (x ) y2 (x )  x 2  1 y2 ( 0)  2

Then applying Euler’s method at each step,

y1 (1.0)  5.0  [ 2.0](1.0)  7.0


y2 (1.0)  2.0  [5.0(2.0)  ( 0) 2  1](1.0)  13.0

y1 ( 2.0)  7.0  [13.0](1.0)  20.0


y2 (2.0)  13.0  [7.0(13.0)  (1.0)2  1](1.0)  106

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

Using one-step method to solve a system of ODE.

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.

Solution: Rearranging the above equation into the form of eq.(6.1-32),

y ' '  f ( x , y , y ' )  01 . ( y' )3  y


. y '01

Introducing new variables,

y1 ( x )  y (x ) and y2 ( x )  y ' (x )

we obtain two simultaneous equations as

y '1 (x )  y2 (x ) y1 ( 0)  1
y ' 2 ( x )  01 . ( y2 ) 3  y1
. y2  01 y2 (0)  1

Then applying Euler’s method at each step,

y1 (1.0)  1.0  [1.0](1.0)  2.0


y2 (1.0)  1.0  [ 01 . (1) 3  1](1.0)  0.0
. (1)  01

y1 ( 2.0)  2.0  [0.0](1.0)  2.0


. (0.0)  ( 0.0) 3  2.0](1.0)  2.0
y2 (2.0)  0.0  [ 01

x y1 y2
0.0 1.0 1.0
0.5 2.0 0.0
2.0 2.0 -2.0

Вам также может понравиться