Lecture 9
Lecture 9
3
EXAMPLE: ODE IN CHEMICAL REACTION
PROBLEM
Hence,
A chemical reaction of the type of dCA
k1 k1C AC B k 2CC
A B C dt
k2
(2)
dCB
k1C AC B k 2CC ODE
dt
takes place in a reactor, the material balance can be dCC
applied as: k1C AC B k 2CC
dt
Input + Generation =Output +Accumulation
(3)
For a batch reactor,
Input + Generation =Output +Accumulation
4
CLASSIFICATION OF ODES
ODEs are classified according to their order and their linearity.
The order of an ODE is the order of the highest derivative present in that equation.
1st order
dy
y kx
dx
d2y dy
2nd order 2
y kx
dx dx
2
d3y d 2 y dy
3rd order 3
a 2 b kx
dx dx dx
5
CLASSIFICATION OF ODES
ODEs also can be classified according to its linearity, i.e. linear and nonlinear ODE.
5 2
d3y d 2 y dy
3 a 2 b kx
dx dx dx Has degree of 5
2 5 10
d3y d2y dy
3 a 2 b kx
dx dx dx Has degree of 2
7
RUNGE-KUTTA METHODS
• However not all ODEs can be solved using analytical methods of calculus.
• Need to use numerical methods.
• Methods used to solve ODEs using iterative methods.
• Developed by German mathematicians C. Runge and M.W. Kutta.
dy
f ( x, y)
dx
8
RUNGE-KUTTA METHODS
• Euler’s method
• Heun’s method
• Midpoint method
• Higher Order Runge-Kutta (RK) method
9
RUNGE-KUTTA METHODS
• Solve ordinary differential equations of the form
dy
f ( x, y)
dx
• Applied step by step to compute out the value in the future (trajectory of the solution).
10
RUNGE-KUTTA METHODS
• The type of RK methods can be differentiated by the manner in which the slope is
estimated.
• The easiest one-step method: Euler’s method.
• However, Euler’s method has the least accurate predictions compared to other RK
methods.
11
EULER’S METHOD
12
EULER’S METHOD
• The first derivative provides a direct estimate of
the slope at xi
f ( xi , yi )
where f(xi,yi) is the differential equation evaluated
at xi and yi. This estimate can be substituted into
the equation:
13
dy
2 x3 12 x 2 20 x 8.5
dx
14
ERROR ANALYSIS OF THE RK METHOD
Numerical solutions of ODEs involves two types of error:
i) Truncation/discretisation errors
Caused by the nature of the techniques employed to approximate the value of y.
15
ERROR ANALYSIS OF THE RK METHOD
Truncation errors:
i) Local truncation error that results from an application of the method in question
over single step.
ii) Propagated truncation error that results from the approximation produced
during the previous steps.
16
ERROR ANALYSIS OF THE EULER’S METHOD (CONT.)
17
ERROR ANALYSIS OF THE RK METHOD (CONT.)
Conclusions:
i) The global error can be reduced by decreasing h.
ii) The method will provide error-free predictions if the underlying function is
linear.
18
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
19
Heun’s Method
20
DERIVATION OF HEUN’S METHOD
𝑓 𝑥 ,𝑦 + 𝑓(𝑥 ,𝑦 )
𝑦 =𝑦 + ℎ
2
Corrector equation
22
PREDICTOR-CORRECTOR
APPROACH
Predictor : yi01 yi f ( xi , yi )h
f ( xi , yi ) f ( xi 1 , yi01 )
Corrector : yi 1 yi h
2
23
Predictor
Corrector
24
HEUN’S METHOD
• Since the corrector equation has yi+1 on both LHS & RHS, it can be applied
in iterative fashion (repeatedly) in order to get an improved estimation of
yi+1.
• A termination criterion of a Heun’s method iterative process:
25
.
𝑦 = 4𝑒 − 0.5𝑦
26
27
THE MID-POINT METHOD
29
THE MID-POINT METHOD
30
EXAMPLE 3
Solve the following ODE problem using midpoint method over the
interval from x = 0 to x = 2 with a step size of 0.5. The initial condition
at x = 0 is y = 1.
dy
yx 2 1.2 y
dx
31
.
𝑦 = 4𝑒 − 0.5𝑦
32
SUMMARY OF IMPROVED EULER’S METHODS
• Required more computational effort to determine the slope.
• Improved accuracy by reducing errors.
33