Professional Documents
Culture Documents
(CENG-2084)
Chapter 7
Numerical Solution of Ordinary
Differential Equations
1
Mastewal S 5/22/2020
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Differential Equations
• Differential equations play a fundamental role in engineering.
• Equations which are composed of an unknown function and its
derivatives are called differential equations.
2
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solving Ordinary Differential Equations (ODEs)
dy
f ( x, y )
dx
New value old value slope * (step size)
yi 1 yi * h
Euler’s Method
• First derivative provides a direct estimate of
the slope at xi
then,
y i 1 y i f ( x i , y i )h
3
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Error Analysis for Euler’s Method
• Numerical solutions of ODEs involves two types of error:
– Truncation error
• Local truncation error
• Propagated truncation error
The sum of the two is the total or global truncation error
– Round-off errors (due to limited digits in representing numbers in a computer)
• We can use Taylor series to quantify the local truncation error in Euler’s method.
Given y' f ( x , y ) f ( xi , yi ) 2
yi" 2 yi( n ) n Ea h R3
yi 1 yi y h h ...
'
i h Rn 2!
2! n!
f ( n1) ( xi , yi ) n
f ( xi , yi ) 2
yi 1 yi f ( xi , yi )h
f ' ( xi , yi ) 2
h ... h O( hn1 ) Ea h O( h 2 )
2! n! 2!
EULER Local Truncation ERROR
5
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Improvements of Euler’s method
– Heun’s Method
– The Midpoint (or Improved Polygon) Method
6
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Heun’s method
• To improve the estimate of the slope,
determine two derivatives for the interval:
• At the initial point
• At the end point
Predictor : yi01 yi f ( xi , yi )h
f ( xi , yi ) f ( xi 1 , yi01 )
Corrector : yi 1 yi h
2
7
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Heun’s method (improved)
Original Huen’s:
Predictor : yi01 yi f ( xi , yi )h
f ( xi , yi ) f ( xi 1 , yi01 )
Corrector : yi 1 yi h
2
Note that the corrector can be iterated to improve the
accuracy of yi+1.
Predictor : yi01 yi f ( xi , yi )h
f ( xi , yi ) f ( xi 1 , yij11 )
Corrector : y ij1 yi h j 1,2,...
2
However, it does not necessarily converge on the true answer
but will converge on an estimate with a small error.
h
yi 1/2 yi f ( xi , yi )
2
yi 1 yi f ( xi 1/ 2 , yi 1/ 2 )h
9
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Runge-Kutta Methods (RK)
• Runge-Kutta methods achieve the accuracy of a Taylor series approach
without requiring the calculation of higher derivatives.
yi 1 yi ( xi , yi , h)h
a1k1 a2 k 2 an k n Increment Function
yi 1 yi ( xi , yi , h)h
a1k1 a2 k 2 an k n
k1 f ( xi , yi )
yi 1 yi f ( xi , yi )h (Euler' s Method)
11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Runge-Kutta Methods Cont’d
yi 1 yi (a1k1 a2 k2 )h
k1 f ( x i , yi ) k2 f ( xi p1h, yi q11k1h)
• Values of a1, a2, p1, and q11 are evaluated by setting the above
equation equal to a Taylor series expansion to the second order
term. This way, three equations can be derived to evaluate the
four unknown constants (See Box 25.1 for this derivation). On
page 731. a1 a2 1
1
a 2 p1
A value is assumed for one of the 2
unknowns to solve for the other three.
1
a2 q11
2 12
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
yi 1 yi (a1k1 a2 k2 )h a1 a2 1
k1 f ( x i , yi ) k2 f ( xi p1h, yi q11k1h) 1
a 2 p1
2
• Because we can choose an infinite number of values for a2,
1
there are an infinite number of second-order RK methods. a2 q11
2
Three of the most commonly used methods are:
– Huen’s Method with a Single Corrector (a2=1/2)
1 1
yi 1 yi (a1k1 a2 k 2 )h yi ( k1 k 2 ) h
2 2
k1 f ( x i , yi ) k 2 f ( xi h, yi k1h) 13
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
yi 1 yi (a1k1 a2 k2 )h a1 a2 1
k1 f ( x i , yi ) k2 f ( xi p1h, yi q11k1h) 1
a 2 p1
2
1
The Midpoint Method (a2 = 1) a2 q11
2
a1 = 0 p1 = 1/2 q11 = 1/2
yi 1 yi ( a1k1 a2 k 2 )h yi ( k 2 ) h
1 1
k1 f ( x i , yi ) k 2 f ( xi h, yi k1h)
2 2
h h
yi 1 yi ( k 2 ) h yi f ( xi , yi f ( x i , yi ))h
2 2
14
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Comparison of Various
• Three most commonly used Second-Order RK Methods
methods:
1 2
yi 1 yi (a1k1 a2 k 2 )h yi ( k1 k 2 )h
3 3
3 3
k1 f ( x i , yi ) k 2 f ( xi h, yi k1h)
4 4 15
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Systems of Equations
• Many practical problems in engineering and science require the solution of a
system of simultaneous ordinary differential equations (ODEs) rather than a
single equation:
dy1
f1 ( x, y1 , y2 , , yn )
dx
dy2
f 2 ( x, y1 , y2 , , yn )
dx
dyn
f n ( x, y1 , y2 , , yn )
dx
• Solution requires that n initial conditions be known at the starting value of x.
i.e. (x0, y1(x0), y2(x0), …, yn(x0))