SlideShare a Scribd company logo
Solution of Nonlinear
Equations
Chapter 2
02Solution of Nonlinear Equations
 Finding the solution to a nonlinear equation or a
system of nonlinear equations is a common
problem arising from the analysis and design of
chemical processes in steady state.
 the relevant MATLAB commands used to deal
with this kind of problem are introduced.
 the solution-finding procedure through using the
Simulink simulation interface will also be
demonstrated.
2
02Solution of Nonlinear Equations
2.1 Relevant MATLAB commands and the
Simulink solution interface
 2.1.1 Nonlinear equation of a single variable
3
 For example, one intends to obtain the volume of 1 g-
mol propane gas at P = 10 atm and T = 225.46 K
from the following Van der Waals P-V-T equation:
02Solution of Nonlinear Equations
2.1.1 Nonlinear equation of a single variable
• where a = 8.664 atm (L/g-mol), b = 0.08446 L/g-mol, and the
ideal gas constant R is 0.08206 atmL/g-molK.
x = fzero(‘filename’, x0)
4
02Solution of Nonlinear Equations
2.1.1 Nonlinear equation of a single variable
──────────────── PVT.m ────────────────
function f=PVT(V)
%
% Finding the solution to the Van der Waals equation (2.1-2)
%
% given data
%
a=8.664; % constant, atm (L/g-mol)^2
b=0.08446; % constant, L/g-mol
R=0.08206; % ideal gas constant, atm-L/g-mol‧K
P=10; % pressure, atm
T=225.46; % temperature, K
%
% P-V-T equation
%
f= (P+a/V^2)*(V-b)-R*T;
────────────────────────────────────
5
02Solution of Nonlinear Equations
>> V=fzero('PVT', 1) % the initial guess value is set to 1
V =
1.3204
>> V=fzero ('PVT', 0.1) % use 0.1 as the initial guess value
V =
0.1099
6
02Solution of Nonlinear Equations
>> P=10;
>> T=225.46;
>> R=0.08206;
>> V0=R*T/P; % determine a proper initial guess value by the
ideal gas law
>> V=fzero('PVT', V0) % solving with V0 as the initial guess
value
V=
1.3204
7
02Solution of Nonlinear Equations
>> options= optimset('disp', 'iter'); % display the iteration process
>> V=fzero('PVT', V0, options)
Search for an interval around 1.8501 containing a sign change:
Func-count a f(a) b f(b) Procedure
1 1.85012 3.62455 1.85012 3.62455 initial interval
3 1.7978 3.22494 1.90245 4.03063 search
5 1.77612 3.06143 1.92413 4.20061 search
7 1.74547 2.83234 1.95478 4.44269 search
9 1.70211 2.51286 1.99813 4.78826 search
11 1.64081 2.07075 2.05944 5.28301 search
13 1.5541 1.46714 2.14614 5.99373 search
15 1.43149 0.66438 2.26876 7.01842 search
16 1.25808 -0.340669 2.26876 7.01842 search
8
02Solution of Nonlinear Equations
Search for a zero in the interval [1.2581, 2.2688]:
Func-count X f(x) Procedure
16 1.25808 0.340669 initial
17 1.30487 0.0871675 interpolation
18 1.32076 0.00213117 interpolation
19 1.32038 1.80819e-005 interpolation
20 1.32039 3.64813e-009 interpolation
21 1.32039 0 interpolation
Zero found in the interval [1.25808, 2.26876]
V=
1.3204
9
02Solution of Nonlinear Equations
Solution by Simulink:
Step 1: start Simulink
10
02Solution of Nonlinear Equations
Solution by Simulink:
Step 2:
11
02Solution of Nonlinear Equations
Solution by Simulink:
Step 3: Edit Fcn
(10+8.664/u (1)^2)*(u (1)-0.08446)-0.08206*225.46
12
02Solution of Nonlinear Equations
Solution by Simulink:
Step 4: solution display
13
02Solution of Nonlinear Equations
Solution by Simulink:
Step 5: Key in the initial guess value
14
02Solution of Nonlinear Equations
Solution by Simulink:
Step 6: Click
building a dialogue box
15
02Solution of Nonlinear Equations
Solution by Simulink:
Step 1-2:
Step 3: Edit Fcn using variable names, P, R, T, a, and b
(P + a/ u (1) ^2)*(u (1)b) R*T
16
02Solution of Nonlinear Equations
Solution by Simulink:
Step 4-5:
17
02Solution of Nonlinear Equations
Solution by Simulink:
Step 6:
18
02Solution of Nonlinear Equations
Solution by Simulink:
Step 6:
19
02Solution of Nonlinear Equations
Solution by Simulink:
Step 7: Mask Subsystem
20
02Solution of Nonlinear Equations
Solution by Simulink:
Step 8: key in the parameter values
21
02Solution of Nonlinear Equations
Solution by Simulink:
Step 9: Execute the program
22
02Solution of Nonlinear Equations
2.1.2 Solution of a system of nonlinear equations
23
02Solution of Nonlinear Equations
• CSTR
24
• The kinetic parameters are as follows: B = 8, Da = 0.072,  =
20, and  = 0.3.
x=fsolve(‘filename’, x0)
02Solution of Nonlinear Equations
Step 1: Provide the function
──────────────── cstr.m ────────────────
function f=fun(x)
%
% steady-state equation system (2.1-6) of the CSTR
%
% kinetic parameters
%
B=8;
Da=0.072;
phi=20;
beta=0.3;
%
% nonlinear equations in vector form
%
f= [-x(1)+Da*(1-x(1))*exp(x(2)/(1+x(2)/phi))
-(1+beta)*x(2)+B*Da*(1-x(1))*exp(x(2)/(1+x(2)/phi))];
─────────────────────────────────────────────────
25
02Solution of Nonlinear Equations
Step 2:
>> x=fsolve('cstr', [0.1 1]) % solve the equations with the initial guess [0.1 1]
x=
0.1440 0.8860
>> ezplot('-x1+0.072*(1-x1)*exp(x2/(1+x2/20))', [0, 1, 0, 8]) % plotting (2.1-6a)
>> hold on
>> ezplot('-(1+0.3)*x2+8*0.072*(1-x1)*exp(x2/(1+x2/20))', [0, 1, 0, 8]) % plotting
(2.1-6b)
>> hold off
26
02Solution of Nonlinear Equations
27
02Solution of Nonlinear Equations
• (0.15, 1), (0.45, 3), and (0.75, 5)
>> x_1=fsolve('cstr', [0.15 1]) % the first solution
x_1=
0.1440 0.8860
>> x_2=fsolve('cstr', [0.45 3]) % the second solution
x_2=
0.4472 2.7517
>> x_3=fsolve('cstr', [0.75 5]) % the third solution
x_3=
0.7646 4.7050
28
02Solution of Nonlinear Equations
Solution by Simulink:
Step 1:
29
02Solution of Nonlinear Equations
Solution by Simulink:
Step 2:
In Fcn: -u(1)+Da*(1-u(1))*exp(u(2)/(1+u(2)/phi))
In Fcn 1: - (1+beta)*u(2)+B*Da*(1-u(1))*exp(u(2)/(1+u(2)/phi))
30
02Solution of Nonlinear Equations
Solution by Simulink:
Step 2:
31
02Solution of Nonlinear Equations
Solution by Simulink:
Step 3:
32
02Solution of Nonlinear Equations
Solution by Simulink:
Step 4: Create a Subsystem for
33
02Solution of Nonlinear Equations
Solution by Simulink:
Step 5: Create a dialogue box
34
02Solution of Nonlinear Equations
Solution by Simulink:
Step 6: Input system parameters and initial guess values
35
02Solution of Nonlinear Equations
Solution by Simulink:
Step 7:
36
02Solution of Nonlinear Equations
2.2 Chemical engineering examples
Example 2-2-1
Boiling point of an ideal solution
Consider a three-component ideal mixture of which the vapor
pressure of each component can be expressed by the following
Antoine equation:
where T represents the temperature of the solution (C) and Pi
0
denotes the saturated vapor pressure (mmHg). The Antoine
coefficients of each component are shown in the following table
(Leu, 1985):
37
02Solution of Nonlinear Equations
Example 2-2-1
Component Ai Bi Ci
1 6.70565 1,211.033 220.790
2 6.95464 1,344.800 219.482
3 7.89750 1,474.080 229.130
38
Determine the boiling point at one atmospheric pressure for
each of the following composition conditions:
Condition x1 x2 x3
1 0.26 0.38 0.36
2 0.36 0.19 0.45
02Solution of Nonlinear Equations
Problem formulation and analysis:
Raoult’s law:
39
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_1.m ───────────────
%
% Example 2-2-1 boiling point of an ideal solution
%
% main program: ex2_2_1.m
% subroutine (function file): ex2_2_1f.m
%
clear
clc
%
global A B C X_M
%
% given data
%
A= [6.70565 6.95464 7.89750]; % coefficient A
B= [-1211.033 -1344.800 -1474.080]; % coefficient B
C= [220.790 219.482 229.130]; % coefficient C
%
40
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_1.m ───────────────
X= [0.25 0.40 0.35
0.35 0.20 0.45]; % component concentrations for each case
%
[m, n]=size(X); % n: the number of components
% m: the number of conditions
%
for i=1: m
X_M=X(i, :);
T(i) =fzero('ex2_2_1f', 0);
end
%
% results printing
%
for i=1: m
fprintf('condition %d, X(l)=%.3f, X(2)=%.3f, X(3)=%.3f, boiling point=…
%.3f ℃n',i,X(i,1),X(i,2),X(i,3),T(i))
end
─────────────────────────────────────────────────
41
02Solution of Nonlinear Equations
MATLAB program design:
──────────────── ex2_2_1f.m ────────────────
%
% example 2-2-1 boiling point of an ideal solution
% subroutine (function file): ex2_2_1f.m
%
function f= ex2_2_1f(T)
global A B C X_M
Pi=10.^(A+B./(C+T)); % saturated vapor pressure of each component
p=sum(X_M.*Pi); % total pressure
f=p-760;
end
─────────────────────────────────────────────────
42
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_1
condition 1, X(l)=0.250, X(2)=0.400, X(3)=0.350, boiling
point=82.103C
condition 2, X(l)=0.350, X(2)=0.200, X(3)=0.450, boiling
point=77.425C
43
02Solution of Nonlinear Equations
Example 2-2-2
Equilibrium concentrations in a reaction system
3H2 + CO ⇌ CH4 + H2O, 𝐾1 = 69.18
CO + H2O ⇌ CO2 + H2, 𝐾2 = 4.68
CO2 + C(𝑠) ⇌ 2CO, 𝐾3 = 5.60 × 10−3
5H2 + 2CO ⇌ C2H6 + 2H2O, 𝐾4 = 0.14
where Ki is the equilibrium constant under the operating
condition of 500C and 1 atmospheric pressure. Assume that 1
mole of CO and 3 moles of H2 exist initially in the system,
determine the equilibrium concentration of each component
(mole fraction) when the reaction system reaches an equilibrium.
44
02Solution of Nonlinear Equations
Analysis of the question:
Let y1, y2, …, and y6 stand for the mole fractions of H2, CO, CH4,
H2O, CO2, and C2H6, respectively. Besides, let x1, x2, x3, and x4
be the reaction rates of individual equations in (2.2-5a-d).
45
02Solution of Nonlinear Equations
Analysis of the question:
46
D = 4  2x1 + x3  4x4
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_2.m ───────────────
function ex2_2_2 % notice the format of the first line
%
% Example 2-2-2 Equilibrium concentrations in a reaction system
%
clear
clc
%
% initial guess values
%
x0= [0.7 0 -0.1 0];
%
% solving by calling the embedded function file ex2_2_2f
%
options= optimset('disp', 'iter');
x=fsolve(@ex2_2_2f, x0, options); % notice the use of the function handle @
%
% calculate the mole fraction
%
47
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_2.m ───────────────
y=ex2_2_2y(x);
%
% results printing
%
disp(' ')
disp('reaction rate of each equation')
%
for i=1:4
fprintf('x(%d) =%.3e n', i, x (i))
end
%
disp(' ')
disp('mole fraction of each component')
%
for i=1:6
fprintf('y(%i) =%.3e n', i, y (i))
end
48
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_2.m ───────────────
%
% chemical equilibrium equations
%
function f=ex2_2_2f(x)
%
y= ex2_2_2y(x);
%
% the set of nonlinear equations
%
f= [y(3)*y(4)/(y (1)^3*y(2))-69.18
y(5)*y(1)/(y(2)*y(4))-4.68
y(2)^2/y(5)-5.60e-3
y(6)*y(4)^2/(y(1)^5*y(2)^2)-0.14];
%
% the subroutine for calculating the mole fraction
%
function y=ex2_2_2y(x)
49
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_2.m ───────────────
% chemical equilibrium equations
%
function f=ex2_2_2f(x)
%
y= ex2_2_2y(x);
%
% the set of nonlinear equations
%
f= [y(3)*y(4)/(y (1)^3*y(2))-69.18
y(5)*y(1)/(y(2)*y(4))-4.68
y(2)^2/y(5)-5.60e-3
y(6)*y(4)^2/(y(1)^5*y(2)^2)-0.14];
%
% the subroutine for calculating the mole fraction
%
function y=ex2_2_2y(x)
D=4-2*x(1) +x(3)-4*x(4);
50
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_2.m ───────────────
if D == 0
disp('D is zero')
return
end
y(1)=(3-3*x(1) +x(2)-5*x(4))/D;
y(2)=(1-x(1)-x(2) +2*x(3)-2*x(4))/D;
y(3)=x(1)/D;
y(4)=(x(1)-x(2) +2*x(4))/D;
y(5)=(x(2)-x(3))/D;
y(6)=x(4)/D;
─────────────────────────────────────────────────
51
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_2
reaction rate of each equation
x (1) =6.816e-001
x (2) =1.590e-002
x (3) =-1.287e-001
x (4) =1.400e-005
52
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_2
mole fraction of each component
y(1) =3.872e-001
y(2) =1.797e-002
y(3) =2.718e-001
y(4) =2.654e-001
y(5) =5.765e-002
y(6) =5.580e-006
53
02Solution of Nonlinear Equations
Example 2-2-3
Analysis of a pipeline network
Figure 2.1 systematically illustrates a pipeline network installed
on a horizontal ground surface. In the network, raw materials are
fed to eight locations denoted as P1, P2, … , P7, and P8, and the
flow rate (m3/min) required at each of the eight locations is listed
as follows (Leu, 1985):
P1Q = 3.0, P2Q = 2.0, P3Q = 5.0, P4Q = 3.0
P5Q = 2.0, P6Q = 2.0, P7Q = 5.0, P8Q = 2.0
54
02Solution of Nonlinear Equations
55
Due to flow frictions, the head loss h(m) for each 1/2 side of
the pipeline (such as P1 to P5) is given by
Note that the head loss is a function of the flow rate Q
(m3/min) in the pipeline. Based on the required flow rates
PiQ determine the corresponding flow rates, Q1 to Q9, in the
pipeline and the head at each of the eight locations.
02Solution of Nonlinear Equations
56
Figure 2.1 Schematic diagram of the pipeline network.
02Solution of Nonlinear Equations
Problem formulation and analysis:
mass balance
Mass balance at P2: Q3 = Q5 + P2Q
Mass balance at P3: Q7 + Q9 = P3Q
Mass balance at P1: Q1 = Q8 + P4Q
Mass balance at P5: Q2 = Q3 + Q4 + P5Q
Mass balance at P6: Q5 = Q7 + P6Q
Mass balance at P7: Q6 + Q8 = Q9 + P7Q
Mass balance at P8: Q4 = Q6 + P8Q
57
02Solution of Nonlinear Equations
Problem formulation and analysis:
Head loss balance by considering hP1P5
+hP5P8
+hP8P7
+hP1P4
+hP4P7
:
58
Head loss balance by considering
hP5P2
+hP2P6
+hP6P6
=hP5P8
+hP8P7
+hP7P3
:
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
function ex2_2_3
%
% Example 2-2-3 pipeline network analysis
%
clear
clc
%
global PQ % declared as a global parameter
%
PQ=[3 2 5 3 2 2 5 2]; % flow rate required at each location
%
Q0=2*ones(1, 9); % initial guess value
%
% solving
%
Q=fsolve(@ex2_2_3f, Q0,1.e-6); % setting the solution accuracy as 1.e-6
%
59
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
h(3)=10;
h(6)=h(3)+0.5*abs(Q(7))^0.85*Q(7);
h(2)=h(6)+0.5*abs(Q(5))^0.85*Q(5);
h(7)=h(3)+0.5*abs(Q(9))^0.85*Q(9);
h(8)=h(7)+0.5*abs(Q(6))^0.85*Q(6);
h(5)=h(2)+0.5*abs(Q(3))^0.85*Q(3);
h(4)=h(7)+0.5*abs(Q(8))^0.85*Q(8);
h(1)=h(5)+0.5*abs(Q(2))^0.85*Q(2);
%
% results printing
%
disp(' ')
disp('flow at each location (m^3/min)')
for i=1:9
fprintf('Q(%i)=%7.3f n',i,Q(i))
end
disp(' ')
disp('head at each location (m)')
60
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
for i=1:8
fprintf('h(%i)=%7.3f n',i,h(i))
end
%
% nonlinear simultaneous equations
%
function f=ex2_2_3f(Q)
%
global PQ
%
f=[Q(3)-Q(5)-PQ(2)
Q(7)+Q(9)-PQ(3)
Q(1 )-Q(8)-PQ(4)
Q(2)-Q(3)-Q(4)-PQ(5)
Q(5)-Q(7)-PQ(6)
Q(6)+Q(8)-Q(9)-PQ(7)
Q(4)-Q(6)-PQ(8)
61
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
0.5*abs(Q(2))^0.85*Q(2)+0.5*abs(Q(4))^0.85*Q(4)+0.5*abs(Q(6))^0.85*Q(6)-...
abs(Q(1))^0.85*Q(1)-0.5*abs(Q(8))^0.85*Q(8)
0.5*abs(Q(3))^0.85*Q(3)+0.5*abs(Q(5))^0.85*Q(5)+0.5*abs(Q(7))^0.85*Q(7)-...
0.5*abs(Q(4))^0.85*Q(4)-0.5*abs(Q(6))^0.85*Q(6)-0.5*abs(Q(9))^0.85*Q(9)];
─────────────────────────────────────────────────
62
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_3
flow at each location (m^3/min)
Q(1)= 8.599
Q(2)= 12.401
Q(3)= 5.517
Q(4)= 4.884
Q(5)= 3.517
Q(6)= 2.884
Q(7)= 1.517
Q(8)= 5.599
Q(9)= 3.483
63
head at each location (m)
h(1)= 80.685
h(2)= 16.202
h(3)= 10.000
h(4)= 27.137
h(5)= 27.980
h(6)= 11.081
h(7)= 15.031
h(8)= 18.578
02Solution of Nonlinear Equations
Example 2-2-4
A material drying process through heat conduction and
forced convection
Figure 2.2 schematically depicts a drying process (Leu, 1985),
where a wet material with thickness of 6 cm is placed on a hot
plate maintained at 100C.
64
Figure 2.2 A material drying process through heat conduction and forced convection.
02Solution of Nonlinear Equations
To dry the material, the hot wind with a temperature of 85C and
partial vapor pressure of 40 mmHg is blowing over the wet
material at a flow rate of 3.5 m/s. The relevant operation
conditions and assumptions are stated as follows:
(1) During the drying process, the heat conduction coefficient of
the wet material is kept constant, and its value is measured to
be 1.0 kcal/m·hr·C.
(2) The convective heat transfer coefficient h (kcal/m·hr·C)
between the hot wind and the material surface is a function of
mass flow rate of wet air G (kg/hr), which is given by
h = 0.015G 0.8
(3) The saturated vapor pressure Ps (mmHg), which is a function
of temperature ( C), can be expressed by the Antoine
equations as follows:
65
02Solution of Nonlinear Equations
(4) The latent heat of water vaporization rm (kcal/kg) is a
function of temperature T (C), which is given by
rm = 597.65 – 0.575 T
(5) The mass flow rate of wet air G and its mass transfer
coefficient M are measured to be the values of 1.225×104
kg/hr and 95.25 kg/m2·hr, respectively.
Based on the operating conditions mentioned above, determine
the surface temperature of the material Tm and the constant drying
rate Rc, which is defined as
Rc = M(Hm – H)
66
02Solution of Nonlinear Equations
Problem formulation and analysis:
67
h = 0.015G 0.8
rm = 597.65 – 0.575T
Tp = 100 C
L = 0.06 m
k = 1 kcal/m·hr· C
Ta = 85 C
G = 1.225×104 kg/hr
M = 95.25 kg/m2· hr
02Solution of Nonlinear Equations
Problem formulation and analysis:
68
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
function ex2_2_4
%
% Example 2-2-4 A material drying process via heat conduction and forced convection
%
clear
clc
%
global h Ta M k L Tp H
%
G=1.225e4; % mass flow rate of wet air (kg/hr)
M=95.25; % mass transfer coefficient (kg/m^2.hr)
k=1; % heat transfer coefficient of the wet material (kcal/m.hr.℃)
Tp=100; % hot plate temperature (℃)
L=0.06; % material thickness (m)
Ta=85; % hot wind temperature (℃)
P=40; % partial pressure of water vapor (mmHg)
H=18.02*P/(28.97*(760-P)); % humidity of hot air (%)
h=0.015*G^0.8; % heat transfer coefficient (kcal/m^2.hr. ℃)
69
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
%
% solving for Tm
%
Tm=fzero(@ex2_2_4f, 50);
%
Ps=ex2_2_4Ps(Tm); % eq. (2.2-12)
%
% calculating constant drying rate
%
Hm=18.02*Ps/(28.97* (760-Ps)); % eq. (2.2-17)
Rc=M*(Hm-H); % eq. (2.2-14)
%
% results printing
%
fprintf('the surface temperature of the material =%.3f ℃n', Tm)
fprintf('the constant drying rate = %.3f kg/m^2.hrn', Rc)
%
70
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
% nonlinear function
%
function f = ex2_2_4f(Tm)
%
global h Ta M k L Tp H
%
Ps= ex2_2_4Ps(Tm); % eq.(2.2-12)
%
Hm=18.02*Ps/(28.97*(760-Ps)); % eq.(2.2-17)
rm=597.65-0.575*Tm; % eq.(2.2-13)
%
f=h*(Ta-Tm)-M*(Hm-H)*rm-k/L*(Tm-Tp); % eq.(2.2-15)
%
% subroutine for calculating the saturated vapor pressure
%
function Ps=ex2_2_4Ps(Tm)
if Tm < 55
71
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_3.m ───────────────
Ps=10^(7.7423-1554.16/(219+Tm));
elseif Tm >= 55
Ps=10^(7.8097-1572.53/(219+Tm));
end
─────────────────────────────────────────────────
72
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_4
the surface temperature of the material = 46.552C
the constant drying rate = 3.444 kg/m^2.hr
73
02Solution of Nonlinear Equations
Example 2-2-5
A mixture of 50 mol% propane and 50 mol% n-butane is to be
distilled into 90 mol% propane distillate and 90 mol% n-butane
bottoms by a multistage distillation column. The q value of raw
materials is 0.5, and the feeding rate is 100 mol/hr. Suppose the
binary distillation column is operated under the following
operating conditions (McCabe and Smith, 1967):
1) The Murphree vapor efficiency EMV is 0.7;
2) The entrainment effect coefficient ε is 0.2;
3) The reflux ratio is 2.0;
4) The operating pressure in the tower is 220 Psia;
74
02Solution of Nonlinear Equations
5) The equilibrium coefficient (K = y/x), which depends on the
absolute temperature T (R), is given by
ln K = A/T+B+CT
where the coefficients A, B, and C under 220 Psia for propane
and n-butane are listed in the table below.
75
Component A B C
Propane 3,987.933 8.63131 0.00290
n-Butane 4,760.751 8.50187 0.00206
02Solution of Nonlinear Equations
Answers to the following questions:
1) The theoretical number of plates and the position of the
feeding plate.
2) The component compositions in the gas phase and the liquid
phase at each plate.
3) The temperature of the re-boiler and the bubble point at each
plate.
76
02Solution of Nonlinear Equations
Problem formulation and analysis:
(1) Overall mass balance:
77
W = F  D
Name of
variable Physical meaning Name of
variable Physical meaning
D Flow rate of the distillate xD Composition of the distillate
F Flow rate of the feed xw Composition of the bottoms
W Flow rate of the bottoms zF Composition of the feed
02Solution of Nonlinear Equations
Problem formulation and analysis:
(1) Overall mass balance:
78
02Solution of Nonlinear Equations
79
02Solution of Nonlinear Equations
Problem formulation and analysis:
(2) Material balance on the feed plate:
80
q value Condition of the feed
q > 1 The temperature of the feed is lower than the boiling point
q = 1 Saturated liquid
0 < q < 1 Mixture of liquid and vapor
q = 0 Saturated vapor
q < 0 Overheated vapor
02Solution of Nonlinear Equations
Problem formulation and analysis:
(3) Material balance made for the re-boiler
(4) Stripping section
81
02Solution of Nonlinear Equations
Problem formulation and analysis:
(5) Enriching section
𝑥 𝑛+1 =
𝐿𝑦𝑛 + 𝜀𝑉𝑥 𝑛 − 𝐷𝑥 𝐷
𝐿 + 𝜀𝑉
(6) Feed plate
𝑥𝑓+1 =
𝑉′𝑦𝑓 + 𝜀𝑉′𝑥𝑓 + 1 − 𝑞 𝐹𝑦 𝐹 − 𝐷𝑥 𝐷
𝐿 + 𝜀𝑉′
(A) Calculation of the flash point at the feed plate:
82
, i =1, 2
02Solution of Nonlinear Equations
Problem formulation and analysis:
where
Ki = exp (Ai / T + Bi + CiT)
(B) Calculation of the flash point at the feed plate:
83
02Solution of Nonlinear Equations
MATLAB program design:
84
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
function ex2_2_5
%
% Example 2-2-5 analysis of a continuous multi-stage binary distillation
%
clear; close all
clc
%
% declare the global variables
%
global A B C zf q
global A B C xc
%
% operation data
%
zf=[0.5 0.5]; % feed composition
xd=[0.9 0.1]; % distillate composition
xw=[0.1 0.9]; % composition of the bottom product
F=100; % feed flow rate (mol/h)
85
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
q=0.5; % q value of the feed
Emv=0.7; % Murphree vapor efficiency
Ee=0.2; % entrainment coefficient
RD=2; % reflux ratio
%
A=[-3987.933 -4760.751]; % parameter A
B=[8.63131 8.50187]; % parameter B
C=[-0.00290 -0.00206]; % parameter C
%
% calculating all flow rates (D,W,L,V, LS, and VS)
%
D=F*(zf(1)-xw(1))/(xd(1)-xw(1)) ; % distillate flow rate
W=F-D; % flow rate of the bottom product
L=RD*D; % liquid flow rate in the enriching section
V=L+D; % gas flow rate in the enriching section
LS=L+q*F; % liquid flow rate in the stripping section
VS=V-(1-q)*F; % gas flow rate in the stripping section
%
86
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
% calculating the flash point at the feed plate
%
Tf=fzero(@ex2_2_5f1,620); % flash point
K=exp(A/Tf+B+C*Tf);
yf=zf./(1 +q*(1./K-1)); % gas phase composition at the feed plate
xf=yf./K; % liquid phase composition at the feed plate
Tf=Tf-459.6; % converted to ℉
%
% equilibrium in the re-boiler
%
xc=xw;
Tw=fzero(@ex2_2_5f2,620);
Kw=exp(A/Tw+B+C*Tw);
yw=Kw.*xw; % gas phase composition in the re-boiler
Tw=Tw-459.6; % bubble point (℉) of the re-boiler
%
% calculating the liquid phase composition in the re-boiler
87
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
m=1;
x(m,:)=xw;
y(m,:)=yw;
x(m+1,:)=(VS*y(m,:)+W*xw)/LS;
%
% calculating for the stripping section
%
T(m)=Tw;
while T(m)>Tf
m=m+1;
xc=x(m,:);
T (m)=fzero(@ex2_2_5f2,620);
K(m,:)=exp(A/T(m)+B+C*T(m));
ys(m,:)=K(m,:).*x(m,:);
y(m,:)=Emv*(ys(m,:)-y(m-1,:))+y(m-1,:);
x(m+1,:)=(VS*y(m,:)+Ee*VS*x(m,:)+W*x(m-1,:))/(LS+Ee*VS);
T(m)=T(m)-459.6;
end
88
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
%
% composition calculation
%
n=m+1;
x(n,:)=(VS*yf+Ee*VS*xf+(1-q)*F*yf-D*xd)/(L+Ee*VS);
xc=x(n,:);
T(n)=fzero(@ex2_2_5f2,620);
K(n,:)=exp(A/T(n)+B+C*T(n));
ys(n,:)=K(n,:).*x(n,:);
y(n,:)=Emv*(ys(n,:)-y(n-1,:))+y(n-1,:);
T(n)=T(n)-459.6;
x(n+ 1,:)=(V*y(n,:)+Ee*V*x(n,:)-D*xd)/(L+Ee*V);
%
% calculation for the enriching section
%
while y(n,1)<xd(1)
n=n+1;
89
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
xc=x(n,:);
T(n)=fzero(@ex2_2_5f2,620);
K(n,: )=exp(A/T(n)+B+C*T(n));
ys(n,:)=K(n,:).*x(n,:);
y(n,:)=Emv*(ys(n,:)-y(n-1,:))+y(n-1,:);
x(n+ 1,:)=(V*y(n,:)+Ee*V*x(n,:)-D*xd)/(L+Ee*V);
T(n)=T(n)-459.6;
end
%
N=n+1; % total number of plates
%
% distillate concentration
%
x(N,:)=y(n,:);
%
% results printing
%
90
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
disp(' ')
disp(' ')
disp('The bubble point and compositions at each plate.')
disp(' ')
disp('plate liquid gas temperature')
disp('no. phase phase')
disp('---- ------------------- -------------------- -----------')
for i=1:n
fprintf('%2i %10.5f %10.5f % 10.5f %10.5f %10.2fn',i,x(i,1),x(i,2),…
y(i,1), y(i,2),T(i))
end
fprintf('%2i %10.5f %10.5fn',N,x(N,1),x(N,2))
fprintf('n total no. of plates= %d; the feed plate no.= %d',N,m)
fprintf('n distillate concentration = [%7.5f %10.5f]n', x(N,1),x(N,2))
%
% composition chart plotting
%
91
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
plot(1 :N,x(:, 1),1 :N,x(:,2))
hold on
plot([m m],[0 1],'--')
hold off
xlabel('plate number')
ylabel('liquid phase composition')
title('liquid phase composition chart')
text(3,x(3,1),'leftarrow it{x_1} ','FontSize', 10)
text(3,x(3,2),' leftarrowit{x_2} ','FontSize', 10)
text(m,0.5,' leftarrow position of the feeding plate ','FontSize',10)
axis([1 N 0 1])
%
% flash point determination function
%
function y=ex2_2_5f1(T)
global A B C zf q
K=exp(A./T+B+C*T);
yf=zf./(1 +q*(1./K-1));
92
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_5.m ───────────────
xf=yf./K;
y=sum(yf)-1 ;
%
% bubble point determination function
%
function y=ex2_2_5f2(T)
global A B C xc
K=exp(A./T+B+C.*T);
yc=K.*xc;
y=sum(yc)-1;
─────────────────────────────────────────────────
93
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_5
The bubble point and compositions at each plate.
plate liquid gas temperature
no. phase phase
---- ----------------------------- -------------------------------- ---------------
1 0.10000 0.90000 0.19145 0.80855 196.35
2 0.16097 0.83903 0.26333 0.73667 189.16
3 0.20325 0.79675 0.33070 0.66930 184.28
4 0.26578 0.73422 0.41292 0.58708 177.25
5 0.33394 0.66606 0.49800 0.50200 169.85
6 0.41040 0.58960 0.58324 0.41676 161.88
7 0.44630 0.55370 0.63418 0.36582 158.27
8 0.48858 0.51142 0.67733 0.32267 154.12
9 0.54813 0.45187 0.72610 0.27390 148.47
10 0.61815 0.38185 0.77825 0.22175 142.10
11 0.69448 0.30552 0.82978 0.17022 135.50
12 0.77156 0.22844 0.87685 0.12315 129.18
13 0.84365 0.15635 0.91688 0.08312 123.57
14 0.91688 0.08312
94
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_5
total no. of plates= 14; the feed plate no.= 6
distillate concentration = [0.91688 0.08312]
95
02Solution of Nonlinear Equations
Example 2-2-6
Analysis of a set of three CSTRs in series.
96
In each of the reactors, the following liquid phase reaction
occurs
02Solution of Nonlinear Equations
The reactor volumes and the reaction rate constants are listed in
the following table:
If the concentration of component A fed into the first reactor is C0
= 1 g-mol/L and the flow rate v is kept constant at the value of
0.5 L/min, determine the steady-state concentration of component
A and the conversion rate of each reactor.
97
Reactor
number
Volume, Vi
(L)
Reaction rate constant, Ki
(L/g – mol·min)
1 5 0.03
2 2 0.05
3 3 0.10
02Solution of Nonlinear Equations
Problem formulation and analysis:
steady state, mass
98
, i = 1, 2, 3
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_6.m ───────────────
function ex2_2_6
%
% Example 2-2-6 Analysis of a set of three CSTRs in series
%
Clear; clc;
%
global v VV kk cc
%
% given data
%
C0=1; % inlet concentration (g-mol/L)
v=0.5; % flow in the reactor (L/min)
V=[5 2 3]; % volume of reactor (L)
k=[0.03 0.05 0.1]; % reaction rate constant (L/g.mol.min)
%
% start calculating
%
99
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_6.m ───────────────
C=zeros(n+1,1); % initialize concentrations
x=zeros(n+1,1); % initialize conversion rates
C(1)=C0; % inlet concentration
x(1)=0; % initial conversion rate
for i=2:n+1
VV=V(i-1);
kk=k(i-1);
cc=C(i-1);
C(i)=fzero(@ex2_2_6f,cc); % use inlet conc. as the initial guess value
x(i)=(C0-C(i))/C0; % calculating the conversion rate
end
%
% results printing
%
for i=2:n+1
fprintf('The exit conc. of reactor %d is %.3f with a conversion rate of… %.3f.n',i-
1,C(i),x(i))
100
02Solution of Nonlinear Equations
MATLAB program design:
─────────────── ex2_2_6.m ───────────────
end
%
% reaction equation
%
function f=ex2_2_6f(C)
global v VV kk cc
f=v*cc-v*C-kk*VV*C^1.5;
─────────────────────────────────────────────────
101
02Solution of Nonlinear Equations
Execution results:
>> ex2_2_6
The conc. at the outlet of reactor 1 is 0.790 with a conversion rate of 0.210.
The conc. at the outlet of reactor 2 is 0.678 with a conversion rate of 0.322.
The conc. at the outlet of reactor 3 is 0.479 with a conversion rate of 0.521.
102
02Solution of Nonlinear Equations
2.4 Summary of MATLAB commands related to
this chapter
a. Solution of a single-variable nonlinear equation:
The command format:
x=fzero(fun, x0)
x=fzero(fun, x0, options)
x=fzero(fun, x0, options, Pl , P2, ... )
[x, fval]=fzero(... )
[x, fval, exitflag]=fzero(... )
[x, fval, exitflag, output]=fzero(... )
103
02Solution of Nonlinear Equations
b. Solution of a set of nonlinear equations
The command format:
x=fsolve(fun, x0)
x=fsolve(fun, x0, options)
x=fsolve(fun, x0, options, Pl , P2, ... )
[x, fval]=fsolve(... )
[x, fval, exitflag]=fsolve(... )
[x, fval, exitflag, output] =fsolve(... )
[x, fval, exitflag, output, Jacobian] =fsolve(... )
104

