PART-7 Ordinary Differential Equations Runge-Kutta Methods: Numerical Methods of Chemical Engineers CHE F242
PART-7 Ordinary Differential Equations Runge-Kutta Methods: Numerical Methods of Chemical Engineers CHE F242
ORDINARY DIFFERENTIAL
EQUATIONS
Chapter 25
Runge-Kutta Methods
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solving Ordinary Differential Equations (ODEs)
Euler’s Method
• First derivative provides a direct estimate of
the slope at xi:
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 ( x i , y i ) 2
"
y 2 ( n)
y Ea h R3
yi 1 yi yi' h i
h ... i
h n Rn 2!
2! n!
f ( ) 2
f ' ( xi , yi ) 2 f ( n1) ( xi , yi ) n Ea h O(h 2 )
yi 1 yi f ( x i , yi )h h ... h O( h n1 ) 2!
2! n!
EULER Local Truncation ERROR
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example: Euler’s Method
Solve numerically : dy
2 x 3 12 x 2 20 x 8.5
dx
From x=0 to x=4 with step size h=0.5. Initial condition: (x=0 ; y=1)
Exact Solution: y = -0.5x4 + 4x3 - 10x2 + 8.5x + 1
Numerical Solution:
yi 1 yi f ( xi , yi )h
y(0.5) = y(0) + f(0, 1)0.5
At x = 0, y(0) = 1;
f(0, 1) = -2(0)3 + 12(0)2 – 20(0) + 8.5
y(0.5) = 1+8.5*0.5 = 5.25
The true solution at x=0.5 is
y = -0.5(0.5)4 + 4(0.5)3 – 10(0.5)2 + 8.5 * 0.5 + 1
= 3.21875
and the error is
Et = 63%
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
X yeuler ytrue Error Error
Example: Euler’s Method Global Local
Solve numerically : dy
2 x 3 12 x 2 20 x 8.5 0 1 1 % %
dx
From x=0 to x=4 with step size h=0.5 0.5 5.250 3.218 63.1 63.1
initial condition: (x=0 ; y=1)
1.0 5.875 3.000 95.8 28
Exact Solution: y = -0.5x4 + 4x3 - 10x2 + 8.5x + 1 1.5 5.125 2.218 131.0 1.41
Numerical
Solution: yi 1 yi f ( xi , yi )h 2.0 4.500 2.000 125.0 20.5
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Numerical Solution:
Error due to truncation of the 2nd order term can be calculated as:
-6x 2 + 24x - 20 2 -6(0) 2 + 24(0) - 20
E t, 2 = h = (0.5) 2 2.5
2! 2!
Error due to truncation of the 3nd order term can be calculated as:
-12x+ 24 3 -12(0)+ 24
E t, 3 = h = (0.5)3 0.5
3! 3!
Error due to truncation of the 4th order term can be calculated as:
-12 4 -12
E t, 4 = h = (0.5) 4 0.03125
4! 4!
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
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
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Problem
Use Heun's Method to integrate y' = 4e 0.8x - 0.5y from x=0 to 4,
with a step size of 1. The initial condition at x=0 is y=2.
4 0.8x
Analytical Solution: y = (e - e -0.5x ) + 2e -0.5x
1.3
1st step: The slope at (x 0 , y 0 ) is calculated as:
y 0 ' = 4e 0.8(0) - 0.5(2) = 3
Numerical solution is obtained by using predictor to obtain an estimate of y at 1.0:
yi+10 = y i + f(x i , yi )h = 2+3(1) = 5
Numerical solution is obtained by using predictor to obtain an estimate of y at 1.0:
yi+10 = yi + f(x i , yi )h = 2+3(1) = 5
To improve the estimate for y i+1, we use the value of y10 to predict the slope at the
end of the interval,
y1'=f(x i , yi 0 ) = 4e 0.8(1) - 0.5(5) = 6.402164
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Problem
This can be combined with the initial slope to yield an average slope over the interval
from x=0 to x=1
(3 6.402164)
y' = 4.701082
2
This result can be substituted into the corrector equation to give the prediction at x=1;
y1 = 2 + 4.701082(1) = 6.701082
This estimate can be used to refine or correct the prediction of y1 by substituting the
new result
[3 4e 0.8(1) - 0.5(6.701082)]
y1 = 2 + (1) = 6.275811
2
This estimate can be used to further refine or correct the prediction of y1 by substituting the
new result
[3 4e0.8(1) - 0.5(6.275811)]
y1 = 2 + (1) = 6.382129
2
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Problem
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.