0% found this document useful (0 votes)
7 views3 pages

Chemical Engineering Computing Kyambogo University Lecture 9

The document outlines a lecture on solving chemical engineering problems using MATLAB, specifically focusing on the 'fsolve' function for nonlinear equations related to material and energy balances in a Continuous Stirred Tank Reactor (CSTR). It provides an example of deriving rate equations for various reactions and demonstrates how to implement these equations in MATLAB to determine final concentrations. Additionally, it includes an assignment related to the CSTR, requiring students to calculate reactant concentrations at the end of a reaction.

Uploaded by

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

Chemical Engineering Computing Kyambogo University Lecture 9

The document outlines a lecture on solving chemical engineering problems using MATLAB, specifically focusing on the 'fsolve' function for nonlinear equations related to material and energy balances in a Continuous Stirred Tank Reactor (CSTR). It provides an example of deriving rate equations for various reactions and demonstrates how to implement these equations in MATLAB to determine final concentrations. Additionally, it includes an assignment related to the CSTR, requiring students to calculate reactant concentrations at the end of a reaction.

Uploaded by

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

KYAMBOGO UNIVERSITY

FACULTY OF ENGINEERING
DEPARTMENT OF MINING, CHEMICAL & PETROLEUM ENGINEERING
BACHELOR OF SCIENCE IN CHEMICAL ENGINEERING
Course Code and Name: SCE 2202 COMPUTING FOR CHEMICAL ENGINEERING II
Course Level: YR II, SEM II (2023/2024)
Course Credit: 3 CU
Lecturer: Dr. Dan Egesa
Assisting Lecturer: Joshua Ocoun (Eng.)

SCE 2202 Lecture 09 (22nd March 2024)


SOLVING CHEMICAL ENGINEERING PROBLEMS IN MATLAB
Use of ‘fsolve’ in Nonlinear Equation Problems
Material and Energy balances involving Chemical and Biochemical / Bio molecular
Engineering, mostly involve development of non-linear equations. ‘fsolve’,
in Matlab can help us to solve such problems.

Below is a typical Example;


Consider a Continuous Stirred Tank reactor (CSTR) below:
Q = Volumetric Flow rate, (L/s),
V = Reactor Volume (L),
C (A, B, C, D) = The Concentration of each of the
components in the reactor. (gmole/L),
The reactor operates according to the Equations;
𝑟1
𝐴 → 2𝐵 … 𝑒𝑞𝑛(𝑖)
𝑟2 𝑟3
𝐴 → 𝐶 ← 𝐴 … 𝑒𝑞𝑛(𝑖𝑖)
𝑟4
𝐵 → 𝐶 + 𝐷 … 𝑒𝑞𝑛(𝑖𝑖𝑖)
r(1, 2, 3, 4) represents the rate equations, in each reaction

From this information only we can derive the rate equations for each reaction as, and
assuming the rate constants (k) are already tabulated and known for each, we then

Dr. Dan Egesa (all assignments should to be submitted in time)