More Related Content

PPSX
Ch 04 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
PPSX
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
PPSX
Ch 06 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
PDF
Matlab for Chemical Engineering
PPT
Numerical method
PPTX
Curve fitting
PPSX
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
PDF
NONLINEAR PROGRAMMING - Lecture 1 Introduction
Ch 04 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 06 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Matlab for Chemical Engineering
Numerical method
Curve fitting
Ch 05 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
NONLINEAR PROGRAMMING - Lecture 1 Introduction

What's hot (20)

DOCX
Trapezoidal Method IN Numerical Analysis
PDF
Lecture 04 newton-raphson, secant method etc
PPTX
Duel simplex method_operations research .pptx
PPS
Unit vi
PDF
69686364-Evaporation-Calculations.pdf
PPTX
Finite difference method
PPT
Riemann sumsdefiniteintegrals
PPT
Assignment 1
PDF
Matlab-free course by Mohd Esa
PDF
FINITE DIFFERENCE MODELLING FOR HEAT TRANSFER PROBLEMS
PPTX
Linear programming graphical method (feasibility)
PDF
Applied numerical methods lec14
PPTX
Complementary slackness and farkas lemmaa
PDF
Solution of matlab chapter 1
PPTX
Numerical integration;Gaussian integration one point, two point and three poi...
PPTX
Big M method
DOCX
BSC_Computer Science_Discrete Mathematics_Unit-I
PPSX
Graphical method
PPTX
arijit ppt (1) (1).pptx
PDF
Lesson 6: Limits Involving Infinity
Trapezoidal Method IN Numerical Analysis
Lecture 04 newton-raphson, secant method etc
Duel simplex method_operations research .pptx
Unit vi
69686364-Evaporation-Calculations.pdf
Finite difference method
Riemann sumsdefiniteintegrals
Assignment 1
Matlab-free course by Mohd Esa
FINITE DIFFERENCE MODELLING FOR HEAT TRANSFER PROBLEMS
Linear programming graphical method (feasibility)
Applied numerical methods lec14
Complementary slackness and farkas lemmaa
Solution of matlab chapter 1
Numerical integration;Gaussian integration one point, two point and three poi...
Big M method
BSC_Computer Science_Discrete Mathematics_Unit-I
Graphical method
arijit ppt (1) (1).pptx
Lesson 6: Limits Involving Infinity
Ad

