0% found this document useful (0 votes)
503 views17 pages

Chap Ode

Uploaded by

Naveed Ahmad
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)
503 views17 pages

Chap Ode

Uploaded by

Naveed Ahmad
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/ 17

Numerical Solution

of
Ordinary Differential Equations

Chapter 25

Credit: Prof. Lale Yurttas, Chemical Eng., Texas A&M University


1
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Differential Equations

• Differential equations play a fundamental role in engineering. Many


physical phenomena are best formulated in terms of their rate of change:
dv c v- dependent variable
g v
dt m t- independent variable

• Equations which are composed of an unknown function and its


derivatives are called differential equations.

• One independent variable  ordinary differential equation (or ODE)


• Two or more independent variables  partial diff. equation (or PDE)

• A first order equation includes a first derivative as its highest derivative


• Second order equation includes second derivative

• Higher order equations can be reduced to a system of first order


equations, by redefining the variables.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ODEs and Engineering Practice

Swinging pendulum

d 2 g
2
 sin   0
dt l
A second-order
nonlinear ODE.

Falling parachutist problem


3
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 , yi ) (diff. equ. evaluated at x i and y i )

then,
y i 1  y i  f ( x i , y i )h
4
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 ( xi , yi ) 2
yi 1  yi  f ( xi , yi )h 
f ' ( xi , yi ) 2
h  ... 
f ( n1) ( xi , yi ) n
h  O( hn1 ) Ea  h  O(h 2 )
2! n! 2!
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).
5
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 5.125 2.218 131.0 1.41
1.5
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 et = 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 et = 96%)
y(1.5) = y(1)+f(1, 5.875)0.5 = 5.125
…. 
6
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

7
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

8
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Heun’s method (improved)
Original Huen’s:

Predictor : yi01  yi  f ( xi , yi ) h
f ( xi , yi )  f ( xi 1 , yi01 )
Corrector : yi 1  yi  h
2
Note that the corrector can be iterated to improve the
accuracy of yi+1.

Predictor : yi01  yi  f ( xi , yi )h
f ( xi , yi )  f ( xi 1 , yij11 )
Corrector : y ij1  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.

Example 25.5 from Textbook 9


Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The Midpoint (or Improved Polygon) Method

• Uses Euler’s method to predict a


value of y using the slope value at
the midpoint of the interval:

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

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

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

a ' s are constants


k1  f ( xi , yi )
k 2  f ( xi  p1h, yi  q11k1h) p ’ s and q ’ s are constants
k3  f ( xi  p3h, yi  q21k1h  q22k 2 h)

k n  f ( xi  pn 1h, yi  qn 1k1h  qn 1, 2 k 2 h    qn 1,n 1k n 1h)
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Runge-Kutta Methods (cont.)

• Various types of RK methods can be devised by employing different number


of terms in the increment function as specified by n.

• First order RK method with n=1 and a1 =1 is in fact Euler’s method.

yi 1  yi   ( xi , yi , h)h
  a1k1  a2 k 2    an k n

k1  f ( xi , yi )

choose n 1 and a1  1, we obtain

yi 1  yi  f ( xi , yi )h (Euler's Method)

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Runge-Kutta Methods (cont.)

Second-order Runga-Kutta Methods:

yi 1  yi  (a1k1  a2 k 2 )h
k1  f ( x i , yi ) k 2  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).
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 13
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
yi 1  yi  (a1k1  a2 k 2 )h a1  a2  1
k1  f ( x i , yi ) k 2  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)

– The Midpoint Method (a2=1)

– Ralston’s Method (a2=2/3)

Huen’s Method (a2 = 1/2)  a1 = 1/2 p1 = 1 q11 = 1

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)
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
yi 1  yi  (a1k1  a2 k 2 )h a1  a2  1
k1  f ( x i , yi ) k 2  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

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:

– Huen Method with a Single


Corrector (a2=1/2)

– The Midpoint Method (a2=1)

– Ralston’s Method (a2=2/3)

Ralston’s Method (a2=2/3)

1 2
y i 1  y i  ( a1k1  a 2 k 2 )h  y i  ( k1  k 2 )h
3 3
3 3
k1  f ( x i , y i ) k 2  f ( x i  h, y i  k1h)
4 4
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))

• At iteration i, n values (y1(xi), y2(xi), …, yn(xi)) are computed.


17
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

You might also like