![Page 1: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/1.jpg)
Solution of Nonlinear Equations
Chapter 2
![Page 2: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/2.jpg)
02Solution of Nonlinear Equations
2
① 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.
![Page 3: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/3.jpg)
02Solution of Nonlinear Equations
3
2.1 Relevant MATLAB commands and the Simulink solution interface
2.1.1 Nonlinear equation of a single variable
0)( xf
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:
0)()( 2
RTbV
VaPVf
![Page 4: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/4.jpg)
02Solution of Nonlinear Equations
4
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 atmL/g-molK.
x = fzero(‘filename’, x0)
![Page 5: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/5.jpg)
02Solution of Nonlinear Equations
5
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)^2b=0.08446; % constant, L/g-molR=0.08206; % ideal gas constant, atm-L/g-mol K‧P=10; % pressure, atmT=225.46; % temperature, K%% P-V-T equation%f= (P+a/V^2)*(V-b)-R*T; ────────────────────────────────────
![Page 6: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/6.jpg)
02Solution of Nonlinear Equations
6
>> 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
![Page 7: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/7.jpg)
02Solution of Nonlinear Equations
7
>> 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
![Page 8: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/8.jpg)
02Solution of Nonlinear Equations
8
>> 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) Procedure1 1.85012 3.62455 1.85012 3.62455 initial interval3 1.7978 3.22494 1.90245 4.03063 search5 1.77612 3.06143 1.92413 4.20061 search7 1.74547 2.83234 1.95478 4.44269 search9 1.70211 2.51286 1.99813 4.78826 search11 1.64081 2.07075 2.05944 5.28301 search13 1.5541 1.46714 2.14614 5.99373 search15 1.43149 0.66438 2.26876 7.01842 search16 1.25808 -0.340669 2.26876 7.01842 search
![Page 9: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/9.jpg)
02Solution of Nonlinear Equations
9
Search for a zero in the interval [1.2581, 2.2688]:
Func-count X f(x) Procedure16 1.25808 0.340669 initial17 1.30487 0.0871675 interpolation18 1.32076 0.00213117 interpolation19 1.32038 1.80819e-005 interpolation20 1.32039 3.64813e-009 interpolation21 1.32039 0 interpolation
Zero found in the interval [1.25808, 2.26876]
V=
1.3204
![Page 10: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/10.jpg)
02Solution of Nonlinear Equations
10
Solution by Simulink:Step 1: start Simulink
![Page 11: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/11.jpg)
02Solution of Nonlinear Equations
11
Solution by Simulink:Step 2:
![Page 12: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/12.jpg)
02Solution of Nonlinear Equations
12
Solution by Simulink:Step 3: Edit Fcn
(10+8.664/u (1)^2)*(u (1)-0.08446)-0.08206*225.46
![Page 13: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/13.jpg)
02Solution of Nonlinear Equations
13
Solution by Simulink:Step 4: solution display
![Page 14: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/14.jpg)
02Solution of Nonlinear Equations
14
Solution by Simulink:Step 5: Key in the initial guess value
![Page 15: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/15.jpg)
02Solution of Nonlinear Equations
15
Solution by Simulink:Step 6: Click
building a dialogue box
![Page 16: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/16.jpg)
02Solution of Nonlinear Equations
16
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
![Page 17: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/17.jpg)
02Solution of Nonlinear Equations
17
Solution by Simulink:Step 4-5:
![Page 18: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/18.jpg)
02Solution of Nonlinear Equations
18
Solution by Simulink:Step 6:
![Page 19: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/19.jpg)
02Solution of Nonlinear Equations
19
Solution by Simulink:Step 6:
![Page 20: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/20.jpg)
02Solution of Nonlinear Equations
20
Solution by Simulink:Step 7: Mask Subsystem
![Page 21: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/21.jpg)
02Solution of Nonlinear Equations
21
Solution by Simulink:Step 8: key in the parameter values
![Page 22: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/22.jpg)
02Solution of Nonlinear Equations
22
Solution by Simulink:Step 9: Execute the program
![Page 23: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/23.jpg)
02Solution of Nonlinear Equations
23
2.1.2 Solution of a system of nonlinear equations
0),,,(
0),,,(0),,,(
21
212
211
nn
n
n
xxxf
xxxfxxxf
0)( xF
![Page 24: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/24.jpg)
02Solution of Nonlinear Equations
24
• CSTR
/1
exp)1(2
2111 x
xxDxx a
/1
exp)1()1(2
2122 x
xxBDxx a
• The kinetic parameters are as follows: B = 8, Da = 0.072, = 20, and = 0.3.
21 1 2 1 1
2
22 1 2 2 1
2
( , ) (1 )exp 01 /
( , ) (1 ) (1 )exp 01 /
a
a
xf x x x D x
x
xf x x x BD xx
x=fsolve(‘filename’, x0)
![Page 25: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/25.jpg)
02Solution of Nonlinear Equations
25
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))];
─────────────────────────────────────────────────
![Page 26: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/26.jpg)
02Solution of Nonlinear Equations
26
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
![Page 27: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/27.jpg)
02Solution of Nonlinear Equations
27
![Page 28: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/28.jpg)
02Solution of Nonlinear Equations
28
• (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
![Page 29: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/29.jpg)
02Solution of Nonlinear Equations
29
Solution by Simulink:Step 1:
![Page 30: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/30.jpg)
02Solution of Nonlinear Equations
30
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))
![Page 31: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/31.jpg)
02Solution of Nonlinear Equations
31
Solution by Simulink:Step 2:
![Page 32: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/32.jpg)
02Solution of Nonlinear Equations
32
Solution by Simulink:Step 3:
![Page 33: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/33.jpg)
02Solution of Nonlinear Equations
33
Solution by Simulink:Step 4: Create a Subsystem for
![Page 34: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/34.jpg)
02Solution of Nonlinear Equations
34
Solution by Simulink:Step 5: Create a dialogue box
![Page 35: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/35.jpg)
02Solution of Nonlinear Equations
35
Solution by Simulink:Step 6: Input system parameters and initial guess values
![Page 36: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/36.jpg)
02Solution of Nonlinear Equations
36
Solution by Simulink:Step 7:
![Page 37: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/37.jpg)
02Solution of Nonlinear Equations
37
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 Pi0
denotes the saturated vapor pressure (mmHg). The Antoine coefficients of each component are shown in the following table (Leu, 1985):
TCB
APi
iii 0log
![Page 38: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/38.jpg)
02Solution of Nonlinear Equations
38
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
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
![Page 39: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/39.jpg)
02Solution of Nonlinear Equations
39
Problem formulation and analysis:Raoult’s law:
0iii PxP
033
022
011
3
1
PxPxPxPPi
i
076010
0)(
3
1
)/(
3
1
0
i
TCBAi
iii
iiix
PPxTf
![Page 40: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/40.jpg)
02Solution of Nonlinear Equations
40
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%clearclc%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 %
![Page 41: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/41.jpg)
02Solution of Nonlinear Equations
41
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: mX_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 ─────────────────────────────────────────────────
![Page 42: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/42.jpg)
02Solution of Nonlinear Equations
42
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_MPi=10.^(A+B./(C+T)); % saturated vapor pressure of each componentp=sum(X_M.*Pi); % total pressuref=p-760;end ─────────────────────────────────────────────────
![Page 43: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/43.jpg)
02Solution of Nonlinear Equations
43
Execution results:>> ex2_2_1
condition 1, X(l)=0.250, X(2)=0.400, X(3)=0.350, boiling point=82.103C
condition 2, X(l)=0.350, X(2)=0.200, X(3)=0.450, boiling point=77.425C
![Page 44: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/44.jpg)
02Solution of Nonlinear Equations
44
Example 2-2-2
Equilibrium concentrations in a reaction system
where Ki is the equilibrium constant under the operating
condition of 500C 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.
![Page 45: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/45.jpg)
02Solution of Nonlinear Equations
45
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).
18.692
31
43 yyyy
68.442
15 yyyy
3
5
22 106.5
yy
14.022
51
246
yyyy
![Page 46: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/46.jpg)
02Solution of Nonlinear Equations
46
Analysis of the question:
Dxxxy /)533( 4211
Dxxxxy /)221( 43212
Dxy /13
Dxxxy /)2( 4214
Dxxy /)( 325
Dxy /46
D = 4 2x1 + x3 4x4
![Page 47: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/47.jpg)
02Solution of Nonlinear Equations
47
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%clearclc%% 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%
![Page 48: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/48.jpg)
02Solution of Nonlinear Equations
48
MATLAB program design:─────────────── ex2_2_2.m ───────────────y=ex2_2_2y(x);%% results printing%disp(' ')disp('reaction rate of each equation')%for i=1:4fprintf('x(%d) =%.3e \n', i, x (i))end%disp(' ')disp('mole fraction of each component')%for i=1:6fprintf('y(%i) =%.3e \n', i, y (i))end
![Page 49: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/49.jpg)
02Solution of Nonlinear Equations
49
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)
![Page 50: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/50.jpg)
02Solution of Nonlinear Equations
50
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);
![Page 51: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/51.jpg)
02Solution of Nonlinear Equations
51
MATLAB program design:─────────────── ex2_2_2.m ───────────────if D == 0disp('D is zero')returnendy(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;
─────────────────────────────────────────────────
![Page 52: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/52.jpg)
02Solution of Nonlinear Equations
52
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
![Page 53: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/53.jpg)
02Solution of Nonlinear Equations
53
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
![Page 54: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/54.jpg)
02Solution of Nonlinear Equations
54
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
![Page 55: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/55.jpg)
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.
QQh 85.05.0
![Page 56: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/56.jpg)
02Solution of Nonlinear Equations
56
Figure 2.1 Schematic diagram of the pipeline network.
![Page 57: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/57.jpg)
02Solution of Nonlinear Equations
57
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
![Page 58: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/58.jpg)
02Solution of Nonlinear Equations
58
Problem formulation and analysis:Head loss balance by considering hP1P5
+hP5P8+hP8P7
+hP1P4+hP4P7
:
885.0
8185.0
1
685.0
6485.0
4285.0
2
5.05.02
5.05.05.0
QQQQ
QQQQQQ
985.0
9685.0
6485.0
4
785.0
7585.0
5385.0
3
5.05.05.0
5.05.05.0
QQQQQQ
QQQQQQ
Head loss balance by considering hP5P2
+hP2P6+hP6P6
=hP5P8+hP8P7
+hP7P3:
![Page 59: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/59.jpg)
02Solution of Nonlinear Equations
59
MATLAB program design:─────────────── ex2_2_3.m ───────────────function ex2_2_3%% Example 2-2-3 pipeline network analysis%clearclc%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%
![Page 60: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/60.jpg)
02Solution of Nonlinear Equations
60
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:9fprintf('Q(%i)=%7.3f \n',i,Q(i))enddisp(' ')disp('head at each location (m)')
![Page 61: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/61.jpg)
02Solution of Nonlinear Equations
61
MATLAB program design:─────────────── ex2_2_3.m ───────────────for i=1:8fprintf('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)
![Page 62: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/62.jpg)
02Solution of Nonlinear Equations
62
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)];
─────────────────────────────────────────────────
![Page 63: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/63.jpg)
02Solution of Nonlinear Equations
63
Execution results:>> ex2_2_3flow 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
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
![Page 64: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/64.jpg)
02Solution of Nonlinear Equations
64
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 100C.
Figure 2.2 A material drying process through heat conduction and forced convection.
![Page 65: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/65.jpg)
02Solution of Nonlinear Equations
65
To dry the material, the hot wind with a temperature of 85C 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:
![Page 66: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/66.jpg)
02Solution of Nonlinear Equations
66
(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)
log = 7.7423 1,554.16/(219+ ), 35 < 55 C sP T T
log = 7.8097 1,572.53/(219+ ), 55 85 C sP T T
![Page 67: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/67.jpg)
02Solution of Nonlinear Equations
67
Problem formulation and analysis:
Heat of vaporization Heat convection Heat conduction from hot plate
to the wet material
( ) ( ) ( )m m a m p mkM H H r h T T T TL
h = 0.015G 0.8
rm = 597.65 – 0.575T
Tp = 100 C
L = 0.06 mk = 1 kcal/m·hr· CTa = 85 C
G = 1.225×104 kg/hrM = 95.25 kg/m2· hr
![Page 68: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/68.jpg)
02Solution of Nonlinear Equations
68
Problem formulation and analysis:
)760(97.2802.18
PPH
)760(97.2802.18
s
sm P
PH
![Page 69: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/69.jpg)
02Solution of Nonlinear Equations
69
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%clearclc%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. )℃
![Page 70: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/70.jpg)
02Solution of Nonlinear Equations
70
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.hr\n', Rc)%
![Page 71: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/71.jpg)
02Solution of Nonlinear Equations
71
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
![Page 72: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/72.jpg)
02Solution of Nonlinear Equations
72
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
─────────────────────────────────────────────────
![Page 73: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/73.jpg)
02Solution of Nonlinear Equations
73
Execution results:>> ex2_2_4
the surface temperature of the material = 46.552C
the constant drying rate = 3.444 kg/m^2.hr
![Page 74: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/74.jpg)
02Solution of Nonlinear Equations
74
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;
![Page 75: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/75.jpg)
02Solution of Nonlinear Equations
75
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.
Component A B C
Propane 3,987.933 8.63131 0.00290
n-Butane 4,760.751 8.50187 0.00206
![Page 76: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/76.jpg)
02Solution of Nonlinear Equations
76
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.
![Page 77: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/77.jpg)
02Solution of Nonlinear Equations
77
Problem formulation and analysis:(1) Overall mass balance:
WD
WF
xxxzFD=
)(
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
![Page 78: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/78.jpg)
02Solution of Nonlinear Equations
78
Problem formulation and analysis:(1) Overall mass balance:
D=LRD /
DRL D
DLV
![Page 79: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/79.jpg)
02Solution of Nonlinear Equations
79
![Page 80: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/80.jpg)
02Solution of Nonlinear Equations
80
Problem formulation and analysis:(2) Material balance on the feed plate:
qFL=L
FqVV )1(
heat required to convert one mole of the feed into saturated vapor molar latent heat of vaporization
q =
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
![Page 81: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/81.jpg)
02Solution of Nonlinear Equations
81
Problem formulation and analysis:(3) Material balance made for the re-boiler
(4) Stripping section
LWxyV=x W
1
2
VLWxxVyV=x Wmm
m
1
11* )( mmmMVm yyyEy
![Page 82: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/82.jpg)
02Solution of Nonlinear Equations
82
Problem formulation and analysis:(5) Enriching section
(6) Feed plate
(A) Calculation of the flash point at the feed plate:
11 1
FiFi
i
zy =
qK
, i =1, 2
![Page 83: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/83.jpg)
02Solution of Nonlinear Equations
83
Problem formulation and analysis:
where
Ki = exp (Ai / T + Bi + CiT)
(B) Calculation of the flash point at the feed plate:
FiFi
i
yx =
K
12
1
=yi
Fi
niini xK=y*
12
1
=yi
ni
![Page 84: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/84.jpg)
02Solution of Nonlinear Equations
84
MATLAB program design:
![Page 85: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/85.jpg)
02Solution of Nonlinear Equations
85
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 allclc%% declare the global variables%global A B C zf qglobal A B C xc%% operation data%zf=[0.5 0.5]; % feed compositionxd=[0.9 0.1]; % distillate compositionxw=[0.1 0.9]; % composition of the bottom product F=100; % feed flow rate (mol/h)
![Page 86: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/86.jpg)
02Solution of Nonlinear Equations
86
MATLAB program design:─────────────── ex2_2_5.m ───────────────q=0.5; % q value of the feedEmv=0.7; % Murphree vapor efficiencyEe=0.2; % entrainment coefficientRD=2; % reflux ratio%A=[-3987.933 -4760.751]; % parameter A B=[8.63131 8.50187]; % parameter BC=[-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 rateW=F-D; % flow rate of the bottom productL=RD*D; % liquid flow rate in the enriching sectionV=L+D; % gas flow rate in the enriching sectionLS=L+q*F; % liquid flow rate in the stripping sectionVS=V-(1-q)*F; % gas flow rate in the stripping section%
![Page 87: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/87.jpg)
02Solution of Nonlinear Equations
87
MATLAB program design:─────────────── ex2_2_5.m ───────────────% calculating the flash point at the feed plate%Tf=fzero(@ex2_2_5f1,620); % flash pointK=exp(A/Tf+B+C*Tf);yf=zf./(1 +q*(1./K-1)); % gas phase composition at the feed platexf=yf./K; % liquid phase composition at the feed plateTf=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-boilerTw=Tw-459.6; % bubble point ( ) of the re-boiler℉%% calculating the liquid phase composition in the re-boiler
![Page 88: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/88.jpg)
02Solution of Nonlinear Equations
88
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)>Tfm=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
![Page 89: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/89.jpg)
02Solution of Nonlinear Equations
89
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;
![Page 90: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/90.jpg)
02Solution of Nonlinear Equations
90
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%
![Page 91: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/91.jpg)
02Solution of Nonlinear Equations
91
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:nfprintf('%2i %10.5f %10.5f % 10.5f %10.5f %10.2f\n',i,x(i,1),x(i,2),…y(i,1), y(i,2),T(i))endfprintf('%2i %10.5f %10.5f\n',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%
![Page 92: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/92.jpg)
02Solution of Nonlinear Equations
92
MATLAB program design:─────────────── ex2_2_5.m ───────────────plot(1 :N,x(:, 1),1 :N,x(:,2))hold onplot([m m],[0 1],'--')hold offxlabel('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),' \leftarrow\it{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 qK=exp(A./T+B+C*T);yf=zf./(1 +q*(1./K-1));
![Page 93: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/93.jpg)
02Solution of Nonlinear Equations
93
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 xcK=exp(A./T+B+C.*T);yc=K.*xc;y=sum(yc)-1;
─────────────────────────────────────────────────
![Page 94: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/94.jpg)
02Solution of Nonlinear Equations
94
Execution results:>> ex2_2_5
The bubble point and compositions at each plate.plate liquid gas temperatureno. 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.4710 0.61815 0.38185 0.77825 0.22175 142.1011 0.69448 0.30552 0.82978 0.17022 135.5012 0.77156 0.22844 0.87685 0.12315 129.1813 0.84365 0.15635 0.91688 0.08312 123.57 14 0.91688 0.08312
![Page 95: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/95.jpg)
02Solution of Nonlinear Equations
95
Execution results:>> ex2_2_5
total no. of plates= 14; the feed plate no.= 6
distillate concentration = [0.91688 0.08312]
![Page 96: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/96.jpg)
02Solution of Nonlinear Equations
96
Example 2-2-6
Analysis of a set of three CSTRs in series.
In each of the reactors, the following liquid phase reaction occurs
5.1, AA CkrRA
![Page 97: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/97.jpg)
02Solution of Nonlinear Equations
97
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.
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
![Page 98: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/98.jpg)
02Solution of Nonlinear Equations
98
Problem formulation and analysis:steady state, mass
05.11 iiiii VCkvCvC , i = 1, 2, 3
![Page 99: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/99.jpg)
02Solution of Nonlinear Equations
99
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%
![Page 100: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/100.jpg)
02Solution of Nonlinear Equations
100
MATLAB program design:─────────────── ex2_2_6.m ───────────────C=zeros(n+1,1); % initialize concentrations x=zeros(n+1,1); % initialize conversion ratesC(1)=C0; % inlet concentrationx(1)=0; % initial conversion rate for i=2:n+1VV=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 valuex(i)=(C0-C(i))/C0; % calculating the conversion rateend%% results printing%for i=2:n+1fprintf('The exit conc. of reactor %d is %.3f with a conversion rate of… %.3f.\n',i-1,C(i),x(i))
![Page 101: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/101.jpg)
02Solution of Nonlinear Equations
101
MATLAB program design:─────────────── ex2_2_6.m ───────────────end%% reaction equation%function f=ex2_2_6f(C)global v VV kk ccf=v*cc-v*C-kk*VV*C^1.5;
─────────────────────────────────────────────────
![Page 102: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/102.jpg)
02Solution of Nonlinear Equations
102
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.
![Page 103: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/103.jpg)
02Solution of Nonlinear Equations
103
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(... )
![Page 104: Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片](https://reader038.vdocuments.net/reader038/viewer/2022102323/54967ba5b47959821d8b4733/html5/thumbnails/104.jpg)
02Solution of Nonlinear Equations
104
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(... )