Joshua Ocoun (Eng.) 2023/2024Adc Yr.
proceed and do a mass balance.
For such a reactions; the rate equations are derived as below; and more of this can
will be learnt in Reaction Engineering. 𝑟1,2,3,4 = 𝑔𝑚𝑜𝑙 ⁄𝐿 − 𝑠
3⁄
𝑟1 = 𝑘1 𝐶𝐴 , 𝑟2 = 𝑘2 𝐶𝐴 2 , 𝑟3 = 𝑘3 𝐶𝐶2 , 𝑟4 = 𝑘4 𝐶𝐵2
Assuming;
−1
0.25𝐿1⁄2 0.1𝐿 0.5𝐿
𝑘1 = 1.15𝑠 , 𝑘2 = , 𝑘 3 = , 𝑘 4 =
𝑔𝑚𝑜𝑙1⁄2 − 𝑠 𝑔𝑚𝑜𝑙 − 𝑠 𝑔𝑚𝑜𝑙 − 𝑠
500𝐿
𝐹𝑙𝑜𝑤𝑟𝑎𝑡𝑒 𝑄 = , 𝐶𝑆𝑇𝑅 𝑉𝑜𝑙𝑢𝑚𝑒 𝑉 = 1000𝐿
𝑠
We can then, proceed and do a mass balance as below;
𝑉 𝑉 𝑉
𝐶𝐴 = 𝐶𝐴𝑜 + (−𝑟1 ) + (−𝑟2 ) + (𝑟3 ) … 𝑒𝑞𝑛(1)
𝑄 𝑄 𝑄
𝑉 𝑄
𝐶𝐵 = 𝐶𝐵𝑜 + × 2𝑟1 − × 𝑟4 … 𝑒𝑞𝑛(2)
𝑄 𝑉
𝑉 𝑉 𝑉
𝐶𝐶 = 𝐶𝐶𝑜 + 𝑟2 − 𝑟3 + 𝑟4 … 𝑒𝑞𝑛(3)
𝑄 𝑄 𝑄
𝑉
𝐶𝐷 = 𝐶𝐷𝑜 + 𝑟4 … 𝑒𝑞𝑛(4)
𝑄
We substitute in the expressions of r1, 2, 3, 4 ;
𝑉 ⁄
𝐶𝐴 = 𝐶𝐴𝑜 + (−𝑘1 𝐶𝐴 − 𝑘2 𝐶𝐴3 2 + 𝑘3 𝐶𝐶2 ) … 𝑒𝑞𝑛(1)
𝑄
𝑉
𝐶𝐵 = 𝐶𝐵𝑜 + (2𝑘1 𝐶𝐴 − 𝑘4 𝐶𝐵2 ) … 𝑒𝑞𝑛(2)
𝑄
𝑉 ⁄
𝐶𝐶 = 𝐶𝐶𝑜 + (𝑘2 𝐶𝐴3 2 − 𝑘3 𝐶𝑐2 + 𝑘4 𝐶𝐵2 ) … 𝑒𝑞𝑛(3)
𝑄
𝑉
𝐶𝐷 = 𝐶𝐷𝑜 + (𝑘4 𝐶𝐵2 ) … 𝑒𝑞𝑛(3)
𝑄
These are the equations we write in MATLAB. As below.
x = fsolve(func, x0)
Where;
x = a vector of unknowns
func = a function m-file that evaluates the right-hand side of f(x) = 0
x(0) = a vector of initial guesses of x

Dr. Dan Egesa (all assignments should to be submitted in time)


Joshua Ocoun (Eng.) 2023/2024Adc Yr.
We can write an m-file as below and proceed to solve.
function f = CSTR ( C )
f(1),(2),(3),(4) represent eqn (1),(2),(3),(4) summated to
k1 = 1.15; 𝑉
zero. e.g (𝑓(1) = −𝐶𝐴 + 𝐶𝐴𝑜 + 𝑄 (−𝑟1 − 𝑟2 + 𝑟3 ) = 0)
k2 = 0.25;
k3 = 0.1;
C(1),(2),(3),(4) represent CA, B, C, D respectively
k4 = 0.5;
Q = 500;
CInit represents the initial concentrations of each of the
V = 1000; components in the reactor
CInit = [1; 0; 0; 0];
f(1) = -C(1)+CInit(1)+ V*(-k1*C(1) - k2*C(1)^1.5 + k3*C(3)^2)/Q;
f(2) = -C(2)+CInit(2)+ V*(2*k1*C(1) - k4*C(2)^2)/Q;
f(3) = -C(3)+CInit(3)+ V*(k2*C(1)^1.5 – k3*C(3)^2 +k4*C(2)^2)/Q;
f(4) = -C(4)+CIntit(4)+ V*(k4*C(2)^2)/Q;
end

We now go to the Command Window and use ‘fsolve’ to calculate


At first we can put in an initial guess, of the concentration. With the initial guess
Matlab will then solve the problem Numerically.
>> C0 = [0.5; 0.5; 0.5; 0.5]; (Initial guess)
>> C = fsolve(CSTR, C0)

In this particular case we are determining the final concentration of each of the
reactant at the end of the reaction.
NOTE: The same problem can be solved using ‘ode45’ and a time versus
concentration graph is plotted. This describes the concentration of each reactant as
time increases. [Check lecture 8].

Individual Assignment 12 :( Deadline 2nd April 2024)


Assuming the Example in Lecture 8 was a CSTR, (Continuous flow stirred tank
reactor) with a Capacity of 500L and a 2.5kW Centrifugal pump feeds in 200L every
30min, determine the final concentrations of each of the reactants and the end of the
reaction.
End**

Dr. Dan Egesa (all assignments should to be submitted in time)


Joshua Ocoun (Eng.) 2023/2024Adc Yr.

You might also like