You are on page 1of 16

CHEMICAL ENGINEERING

COMPUTATION
KKKK3522

Jarinah Mohd Ali, PhD


Jabatan Kejuruteraan Kimia & Proses
Fakulti Kejuruteraan dan Alam Bina
Universiti Kebangsaan Malaysia

jarinah@ukm.edu.my
INITIAL VALUE PROBLEM
OBJECTIVES
1) Knowing how to implement the Runge-Kutta (RK)
methods for a single ODE:
• Euler
• Heun
• Fourth-Order RK
2) Knowing how to implement the Runge-Kutta
methods for systems of ODEs:
• Euler
• Fourth-order RK

28/11/2019 KKKK3522 Chemical Engineering Computation 2


ORDINARY DIFFERENTIAL EQUATION (ODE)
• Equation/function that involves only one
independent variable

• General form of ordinary differential equation (ODE)


!"
= %(#, ")
!#
• The methods are a one-step methods with general
format:
")*+ = ") + ∅ℎ

• ∅ is the increment function used to extrapolate from


") (old value) to ")*+ (new value)
28/11/2019 KKKK3522 Chemical Engineering Computation 3
EULER METHOD

Slope = #(%& , (& )


• Known also as a point-slope
method
• Slope = ∅ = #(%& , (& )
• General equation (&*+ = (& + ∅ℎ

(&*+ = (& + #(%& , (& )ℎ

• New value of is predicted using the


slope
%& %&*+ %

28/11/2019 KKKK3522 Chemical Engineering Computation 4


EULER METHOD
Step 1:
Find the first derivative of a given function ! = −0.5' ( + 4' + −
10' - + 8.5' + 1
/!
= −2' + + 12' - − 20' + 8.5
/'
IF FUNCTION
Step 2: IS NOT
Identify the information to solve the problem: GIVEN??

1. Interval (1 = 2 to 1 = 3)
2. Step size of h= 2. 4.
3. Initial condition of (1 = 2 , 6 = 7)

28/11/2019 KKKK3522 Chemical Engineering Computation 5


EULER METHOD
Step 3:
Substitute in the equation

!"#$ = !" + '()" , !" )ℎ

Step 4:
Find the error, -. and percentage of error, /.

Note: Error can be calculated using Taylor series estimate


01 (23 ,43 ) 5 011 (23 ,43 ) 7 0(8) (23 ,43 ) 9
-. = 5!
ℎ + 7! ℎ + 9!

Step 5:
Repeat the calculation with new step size until obtain the solution
or within the interval
28/11/2019 KKKK3522 Chemical Engineering Computation 6
EULER METHOD (EXCEL)
substitute to substitute to !t
equation formula
x ytrue f(xi,yi) f(xi,yi)*h yeuler Et Et(%)
i 0.0000 1.0000 8.5000 4.2500 1.0000 0.00 0.00
+1 0.5000 3.2188 1.2500 0.6250 5.2500 -2.03 -63.11
1.0000 3.0000 -1.5000 -0.7500 5.8750 -2.88 -95.83
1.5000 2.2188 -1.2500 -0.6250 5.1250 -2.91 -130.99
2.0000 2.0000 0.5000 0.2500 4.5000 -2.50 -125.00
2.5000 2.7188 2.2500 1.1250 4.7500 -2.03 -74.71
3.0000 4.0000 2.5000 1.2500 5.8750 -1.88 -46.88
3.5000 4.7188 -0.2500 -0.1250 7.1250 -2.41 -50.99
4.0000 3.0000 -7.5000 -3.7500 7.0000 -4.00 -133.33

TRY THIS IN EXCEL

28/11/2019 KKKK3522 Chemical Engineering Computation 7


EULER METHOD (MATLAB)
%% Euler simple method
close all
clear all
clc
% f(x) = -0.5x^4+4x^3-10x^2+8.5x+1; need to find the derivative

f= @(x) (-0.5*x.^4)+(4*x.^3)-(10*x.^2)+(8.5*x)+1;
df = @(x) (-2*x.^3)+(12*x.^2)-(20*x)+8.5;

xint = 0; xend = 4; %Interval


h =0.5; %step size
yint = 1; %Initial condition x=0, y=1

x = (xint:h:xend)';
ytrue = f(x);
sh = df(x)*h; % f(xi,yi)h (slope*h)
yeuler = yint;

for i= 2:xend*2
yeuler(i) =sh(i-1)+ yeuler(i-1);
end

28/11/2019 KKKK3522 Chemical Engineering Computation 8


ASSIGNMENT EULER METHOD

!"#
Given the differential equation of !$
= 2 − 6)* . Find the

concentration,)* (mol⁄01) after 3 min with a step size of ℎ = 1.


Initial condition 6 = 0, )* = 0.5 using Euler Method.

Submit by 06/12/2019

28/11/2019 KKKK3522 Chemical Engineering Computation 9


HUEN METHOD
,
Slope =
# $% ,'% (#($%*+,'%*+
.
)
• Predictor-corrector approach
,
# $% ,'% (#($%*+ ,'%*+ )
• Slope = ∅ =
.
• Predictor equation
2
/0(1 = /0 + 4(50 , /0 )ℎ

• Corrector equation
50 50(1 5 2
4 50 , /0 + 4(50(1 , /0(1 )
/0(1 = /0 + ℎ
2

28/11/2019 KKKK3522 Chemical Engineering Computation 10


HUEN METHOD (EXCEL)
Use Heun method to integrate ! " = 4% &.() − 0.5!
from - = 0 to - = 4 with ℎ = 1. Initial condition -& = 0, !& = 2
similar to yeuler
y0^1 Use formula Use formula !a
Slope predictor Predicted slope corrector
x f(xi,yi) ypredictor inbetween Avg ycorrector Ea Ea(%)
i 0.0000 3.0000 2.0000 2.0000
+1 1.0000 6.4022 5.0000 4.7011 6.7011
2.0000 14.1110 11.4022 5.5516 4.2758 6.2758 0.07 6.78
3.0000 31.3361 25.5132 5.7643 4.3821 6.3821 0.02 1.67
4.0000 69.7055 56.8493 5.7111 4.3555 6.3555 0.00 0.42

TRY THIS IN EXCEL

28/11/2019 KKKK3522 Chemical Engineering Computation 11


RUNGE-KUTTA
1) Runge-Kutta (RK) method achieves the accuracy of a Taylor series
without requiring the calculation of higher derivatives.
2) The increment function, ∅ is represented by:

∅ = #$ %$ + #' %' + … + #) %) where #* + are constant and % * +

%$ = ,(./ , 1/ )
%' = ,(./ + 3$ ℎ, 1/ + 5$$ %$ ℎ)
%6 = ,(./ + 3' ℎ, 1/ + 5'$ %$ ℎ + 5'' %' ℎ)

%) = ,(./ + 3)8$ ℎ, 1/ + 5)8$,$ %$ ℎ + 5)8$,' %' ℎ + ⋯ + 5)8$,)8$ %)8$ ℎ)