Similar to Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片 (20)

PPSX
Ch 01 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
PDF
Mathematical models for a chemical reactor
PDF
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
PDF
Introduction to numerical methods in chemical engineering.pdf
PPT
6주차
PDF
Numerical Methods For Chemical Engineering Applications In Matlab Beers
PPT
Research Presentation Spring 2008
PPT
MATLAB ODE
PPTX
Advanced Chemical Engineeirng analysis.pptx
PDF
Numerical analysis using Scilab: Solving nonlinear equations
PDF
Introduction to numerical methods in chemical engineering p. ahuja
PDF
introduction-to-numerical-methods-in-chemical-engineering
PDF
Heat problems
DOCX
Chapter24rev1.pptPart 6Chapter 24Boundary-Valu.docx
PPT
Ch07 5
PDF
Stability Of Linear Delay Differential Equations A Numerical Approach With Ma...
PDF
AOFW CHG433_Part IIb_wip_Nov2023.pdf presentation
PDF
A simple finite element solver for thermo-mechanical problems - margonari eng...
PDF
Clarke fourier theory(62s)
PPTX
Signals And Systems Assignment Help
Ch 01 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Mathematical models for a chemical reactor
[E-book at Google Play Books] MATLAB Applications in Chemical Engineering (20...
Introduction to numerical methods in chemical engineering.pdf
6주차
Numerical Methods For Chemical Engineering Applications In Matlab Beers
Research Presentation Spring 2008
MATLAB ODE
Advanced Chemical Engineeirng analysis.pptx
Numerical analysis using Scilab: Solving nonlinear equations
Introduction to numerical methods in chemical engineering p. ahuja
introduction-to-numerical-methods-in-chemical-engineering
Heat problems
Chapter24rev1.pptPart 6Chapter 24Boundary-Valu.docx
Ch07 5
Stability Of Linear Delay Differential Equations A Numerical Approach With Ma...
AOFW CHG433_Part IIb_wip_Nov2023.pdf presentation
A simple finite element solver for thermo-mechanical problems - margonari eng...
Clarke fourier theory(62s)
Signals And Systems Assignment Help
Ad

More from Chyi-Tsong Chen (20)

PDF
[E-book at Google Play Books] Exercises Solution Manual for MATLAB Applicatio...
PDF
[電子書-Google Play Books ] MATLAB在化工上之應用習題解答自學手冊 (2022).pdf
PDF
[電子書-Google Play Books ] MATLAB程式設計與工程應用習題解答自學手冊 (2022).pdf
PDF
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
PDF
[電子書-Google Play Books] MATLAB在化工上之應用 (2022修訂版) 目錄表.pdf
PPSX
Ch 03 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
PPTX
大學經營與治校理念_陳奇中教授金大演講投影片
PPSX
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
PPSX
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
PPSX
創意研發專論:創意規則 ~陳奇中教授演講投影片
PDF
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
PDF
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
PDF
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
PPTX
MATLAB教學經驗分享~陳奇中教授演講投影片
PDF
認識化工~陳奇中教授演講投影片
PDF
IEET工程教育認證經驗分享~陳奇中教授演講投影片
PPSX
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
PDF
化工與我_學思紀行~陳奇中教授演講投影片
PPSX
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
PPSX
程序控制的第一堂課_從騎腳踏車談起 ~陳奇中教授演講投影片
[E-book at Google Play Books] Exercises Solution Manual for MATLAB Applicatio...
[電子書-Google Play Books ] MATLAB在化工上之應用習題解答自學手冊 (2022).pdf
[電子書-Google Play Books ] MATLAB程式設計與工程應用習題解答自學手冊 (2022).pdf
[電子書-Google Play Books] MATLAB程式設計與工程應用 2022 目錄表.pdf
[電子書-Google Play Books] MATLAB在化工上之應用 (2022修訂版) 目錄表.pdf
Ch 03 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
大學經營與治校理念_陳奇中教授金大演講投影片
化工概論: 製程分析模擬最適化與控制_陳奇中教授演講投影片
Reliability-Based Design Optimization Using a Cell Evolution Method ~陳奇中教授演講投影片
創意研發專論:創意規則 ~陳奇中教授演講投影片
Data Driven Process Optimization Using Real-Coded Genetic Algorithms ~陳奇中教授演講投影片
Designs of Single Neuron Control Systems: Survey ~陳奇中教授演講投影片
Intelligent Process Control Using Neural Fuzzy Techniques ~陳奇中教授演講投影片
MATLAB教學經驗分享~陳奇中教授演講投影片
認識化工~陳奇中教授演講投影片
IEET工程教育認證經驗分享~陳奇中教授演講投影片
當mit遇見MIT_波士頓見聞分享~陳奇中教授演講投影片
化工與我_學思紀行~陳奇中教授演講投影片
程序控制的最後一堂課_ 美好的人生就從今天起 ~陳奇中教授演講投影片
程序控制的第一堂課_從騎腳踏車談起 ~陳奇中教授演講投影片

Recently uploaded (20)

PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Presentation on HIE in infants and its manifestations
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Lesson notes of climatology university.
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
RMMM.pdf make it easy to upload and study
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Structure & Organelles in detailed.
PDF
Computing-Curriculum for Schools in Ghana
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Presentation on HIE in infants and its manifestations
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Final Presentation General Medicine 03-08-2024.pptx
Cell Types and Its function , kingdom of life
O7-L3 Supply Chain Operations - ICLT Program
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Lesson notes of climatology university.
O5-L3 Freight Transport Ops (International) V1.pdf
Complications of Minimal Access Surgery at WLH
Pharmacology of Heart Failure /Pharmacotherapy of CHF
RMMM.pdf make it easy to upload and study
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Structure & Organelles in detailed.
Computing-Curriculum for Schools in Ghana
2.FourierTransform-ShortQuestionswithAnswers.pdf

Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片

  • 2. 02Solution of Nonlinear Equations  Finding the solution to a nonlinear equation or a system of nonlinear equations is a common problem arising from the analysis and design of chemical processes in steady state.  the relevant MATLAB commands used to deal with this kind of problem are introduced.  the solution-finding procedure through using the Simulink simulation interface will also be demonstrated. 2
  • 3. 02Solution of Nonlinear Equations 2.1 Relevant MATLAB commands and the Simulink solution interface  2.1.1 Nonlinear equation of a single variable 3  For example, one intends to obtain the volume of 1 g- mol propane gas at P = 10 atm and T = 225.46 K from the following Van der Waals P-V-T equation:
  • 4. 02Solution of Nonlinear Equations 2.1.1 Nonlinear equation of a single variable • where a = 8.664 atm (L/g-mol), b = 0.08446 L/g-mol, and the ideal gas constant R is 0.08206 atmL/g-molK. x = fzero(‘filename’, x0) 4
  • 5. 02Solution of Nonlinear Equations 2.1.1 Nonlinear equation of a single variable ──────────────── PVT.m ──────────────── function f=PVT(V) % % Finding the solution to the Van der Waals equation (2.1-2) % % given data % a=8.664; % constant, atm (L/g-mol)^2 b=0.08446; % constant, L/g-mol R=0.08206; % ideal gas constant, atm-L/g-mol‧K P=10; % pressure, atm T=225.46; % temperature, K % % P-V-T equation % f= (P+a/V^2)*(V-b)-R*T; ──────────────────────────────────── 5
  • 6. 02Solution of Nonlinear Equations >> V=fzero('PVT', 1) % the initial guess value is set to 1 V = 1.3204 >> V=fzero ('PVT', 0.1) % use 0.1 as the initial guess value V = 0.1099 6
  • 7. 02Solution of Nonlinear Equations >> P=10; >> T=225.46; >> R=0.08206; >> V0=R*T/P; % determine a proper initial guess value by the ideal gas law >> V=fzero('PVT', V0) % solving with V0 as the initial guess value V= 1.3204 7
  • 8. 02Solution of Nonlinear Equations >> options= optimset('disp', 'iter'); % display the iteration process >> V=fzero('PVT', V0, options) Search for an interval around 1.8501 containing a sign change: Func-count a f(a) b f(b) Procedure 1 1.85012 3.62455 1.85012 3.62455 initial interval 3 1.7978 3.22494 1.90245 4.03063 search 5 1.77612 3.06143 1.92413 4.20061 search 7 1.74547 2.83234 1.95478 4.44269 search 9 1.70211 2.51286 1.99813 4.78826 search 11 1.64081 2.07075 2.05944 5.28301 search 13 1.5541 1.46714 2.14614 5.99373 search 15 1.43149 0.66438 2.26876 7.01842 search 16 1.25808 -0.340669 2.26876 7.01842 search 8
  • 9. 02Solution of Nonlinear Equations Search for a zero in the interval [1.2581, 2.2688]: Func-count X f(x) Procedure 16 1.25808 0.340669 initial 17 1.30487 0.0871675 interpolation 18 1.32076 0.00213117 interpolation 19 1.32038 1.80819e-005 interpolation 20 1.32039 3.64813e-009 interpolation 21 1.32039 0 interpolation Zero found in the interval [1.25808, 2.26876] V= 1.3204 9
  • 10. 02Solution of Nonlinear Equations Solution by Simulink: Step 1: start Simulink 10
  • 11. 02Solution of Nonlinear Equations Solution by Simulink: Step 2: 11
  • 12. 02Solution of Nonlinear Equations Solution by Simulink: Step 3: Edit Fcn (10+8.664/u (1)^2)*(u (1)-0.08446)-0.08206*225.46 12
  • 13. 02Solution of Nonlinear Equations Solution by Simulink: Step 4: solution display 13
  • 14. 02Solution of Nonlinear Equations Solution by Simulink: Step 5: Key in the initial guess value 14
  • 15. 02Solution of Nonlinear Equations Solution by Simulink: Step 6: Click building a dialogue box 15
  • 16. 02Solution of Nonlinear Equations Solution by Simulink: Step 1-2: Step 3: Edit Fcn using variable names, P, R, T, a, and b (P + a/ u (1) ^2)*(u (1)b) R*T 16
  • 17. 02Solution of Nonlinear Equations Solution by Simulink: Step 4-5: 17
  • 18. 02Solution of Nonlinear Equations Solution by Simulink: Step 6: 18
  • 19. 02Solution of Nonlinear Equations Solution by Simulink: Step 6: 19
  • 20. 02Solution of Nonlinear Equations Solution by Simulink: Step 7: Mask Subsystem 20
  • 21. 02Solution of Nonlinear Equations Solution by Simulink: Step 8: key in the parameter values 21
  • 22. 02Solution of Nonlinear Equations Solution by Simulink: Step 9: Execute the program 22
  • 23. 02Solution of Nonlinear Equations 2.1.2 Solution of a system of nonlinear equations 23
  • 24. 02Solution of Nonlinear Equations • CSTR 24 • The kinetic parameters are as follows: B = 8, Da = 0.072,  = 20, and  = 0.3. x=fsolve(‘filename’, x0)
  • 25. 02Solution of Nonlinear Equations Step 1: Provide the function ──────────────── cstr.m ──────────────── function f=fun(x) % % steady-state equation system (2.1-6) of the CSTR % % kinetic parameters % B=8; Da=0.072; phi=20; beta=0.3; % % nonlinear equations in vector form % f= [-x(1)+Da*(1-x(1))*exp(x(2)/(1+x(2)/phi)) -(1+beta)*x(2)+B*Da*(1-x(1))*exp(x(2)/(1+x(2)/phi))]; ───────────────────────────────────────────────── 25
  • 26. 02Solution of Nonlinear Equations Step 2: >> x=fsolve('cstr', [0.1 1]) % solve the equations with the initial guess [0.1 1] x= 0.1440 0.8860 >> ezplot('-x1+0.072*(1-x1)*exp(x2/(1+x2/20))', [0, 1, 0, 8]) % plotting (2.1-6a) >> hold on >> ezplot('-(1+0.3)*x2+8*0.072*(1-x1)*exp(x2/(1+x2/20))', [0, 1, 0, 8]) % plotting (2.1-6b) >> hold off 26
  • 27. 02Solution of Nonlinear Equations 27
  • 28. 02Solution of Nonlinear Equations • (0.15, 1), (0.45, 3), and (0.75, 5) >> x_1=fsolve('cstr', [0.15 1]) % the first solution x_1= 0.1440 0.8860 >> x_2=fsolve('cstr', [0.45 3]) % the second solution x_2= 0.4472 2.7517 >> x_3=fsolve('cstr', [0.75 5]) % the third solution x_3= 0.7646 4.7050 28
  • 29. 02Solution of Nonlinear Equations Solution by Simulink: Step 1: 29
  • 30. 02Solution of Nonlinear Equations Solution by Simulink: Step 2: In Fcn: -u(1)+Da*(1-u(1))*exp(u(2)/(1+u(2)/phi)) In Fcn 1: - (1+beta)*u(2)+B*Da*(1-u(1))*exp(u(2)/(1+u(2)/phi)) 30
  • 31. 02Solution of Nonlinear Equations Solution by Simulink: Step 2: 31
  • 32. 02Solution of Nonlinear Equations Solution by Simulink: Step 3: 32
  • 33. 02Solution of Nonlinear Equations Solution by Simulink: Step 4: Create a Subsystem for 33
  • 34. 02Solution of Nonlinear Equations Solution by Simulink: Step 5: Create a dialogue box 34
  • 35. 02Solution of Nonlinear Equations Solution by Simulink: Step 6: Input system parameters and initial guess values 35
  • 36. 02Solution of Nonlinear Equations Solution by Simulink: Step 7: 36
  • 37. 02Solution of Nonlinear Equations 2.2 Chemical engineering examples Example 2-2-1 Boiling point of an ideal solution Consider a three-component ideal mixture of which the vapor pressure of each component can be expressed by the following Antoine equation: where T represents the temperature of the solution (C) and Pi 0 denotes the saturated vapor pressure (mmHg). The Antoine coefficients of each component are shown in the following table (Leu, 1985): 37
  • 38. 02Solution of Nonlinear Equations Example 2-2-1 Component Ai Bi Ci 1 6.70565 1,211.033 220.790 2 6.95464 1,344.800 219.482 3 7.89750 1,474.080 229.130 38 Determine the boiling point at one atmospheric pressure for each of the following composition conditions: Condition x1 x2 x3 1 0.26 0.38 0.36 2 0.36 0.19 0.45
  • 39. 02Solution of Nonlinear Equations Problem formulation and analysis: Raoult’s law: 39
  • 40. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_1.m ─────────────── % % Example 2-2-1 boiling point of an ideal solution % % main program: ex2_2_1.m % subroutine (function file): ex2_2_1f.m % clear clc % global A B C X_M % % given data % A= [6.70565 6.95464 7.89750]; % coefficient A B= [-1211.033 -1344.800 -1474.080]; % coefficient B C= [220.790 219.482 229.130]; % coefficient C % 40
  • 41. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_1.m ─────────────── X= [0.25 0.40 0.35 0.35 0.20 0.45]; % component concentrations for each case % [m, n]=size(X); % n: the number of components % m: the number of conditions % for i=1: m X_M=X(i, :); T(i) =fzero('ex2_2_1f', 0); end % % results printing % for i=1: m fprintf('condition %d, X(l)=%.3f, X(2)=%.3f, X(3)=%.3f, boiling point=… %.3f ℃n',i,X(i,1),X(i,2),X(i,3),T(i)) end ───────────────────────────────────────────────── 41
  • 42. 02Solution of Nonlinear Equations MATLAB program design: ──────────────── ex2_2_1f.m ──────────────── % % example 2-2-1 boiling point of an ideal solution % subroutine (function file): ex2_2_1f.m % function f= ex2_2_1f(T) global A B C X_M Pi=10.^(A+B./(C+T)); % saturated vapor pressure of each component p=sum(X_M.*Pi); % total pressure f=p-760; end ───────────────────────────────────────────────── 42
  • 43. 02Solution of Nonlinear Equations Execution results: >> ex2_2_1 condition 1, X(l)=0.250, X(2)=0.400, X(3)=0.350, boiling point=82.103C condition 2, X(l)=0.350, X(2)=0.200, X(3)=0.450, boiling point=77.425C 43
  • 44. 02Solution of Nonlinear Equations Example 2-2-2 Equilibrium concentrations in a reaction system 3H2 + CO ⇌ CH4 + H2O, 𝐾1 = 69.18 CO + H2O ⇌ CO2 + H2, 𝐾2 = 4.68 CO2 + C(𝑠) ⇌ 2CO, 𝐾3 = 5.60 × 10−3 5H2 + 2CO ⇌ C2H6 + 2H2O, 𝐾4 = 0.14 where Ki is the equilibrium constant under the operating condition of 500C and 1 atmospheric pressure. Assume that 1 mole of CO and 3 moles of H2 exist initially in the system, determine the equilibrium concentration of each component (mole fraction) when the reaction system reaches an equilibrium. 44
  • 45. 02Solution of Nonlinear Equations Analysis of the question: Let y1, y2, …, and y6 stand for the mole fractions of H2, CO, CH4, H2O, CO2, and C2H6, respectively. Besides, let x1, x2, x3, and x4 be the reaction rates of individual equations in (2.2-5a-d). 45
  • 46. 02Solution of Nonlinear Equations Analysis of the question: 46 D = 4  2x1 + x3  4x4
  • 47. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_2.m ─────────────── function ex2_2_2 % notice the format of the first line % % Example 2-2-2 Equilibrium concentrations in a reaction system % clear clc % % initial guess values % x0= [0.7 0 -0.1 0]; % % solving by calling the embedded function file ex2_2_2f % options= optimset('disp', 'iter'); x=fsolve(@ex2_2_2f, x0, options); % notice the use of the function handle @ % % calculate the mole fraction % 47
  • 48. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_2.m ─────────────── y=ex2_2_2y(x); % % results printing % disp(' ') disp('reaction rate of each equation') % for i=1:4 fprintf('x(%d) =%.3e n', i, x (i)) end % disp(' ') disp('mole fraction of each component') % for i=1:6 fprintf('y(%i) =%.3e n', i, y (i)) end 48
  • 49. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_2.m ─────────────── % % chemical equilibrium equations % function f=ex2_2_2f(x) % y= ex2_2_2y(x); % % the set of nonlinear equations % f= [y(3)*y(4)/(y (1)^3*y(2))-69.18 y(5)*y(1)/(y(2)*y(4))-4.68 y(2)^2/y(5)-5.60e-3 y(6)*y(4)^2/(y(1)^5*y(2)^2)-0.14]; % % the subroutine for calculating the mole fraction % function y=ex2_2_2y(x) 49
  • 50. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_2.m ─────────────── % chemical equilibrium equations % function f=ex2_2_2f(x) % y= ex2_2_2y(x); % % the set of nonlinear equations % f= [y(3)*y(4)/(y (1)^3*y(2))-69.18 y(5)*y(1)/(y(2)*y(4))-4.68 y(2)^2/y(5)-5.60e-3 y(6)*y(4)^2/(y(1)^5*y(2)^2)-0.14]; % % the subroutine for calculating the mole fraction % function y=ex2_2_2y(x) D=4-2*x(1) +x(3)-4*x(4); 50
  • 51. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_2.m ─────────────── if D == 0 disp('D is zero') return end y(1)=(3-3*x(1) +x(2)-5*x(4))/D; y(2)=(1-x(1)-x(2) +2*x(3)-2*x(4))/D; y(3)=x(1)/D; y(4)=(x(1)-x(2) +2*x(4))/D; y(5)=(x(2)-x(3))/D; y(6)=x(4)/D; ───────────────────────────────────────────────── 51
  • 52. 02Solution of Nonlinear Equations Execution results: >> ex2_2_2 reaction rate of each equation x (1) =6.816e-001 x (2) =1.590e-002 x (3) =-1.287e-001 x (4) =1.400e-005 52
  • 53. 02Solution of Nonlinear Equations Execution results: >> ex2_2_2 mole fraction of each component y(1) =3.872e-001 y(2) =1.797e-002 y(3) =2.718e-001 y(4) =2.654e-001 y(5) =5.765e-002 y(6) =5.580e-006 53
  • 54. 02Solution of Nonlinear Equations Example 2-2-3 Analysis of a pipeline network Figure 2.1 systematically illustrates a pipeline network installed on a horizontal ground surface. In the network, raw materials are fed to eight locations denoted as P1, P2, … , P7, and P8, and the flow rate (m3/min) required at each of the eight locations is listed as follows (Leu, 1985): P1Q = 3.0, P2Q = 2.0, P3Q = 5.0, P4Q = 3.0 P5Q = 2.0, P6Q = 2.0, P7Q = 5.0, P8Q = 2.0 54
  • 55. 02Solution of Nonlinear Equations 55 Due to flow frictions, the head loss h(m) for each 1/2 side of the pipeline (such as P1 to P5) is given by Note that the head loss is a function of the flow rate Q (m3/min) in the pipeline. Based on the required flow rates PiQ determine the corresponding flow rates, Q1 to Q9, in the pipeline and the head at each of the eight locations.
  • 56. 02Solution of Nonlinear Equations 56 Figure 2.1 Schematic diagram of the pipeline network.
  • 57. 02Solution of Nonlinear Equations Problem formulation and analysis: mass balance Mass balance at P2: Q3 = Q5 + P2Q Mass balance at P3: Q7 + Q9 = P3Q Mass balance at P1: Q1 = Q8 + P4Q Mass balance at P5: Q2 = Q3 + Q4 + P5Q Mass balance at P6: Q5 = Q7 + P6Q Mass balance at P7: Q6 + Q8 = Q9 + P7Q Mass balance at P8: Q4 = Q6 + P8Q 57
  • 58. 02Solution of Nonlinear Equations Problem formulation and analysis: Head loss balance by considering hP1P5 +hP5P8 +hP8P7 +hP1P4 +hP4P7 : 58 Head loss balance by considering hP5P2 +hP2P6 +hP6P6 =hP5P8 +hP8P7 +hP7P3 :
  • 59. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── function ex2_2_3 % % Example 2-2-3 pipeline network analysis % clear clc % global PQ % declared as a global parameter % PQ=[3 2 5 3 2 2 5 2]; % flow rate required at each location % Q0=2*ones(1, 9); % initial guess value % % solving % Q=fsolve(@ex2_2_3f, Q0,1.e-6); % setting the solution accuracy as 1.e-6 % 59
  • 60. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── h(3)=10; h(6)=h(3)+0.5*abs(Q(7))^0.85*Q(7); h(2)=h(6)+0.5*abs(Q(5))^0.85*Q(5); h(7)=h(3)+0.5*abs(Q(9))^0.85*Q(9); h(8)=h(7)+0.5*abs(Q(6))^0.85*Q(6); h(5)=h(2)+0.5*abs(Q(3))^0.85*Q(3); h(4)=h(7)+0.5*abs(Q(8))^0.85*Q(8); h(1)=h(5)+0.5*abs(Q(2))^0.85*Q(2); % % results printing % disp(' ') disp('flow at each location (m^3/min)') for i=1:9 fprintf('Q(%i)=%7.3f n',i,Q(i)) end disp(' ') disp('head at each location (m)') 60
  • 61. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── for i=1:8 fprintf('h(%i)=%7.3f n',i,h(i)) end % % nonlinear simultaneous equations % function f=ex2_2_3f(Q) % global PQ % f=[Q(3)-Q(5)-PQ(2) Q(7)+Q(9)-PQ(3) Q(1 )-Q(8)-PQ(4) Q(2)-Q(3)-Q(4)-PQ(5) Q(5)-Q(7)-PQ(6) Q(6)+Q(8)-Q(9)-PQ(7) Q(4)-Q(6)-PQ(8) 61
  • 62. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── 0.5*abs(Q(2))^0.85*Q(2)+0.5*abs(Q(4))^0.85*Q(4)+0.5*abs(Q(6))^0.85*Q(6)-... abs(Q(1))^0.85*Q(1)-0.5*abs(Q(8))^0.85*Q(8) 0.5*abs(Q(3))^0.85*Q(3)+0.5*abs(Q(5))^0.85*Q(5)+0.5*abs(Q(7))^0.85*Q(7)-... 0.5*abs(Q(4))^0.85*Q(4)-0.5*abs(Q(6))^0.85*Q(6)-0.5*abs(Q(9))^0.85*Q(9)]; ───────────────────────────────────────────────── 62
  • 63. 02Solution of Nonlinear Equations Execution results: >> ex2_2_3 flow at each location (m^3/min) Q(1)= 8.599 Q(2)= 12.401 Q(3)= 5.517 Q(4)= 4.884 Q(5)= 3.517 Q(6)= 2.884 Q(7)= 1.517 Q(8)= 5.599 Q(9)= 3.483 63 head at each location (m) h(1)= 80.685 h(2)= 16.202 h(3)= 10.000 h(4)= 27.137 h(5)= 27.980 h(6)= 11.081 h(7)= 15.031 h(8)= 18.578
  • 64. 02Solution of Nonlinear Equations Example 2-2-4 A material drying process through heat conduction and forced convection Figure 2.2 schematically depicts a drying process (Leu, 1985), where a wet material with thickness of 6 cm is placed on a hot plate maintained at 100C. 64 Figure 2.2 A material drying process through heat conduction and forced convection.
  • 65. 02Solution of Nonlinear Equations To dry the material, the hot wind with a temperature of 85C and partial vapor pressure of 40 mmHg is blowing over the wet material at a flow rate of 3.5 m/s. The relevant operation conditions and assumptions are stated as follows: (1) During the drying process, the heat conduction coefficient of the wet material is kept constant, and its value is measured to be 1.0 kcal/m·hr·C. (2) The convective heat transfer coefficient h (kcal/m·hr·C) between the hot wind and the material surface is a function of mass flow rate of wet air G (kg/hr), which is given by h = 0.015G 0.8 (3) The saturated vapor pressure Ps (mmHg), which is a function of temperature ( C), can be expressed by the Antoine equations as follows: 65
  • 66. 02Solution of Nonlinear Equations (4) The latent heat of water vaporization rm (kcal/kg) is a function of temperature T (C), which is given by rm = 597.65 – 0.575 T (5) The mass flow rate of wet air G and its mass transfer coefficient M are measured to be the values of 1.225×104 kg/hr and 95.25 kg/m2·hr, respectively. Based on the operating conditions mentioned above, determine the surface temperature of the material Tm and the constant drying rate Rc, which is defined as Rc = M(Hm – H) 66
  • 67. 02Solution of Nonlinear Equations Problem formulation and analysis: 67 h = 0.015G 0.8 rm = 597.65 – 0.575T Tp = 100 C L = 0.06 m k = 1 kcal/m·hr· C Ta = 85 C G = 1.225×104 kg/hr M = 95.25 kg/m2· hr
  • 68. 02Solution of Nonlinear Equations Problem formulation and analysis: 68
  • 69. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── function ex2_2_4 % % Example 2-2-4 A material drying process via heat conduction and forced convection % clear clc % global h Ta M k L Tp H % G=1.225e4; % mass flow rate of wet air (kg/hr) M=95.25; % mass transfer coefficient (kg/m^2.hr) k=1; % heat transfer coefficient of the wet material (kcal/m.hr.℃) Tp=100; % hot plate temperature (℃) L=0.06; % material thickness (m) Ta=85; % hot wind temperature (℃) P=40; % partial pressure of water vapor (mmHg) H=18.02*P/(28.97*(760-P)); % humidity of hot air (%) h=0.015*G^0.8; % heat transfer coefficient (kcal/m^2.hr. ℃) 69
  • 70. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── % % solving for Tm % Tm=fzero(@ex2_2_4f, 50); % Ps=ex2_2_4Ps(Tm); % eq. (2.2-12) % % calculating constant drying rate % Hm=18.02*Ps/(28.97* (760-Ps)); % eq. (2.2-17) Rc=M*(Hm-H); % eq. (2.2-14) % % results printing % fprintf('the surface temperature of the material =%.3f ℃n', Tm) fprintf('the constant drying rate = %.3f kg/m^2.hrn', Rc) % 70
  • 71. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── % nonlinear function % function f = ex2_2_4f(Tm) % global h Ta M k L Tp H % Ps= ex2_2_4Ps(Tm); % eq.(2.2-12) % Hm=18.02*Ps/(28.97*(760-Ps)); % eq.(2.2-17) rm=597.65-0.575*Tm; % eq.(2.2-13) % f=h*(Ta-Tm)-M*(Hm-H)*rm-k/L*(Tm-Tp); % eq.(2.2-15) % % subroutine for calculating the saturated vapor pressure % function Ps=ex2_2_4Ps(Tm) if Tm < 55 71
  • 72. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_3.m ─────────────── Ps=10^(7.7423-1554.16/(219+Tm)); elseif Tm >= 55 Ps=10^(7.8097-1572.53/(219+Tm)); end ───────────────────────────────────────────────── 72
  • 73. 02Solution of Nonlinear Equations Execution results: >> ex2_2_4 the surface temperature of the material = 46.552C the constant drying rate = 3.444 kg/m^2.hr 73
  • 74. 02Solution of Nonlinear Equations Example 2-2-5 A mixture of 50 mol% propane and 50 mol% n-butane is to be distilled into 90 mol% propane distillate and 90 mol% n-butane bottoms by a multistage distillation column. The q value of raw materials is 0.5, and the feeding rate is 100 mol/hr. Suppose the binary distillation column is operated under the following operating conditions (McCabe and Smith, 1967): 1) The Murphree vapor efficiency EMV is 0.7; 2) The entrainment effect coefficient ε is 0.2; 3) The reflux ratio is 2.0; 4) The operating pressure in the tower is 220 Psia; 74
  • 75. 02Solution of Nonlinear Equations 5) The equilibrium coefficient (K = y/x), which depends on the absolute temperature T (R), is given by ln K = A/T+B+CT where the coefficients A, B, and C under 220 Psia for propane and n-butane are listed in the table below. 75 Component A B C Propane 3,987.933 8.63131 0.00290 n-Butane 4,760.751 8.50187 0.00206
  • 76. 02Solution of Nonlinear Equations Answers to the following questions: 1) The theoretical number of plates and the position of the feeding plate. 2) The component compositions in the gas phase and the liquid phase at each plate. 3) The temperature of the re-boiler and the bubble point at each plate. 76
  • 77. 02Solution of Nonlinear Equations Problem formulation and analysis: (1) Overall mass balance: 77 W = F  D Name of variable Physical meaning Name of variable Physical meaning D Flow rate of the distillate xD Composition of the distillate F Flow rate of the feed xw Composition of the bottoms W Flow rate of the bottoms zF Composition of the feed
  • 78. 02Solution of Nonlinear Equations Problem formulation and analysis: (1) Overall mass balance: 78
  • 79. 02Solution of Nonlinear Equations 79
  • 80. 02Solution of Nonlinear Equations Problem formulation and analysis: (2) Material balance on the feed plate: 80 q value Condition of the feed q > 1 The temperature of the feed is lower than the boiling point q = 1 Saturated liquid 0 < q < 1 Mixture of liquid and vapor q = 0 Saturated vapor q < 0 Overheated vapor
  • 81. 02Solution of Nonlinear Equations Problem formulation and analysis: (3) Material balance made for the re-boiler (4) Stripping section 81
  • 82. 02Solution of Nonlinear Equations Problem formulation and analysis: (5) Enriching section 𝑥 𝑛+1 = 𝐿𝑦𝑛 + 𝜀𝑉𝑥 𝑛 − 𝐷𝑥 𝐷 𝐿 + 𝜀𝑉 (6) Feed plate 𝑥𝑓+1 = 𝑉′𝑦𝑓 + 𝜀𝑉′𝑥𝑓 + 1 − 𝑞 𝐹𝑦 𝐹 − 𝐷𝑥 𝐷 𝐿 + 𝜀𝑉′ (A) Calculation of the flash point at the feed plate: 82 , i =1, 2
  • 83. 02Solution of Nonlinear Equations Problem formulation and analysis: where Ki = exp (Ai / T + Bi + CiT) (B) Calculation of the flash point at the feed plate: 83
  • 84. 02Solution of Nonlinear Equations MATLAB program design: 84
  • 85. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── function ex2_2_5 % % Example 2-2-5 analysis of a continuous multi-stage binary distillation % clear; close all clc % % declare the global variables % global A B C zf q global A B C xc % % operation data % zf=[0.5 0.5]; % feed composition xd=[0.9 0.1]; % distillate composition xw=[0.1 0.9]; % composition of the bottom product F=100; % feed flow rate (mol/h) 85
  • 86. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── q=0.5; % q value of the feed Emv=0.7; % Murphree vapor efficiency Ee=0.2; % entrainment coefficient RD=2; % reflux ratio % A=[-3987.933 -4760.751]; % parameter A B=[8.63131 8.50187]; % parameter B C=[-0.00290 -0.00206]; % parameter C % % calculating all flow rates (D,W,L,V, LS, and VS) % D=F*(zf(1)-xw(1))/(xd(1)-xw(1)) ; % distillate flow rate W=F-D; % flow rate of the bottom product L=RD*D; % liquid flow rate in the enriching section V=L+D; % gas flow rate in the enriching section LS=L+q*F; % liquid flow rate in the stripping section VS=V-(1-q)*F; % gas flow rate in the stripping section % 86
  • 87. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── % calculating the flash point at the feed plate % Tf=fzero(@ex2_2_5f1,620); % flash point K=exp(A/Tf+B+C*Tf); yf=zf./(1 +q*(1./K-1)); % gas phase composition at the feed plate xf=yf./K; % liquid phase composition at the feed plate Tf=Tf-459.6; % converted to ℉ % % equilibrium in the re-boiler % xc=xw; Tw=fzero(@ex2_2_5f2,620); Kw=exp(A/Tw+B+C*Tw); yw=Kw.*xw; % gas phase composition in the re-boiler Tw=Tw-459.6; % bubble point (℉) of the re-boiler % % calculating the liquid phase composition in the re-boiler 87
  • 88. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── m=1; x(m,:)=xw; y(m,:)=yw; x(m+1,:)=(VS*y(m,:)+W*xw)/LS; % % calculating for the stripping section % T(m)=Tw; while T(m)>Tf m=m+1; xc=x(m,:); T (m)=fzero(@ex2_2_5f2,620); K(m,:)=exp(A/T(m)+B+C*T(m)); ys(m,:)=K(m,:).*x(m,:); y(m,:)=Emv*(ys(m,:)-y(m-1,:))+y(m-1,:); x(m+1,:)=(VS*y(m,:)+Ee*VS*x(m,:)+W*x(m-1,:))/(LS+Ee*VS); T(m)=T(m)-459.6; end 88
  • 89. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── % % composition calculation % n=m+1; x(n,:)=(VS*yf+Ee*VS*xf+(1-q)*F*yf-D*xd)/(L+Ee*VS); xc=x(n,:); T(n)=fzero(@ex2_2_5f2,620); K(n,:)=exp(A/T(n)+B+C*T(n)); ys(n,:)=K(n,:).*x(n,:); y(n,:)=Emv*(ys(n,:)-y(n-1,:))+y(n-1,:); T(n)=T(n)-459.6; x(n+ 1,:)=(V*y(n,:)+Ee*V*x(n,:)-D*xd)/(L+Ee*V); % % calculation for the enriching section % while y(n,1)<xd(1) n=n+1; 89
  • 90. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── xc=x(n,:); T(n)=fzero(@ex2_2_5f2,620); K(n,: )=exp(A/T(n)+B+C*T(n)); ys(n,:)=K(n,:).*x(n,:); y(n,:)=Emv*(ys(n,:)-y(n-1,:))+y(n-1,:); x(n+ 1,:)=(V*y(n,:)+Ee*V*x(n,:)-D*xd)/(L+Ee*V); T(n)=T(n)-459.6; end % N=n+1; % total number of plates % % distillate concentration % x(N,:)=y(n,:); % % results printing % 90
  • 91. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── disp(' ') disp(' ') disp('The bubble point and compositions at each plate.') disp(' ') disp('plate liquid gas temperature') disp('no. phase phase') disp('---- ------------------- -------------------- -----------') for i=1:n fprintf('%2i %10.5f %10.5f % 10.5f %10.5f %10.2fn',i,x(i,1),x(i,2),… y(i,1), y(i,2),T(i)) end fprintf('%2i %10.5f %10.5fn',N,x(N,1),x(N,2)) fprintf('n total no. of plates= %d; the feed plate no.= %d',N,m) fprintf('n distillate concentration = [%7.5f %10.5f]n', x(N,1),x(N,2)) % % composition chart plotting % 91
  • 92. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── plot(1 :N,x(:, 1),1 :N,x(:,2)) hold on plot([m m],[0 1],'--') hold off xlabel('plate number') ylabel('liquid phase composition') title('liquid phase composition chart') text(3,x(3,1),'leftarrow it{x_1} ','FontSize', 10) text(3,x(3,2),' leftarrowit{x_2} ','FontSize', 10) text(m,0.5,' leftarrow position of the feeding plate ','FontSize',10) axis([1 N 0 1]) % % flash point determination function % function y=ex2_2_5f1(T) global A B C zf q K=exp(A./T+B+C*T); yf=zf./(1 +q*(1./K-1)); 92
  • 93. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_5.m ─────────────── xf=yf./K; y=sum(yf)-1 ; % % bubble point determination function % function y=ex2_2_5f2(T) global A B C xc K=exp(A./T+B+C.*T); yc=K.*xc; y=sum(yc)-1; ───────────────────────────────────────────────── 93
  • 94. 02Solution of Nonlinear Equations Execution results: >> ex2_2_5 The bubble point and compositions at each plate. plate liquid gas temperature no. phase phase ---- ----------------------------- -------------------------------- --------------- 1 0.10000 0.90000 0.19145 0.80855 196.35 2 0.16097 0.83903 0.26333 0.73667 189.16 3 0.20325 0.79675 0.33070 0.66930 184.28 4 0.26578 0.73422 0.41292 0.58708 177.25 5 0.33394 0.66606 0.49800 0.50200 169.85 6 0.41040 0.58960 0.58324 0.41676 161.88 7 0.44630 0.55370 0.63418 0.36582 158.27 8 0.48858 0.51142 0.67733 0.32267 154.12 9 0.54813 0.45187 0.72610 0.27390 148.47 10 0.61815 0.38185 0.77825 0.22175 142.10 11 0.69448 0.30552 0.82978 0.17022 135.50 12 0.77156 0.22844 0.87685 0.12315 129.18 13 0.84365 0.15635 0.91688 0.08312 123.57 14 0.91688 0.08312 94
  • 95. 02Solution of Nonlinear Equations Execution results: >> ex2_2_5 total no. of plates= 14; the feed plate no.= 6 distillate concentration = [0.91688 0.08312] 95
  • 96. 02Solution of Nonlinear Equations Example 2-2-6 Analysis of a set of three CSTRs in series. 96 In each of the reactors, the following liquid phase reaction occurs
  • 97. 02Solution of Nonlinear Equations The reactor volumes and the reaction rate constants are listed in the following table: If the concentration of component A fed into the first reactor is C0 = 1 g-mol/L and the flow rate v is kept constant at the value of 0.5 L/min, determine the steady-state concentration of component A and the conversion rate of each reactor. 97 Reactor number Volume, Vi (L) Reaction rate constant, Ki (L/g – mol·min) 1 5 0.03 2 2 0.05 3 3 0.10
  • 98. 02Solution of Nonlinear Equations Problem formulation and analysis: steady state, mass 98 , i = 1, 2, 3
  • 99. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_6.m ─────────────── function ex2_2_6 % % Example 2-2-6 Analysis of a set of three CSTRs in series % Clear; clc; % global v VV kk cc % % given data % C0=1; % inlet concentration (g-mol/L) v=0.5; % flow in the reactor (L/min) V=[5 2 3]; % volume of reactor (L) k=[0.03 0.05 0.1]; % reaction rate constant (L/g.mol.min) % % start calculating % 99
  • 100. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_6.m ─────────────── C=zeros(n+1,1); % initialize concentrations x=zeros(n+1,1); % initialize conversion rates C(1)=C0; % inlet concentration x(1)=0; % initial conversion rate for i=2:n+1 VV=V(i-1); kk=k(i-1); cc=C(i-1); C(i)=fzero(@ex2_2_6f,cc); % use inlet conc. as the initial guess value x(i)=(C0-C(i))/C0; % calculating the conversion rate end % % results printing % for i=2:n+1 fprintf('The exit conc. of reactor %d is %.3f with a conversion rate of… %.3f.n',i- 1,C(i),x(i)) 100
  • 101. 02Solution of Nonlinear Equations MATLAB program design: ─────────────── ex2_2_6.m ─────────────── end % % reaction equation % function f=ex2_2_6f(C) global v VV kk cc f=v*cc-v*C-kk*VV*C^1.5; ───────────────────────────────────────────────── 101
  • 102. 02Solution of Nonlinear Equations Execution results: >> ex2_2_6 The conc. at the outlet of reactor 1 is 0.790 with a conversion rate of 0.210. The conc. at the outlet of reactor 2 is 0.678 with a conversion rate of 0.322. The conc. at the outlet of reactor 3 is 0.479 with a conversion rate of 0.521. 102
  • 103. 02Solution of Nonlinear Equations 2.4 Summary of MATLAB commands related to this chapter a. Solution of a single-variable nonlinear equation: The command format: x=fzero(fun, x0) x=fzero(fun, x0, options) x=fzero(fun, x0, options, Pl , P2, ... ) [x, fval]=fzero(... ) [x, fval, exitflag]=fzero(... ) [x, fval, exitflag, output]=fzero(... ) 103
  • 104. 02Solution of Nonlinear Equations b. Solution of a set of nonlinear equations The command format: x=fsolve(fun, x0) x=fsolve(fun, x0, options) x=fsolve(fun, x0, options, Pl , P2, ... ) [x, fval]=fsolve(... ) [x, fval, exitflag]=fsolve(... ) [x, fval, exitflag, output] =fsolve(... ) [x, fval, exitflag, output, Jacobian] =fsolve(... ) 104