0% found this document useful (0 votes)
213 views14 pages

PART-7 Ordinary Differential Equations Runge-Kutta Methods: Numerical Methods of Chemical Engineers CHE F242

Uploaded by

Hritik Lal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
213 views14 pages

PART-7 Ordinary Differential Equations Runge-Kutta Methods: Numerical Methods of Chemical Engineers CHE F242

Uploaded by

Hritik Lal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

PART-7

ORDINARY DIFFERENTIAL
EQUATIONS
Chapter 25
Runge-Kutta Methods

Numerical Methods of Chemical Engineers


CHE F242

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solving Ordinary Differential Equations (ODEs)

• This chapter is devoted to solving ordinary


differential equations (ODEs) of the form
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:

  f ( x i , y i ) (Ist derivative evaluated at x i and y i )


then,
y i 1  y i  f ( x i , y i )h

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 ( n1) ( xi , yi ) n Ea  h  O(h 2 )
yi 1  yi  f ( x i , yi )h  h  ...  h  O( h n1 ) 2!
2! n!
EULER Local Truncation ERROR

• The error is reduced by 4 times if the step size is halved  O(h2).


• In real problems, the derivatives used in the Taylor series are not easy to obtain.
• If the solution to the differential equation is linear, the method will provide error
free predictions (2nd derivative is zero for a straight line).

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

y(0.5) = y(0)+f(0, 1)0.5 = 1+8.5*0.5 = 5.25


(true solution at x=0.5 is y(0.5) = 3.22 and t = 63%)

y(1) = y(0.5)+f(0.5, 5.25)0.5


= 5.25+[-2(0.5)3+12(0.5)2-20(0.5)+8.5]*0.5
= 5.25+0.625 = 5.875
(true solution at x=1 is y(1) = 3 and t = 96%)
y(1.5) = y(1)+f(1, 5.875)0.5 = 5.125
…. 
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example: Euler’s Method
Estimate the Error : 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:
f'(x i , yi ) 2 f II (x i , y i ) 3 f (3) (x i , y i ) 4
Et = h  h  h
2! 3! 4!
where, f'(x i , yi ) = first derivative of the differential eqn.
f'(x i , yi ) = -6x 2 + 24x - 20
f II (x i , yi ) = -12x+ 24
f (3) (x i , yi ) = -12
We can omit the higher order terms because for this particular case, they equal to zero.

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!

Total Truncation Error:


E t = E t, 2  E t, 3  E t, 4  2.5  0.5  0.03125  2.03125
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.25, Initial condition: (x=0 ; y=1)
Exact Solution: y = -0.5x4 + 4x3 - 10x2 + 8.5x + 1
Numerical Solution:
x yExact f(xi, yi) yEuler Et %
0 1 1
0.25 2.560547 8.5 3.125 22.04424
0.5 3.21875 4.21875 4.179688 29.85437
0.75 3.279297 1.25 4.492188 36.9863
1 3 -0.59375 4.34375 44.79167
1.25 2.591797 -1.5 3.96875 53.12735
1.5 2.21875 -1.65625 3.554688 60.21127
1.75 1.998047 -1.25 3.242188 62.26784
2 2 -0.46875 3.125 56.25
2.25 2.248047 0.5 3.25 44.56994
2.5 2.71875 1.46875 3.617188 33.04598
2.75 3.341797 2.25 4.179688 25.07306
3 4 2.65625 4.84375 21.09375
3.25 4.529297 2.5 5.46875 20.7417
3.5 4.71875 1.59375 5.867188 24.33775
3.75 4.310547 -0.25 5.804688 34.66244
4 3 -3.21875 5 66.66667
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Improve Accuracy

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Improvements of Euler’s method

• A fundamental source of error in Euler’s method is that the


derivative at the beginning of the interval is assumed to apply
across the entire interval.

• Two simple modifications are available to circumvent this


shortcoming:

– 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

• The two derivatives are then


averaged to obtain an improved
estimate of the slope for the entire
interval.

Predictor : yi01  yi  f ( xi , yi )h
f ( xi , yi )  f ( xi 1 , yi01 )
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.

You might also like