28/11/2019 KKKK3522 Chemical Engineering Computation 12


4TH ORDER RUNGE-KUTTA
1
!"#$ = !" + )$ + 2)+ + 2), + )- ℎ
6

Where:

)$ = /(1" , !" )
1 1
)+ = /(1" + ℎ, !" + )$ℎ)
2 2
1 1
), = /(1" + ℎ, !" + )+ℎ)
2 2
)- = /(1" + ℎ, !" + ),ℎ) 1" 1"#$/+ 1"#$

28/11/2019 KKKK3522 Chemical Engineering Computation 13


4TH ORDER RUNGE-KUTTA

Slope
x f(xi,yi) k ymid y(intervalend)
i 0.0000 3.0000 k1 3.0000 0.5000 4.2010 6.20
i+1 1.0000 k2 4.2173 3.5000
k3 3.9130 4.1086
k4 5.9457 5.9130

Homework Example 22.5 Page 574 including MATLAB

28/11/2019 KKKK3522 Chemical Engineering Computation 14


SYSTEM EQUATIONS
• For solving system equations, initial condition is required,
starting value of !
• Single-equation methods can be used to solve systems of
ODE’s
• Apply the one-step method is applied for every equation at
each step before proceeding to the next step. (Example
Euler Method)
• If use Fourth-order Runge-Kutta method care must be taken
in calculating the k’s.

28/11/2019 KKKK3522 Chemical Engineering Computation 15

You might also like