0% found this document useful (0 votes)
8 views

Ejemplo Gibb minimization[1]

The document provides examples of solving chemical engineering problems using MATLAB, including finding the volume of a gas, solving a system of nonlinear equations, and calculating the equilibrium composition of a reaction mixture. It details the use of functions like fzero and fsolve for numerical solutions, as well as the formulation of objective functions and constraints for optimization problems. Additionally, it introduces regression analysis concepts and probability functions related to statistics.

Uploaded by

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

Ejemplo Gibb minimization[1]

The document provides examples of solving chemical engineering problems using MATLAB, including finding the volume of a gas, solving a system of nonlinear equations, and calculating the equilibrium composition of a reaction mixture. It details the use of functions like fzero and fsolve for numerical solutions, as well as the formulation of objective functions and constraints for optimization problems. Additionally, it introduces regression analysis concepts and probability functions related to statistics.

Uploaded by

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

44 Chemical Engineering Computation with MATLAB®

>> R = 0.082054; Tc = 419.6; Pc = 396.743; T = 415; P = 207.2538;


>> a = 0.42748*R^2*Tc^2.5/Pc; b = 0.08664*R*Tc/Pc;
>> f = @(V) R*T./(V-b) - a./(V.*(V+b)*sqrt(T)) - P;
>> V0 = 0.1; V = fzero(f,V0)
V =
0.1291

We can see that V = 0.1291 liter/mol.

Example 2.10: A System of Nonlinear Equations

Find the zeros of the following three equations:

sin ( x ) + y 2 + ln z = 7

3x + 2y - z 3 = -1

x+y+z =5

Solution
We start with the definition of the function containing equations in vector form. The initial esti-
mate of a common solution should be set in advance.

>> fun = @(x) [sin(x(1))+x(2)^2+log(x(3))-7; 3*x(1)+2*x(2)-x(3)^3+1;


x(1)+x(2)+x(3)-5];
>> x0 = [0 2 2]';
>> x = fsolve(fun,x0)
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>
x =
0.6331
2.3934
1.9735

Example 2.11: Composition of the Equilibrium Mixture2

Ethane reacts with steam to form hydrogen over a cracking catalyst at the temperature of
T = 1000 K and pressure of P = 1 atm. The feed contains 4 moles of steam per mole of ethane.
The components present in the equilibrium mixture are shown in Table 2.1. The Gibbs energies
of formation (kcal/gmol) of the various components at the reaction temperature (1000 K) are also
given in Table 2.1. The equilibrium composition of the effluent mixture is to be calculated using
data given in Table 2.1. The initial guess for each component is given in the table.
This problem can be regarded as an optimization problem, which minimizes the total Gibbs
energy. The objective function to be minimized is given by

c
æ G0 n ö
å
G
minni = ni ç i + ln i ÷
RT i =1 è RT å ni ø

where
ni is the number of moles of component i
c is the total number of components
R is the gas constant
Gi0 is the Gibbs energy of pure component i at temperature T
Numerical Methods with MATLAB® 45

TABLE 2.1
Components Present in Effluent of Ethane-Steam Cracking Reactor
i Component Gibbs Energy (kcal/gmol) Feed (gmol) Effluent Initial Guess
1 CH4 4.61 0.001
2 C2H4 28.249 0.001
3 C2H2 40.604 0.001
4 CO2 −94.61 0.993
5 CO −47.942 1
6 O2 0 0.0001
7 H2 0 5.992
8 H2O −46.03 4 1
9 C2H6 26.13 1 0.001

Oxygen, hydrogen, and carbon balances should be set to find ni.

Oxygen: f1 = 2n4 + n5 + 2n6 + n8 - 4 = 0

Hydrogen: f2 = 4n1 + 4n2 + 2n3 + 2n7 + 2n8 + 6n9 - 14 = 0

Carbon: f3 = n1 + 2n2 + 2n3 + n4 + n5 + 2n9 - 2 = 0

These balance equations are constraints that can be introduced into the objective function
using Lagrange multipliers λ1, λ2, and λ3. The extended objective function is given by
c 3
æ G0 n ö
minni ,l j F = å
i =1
ni ç i + ln i ÷ +
è RT å ni ø ål fj =1
j j

All the partial derivatives of the function F with respect to ni and λj vanish at the minimum
point. For example, the partial derivative of F with respect to ni is given by
3
¶F Gi0 æ ¶f j ö
å l çè ¶n ÷ø = 0
ni ni
= + ln + 1- + ( i = 1, 2, ¼, c )
å å
c c j
¶ni RT nk nk j =1 i
k =1 k =1

fj = 0 ( j = 1, 2, 3)
Solution
From fj = 0 (j = 1, 2, 3), we have

f1 = 2n4 + n5 + 2n6 + n8 - 4 = 0

f2 = 4n1 + 4n2 + 2n3 + 2n7 + 2n8 + 6n9 - 14 = 0

f3 = n1 + 2n2 + 2n3 + n4 + n5 + 2n9 - 2 = 0

å
c
Let ns = nk in the relation (∂F/∂ni) = 0 (i = 1, 2,  …, c) and transform logarithms into exponen-
k =1
tial functions to avoid taking logarithms of very small numbers. Applying Gibbs energy data given
in Table 2.1, we have following nonlinear equations:

é æ 4.61´ 103 n öù
n1 - ns exp ê - ç + 1- 1 + 4l 2 + l 3 ÷ ú = 0,
êë è RT ns ø úû
46 Chemical Engineering Computation with MATLAB®

é æ 28.249 ´ 103 n öù
n2 - ns exp ê - ç + 1- 2 + 4l 2 + 2l 3 ÷ ú = 0,
êë è RT ns ø úû

é æ 40.604 ´ 103 n öù
n3 - ns exp ê - ç + 1- 3 + 2l 2 + 2l 3 ÷ ú = 0,
êë è RT ns ø úû

é æ -94.61´ 103 n öù
n4 - ns exp ê - ç + 1- 4 + 2l1 + l 3 ÷ ú = 0,
êë è RT n s ø úû

é æ -47.942 ´ 103 n öù
n5 - ns exp ê - ç + 1- 5 + l1 + l 3 ÷ ú = 0,
êë è RT ns ø úû

é æ n öù
n6 - ns exp ê - ç 1- 6 + 2l1 ÷ ú = 0,
ë è ns øû

é æ n öù
n7 - ns exp ê - ç 1- 7 + 2l 2 ÷ ú = 0,
ë è ns øû

é æ -46.03 ´ 103 n öù
n8 - ns exp ê - ç + 1- 8 + l1 + 2l 2 ÷ ú = 0,
êë è RT n s ø úû

é æ 26.13 ´ 103 n öù
n9 - ns exp ê - ç
RT
+ 1- 9 + 6l 2 + 2l 3
ns
(
÷ ú = 0, R = 1.9872 cal / ( gmol × K ) )
êë è ø úû

There are 12 unknown variables (ni (i = 1, 2,  …, 9), λj (j = 1, 2, 3)) and 12 equations. First, we
construct the MATLAB® function rxnfun, which defines the system of nonlinear equations in vec-
tor form. In this function, all the unknown variables are represented in terms of xi (i = 1, 2,…, 12)
(i.e., xi = ni (i = 1, 2,  …, 9) and xi = λi(i = 10, 11, 12)).

function f = rxnfun(x,T)
R = 1.9872; ns = sum(x(1:9));
f(1,1) = 2*x(4)+x(5)+2*x(6)+x(8)-4;
f(2,1) = 4*x(1)+4*x(2)+2*x(3)+2*x(7)+2*x(8)+6*x(9)-14;
f(3,1) = x(1)+2*x(2)+2*x(3)+x(4)+x(5)+2*x(9)-2;
f(4,1) = x(1)-ns*exp(-(4.61e3/(R*T)+1-x(1)/ns+4*x(11)+x(12)));
f(5,1) = x(2)-ns*exp(-(28.249e3/(R*T)+1-x(2)/ns+4*x(11)+2*x(12)));
f(6,1) = x(3)-ns*exp(-(40.604e3/(R*T)+1-x(3)/ns+2*x(11)+2*x(12)));
f(7,1) = x(4)-ns*exp(-(-94.61e3/(R*T)+1-x(4)/ns+2*x(10)+x(12)));
f(8,1) = x(5)-ns*exp(-(-47.942e3/(R*T)+1-x(5)/ns+x(10)+x(12)));
f(9,1) = x(6)-ns*exp(-(1-x(6)/ns+2*x(10)));
f(10,1) = x(7)-ns*exp(-(1-x(7)/ns+2*x(11)));
f(11,1) = x(8)-ns*exp(-(-46.03e3/(R*T)+1-x(8)/ns+x(10)+2*x(11)));
f(12,1) = x(9)-ns*exp(-(26.13e3/(R*T)+1-x(9)/ns+6*x(11)+2*x(12)));
end

As the initial estimate, we choose x0 = [0.001 0.001 0.001 0.993 1 0.0001 5.992 1 0.001 10
10 10]. Zeros of the nonlinear equation system can be found by using the built-in function fsolve.
The script file ethanrxn shows the solution procedure.
Numerical Methods with MATLAB® 47

% ethanrxn.m: ethane-steam cracking reaction


x0 = [0.001 0.001 0.001 0.993 1 0.0001 5.992 1 0.001 10 10 10]';
T = 1000;
[x, fval] = fsolve(@rxnfun, x0,[],T);
comp = {'CH4','C2H4','C2H2','CO2','CO','O2','H2','H2O','C2H6'};
lamda = {'lambda1','lambda2','lambda3'};
fprintf('\n i\tComp. \t Initial Val.\t\tFinal val.\n');
for k = 1:length(x)-3
fprintf('%d\t%s \t%12.9f\t%12.9f\n',k,comp{k},x0(k),x(k));
end
fprintf('\n i\tLambda\tInitial Val.\tFinal val.\n');
for i = k+1:length(x)
fprintf('%g\t%s\t\t%4.1f\t%15.9f\n',i,lamda{i-length(comp)},x0(i),x(i));
end

Running this script gives

>> ethanrxn
Equation solved.
fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.
<stopping criteria details>

i Comp. Initial Val. Final val.


1 CH4 0.001000000 0.081717614
2 C2H4 0.001000000 0.000000172
3 C2H2 0.001000000 0.000000000
4 CO2 0.993000000 0.664820888
5 CO 1.000000000 1.253460254
6 O2 0.000100000 0.000000000
7 H2 5.992000000 5.419665106
8 H2O 1.000000000 1.416897971
9 C2H6 0.001000000 0.000000450

i Lambda Initial Val. Final val.


10 lambda1 10.0 24.051830977
11 lambda2 10.0 0.051093350
12 lambda3 10.0 1.168410847

2.3 REGRESSION ANALYSIS
2.3.1 Introduction to Statistics
Let N designate the total number of items in the population under consideration, n the number of
items contained in the sample taken from the population (0 ≤ n ≤ N), and mj (j = 1, 2, …, M) the
number of times the value of xj occurs. The probability of occurrence is defined by the number of
occurrences of xj divided by the total number of observations as

mj
Pr ( X = x j ) = lim = p( xj )
n® N m

For a discrete random variable, p(xj) is called the probability function, and it has the following
properties:
M

0 £ p ( x j ) £ 1, åp ( x ) = 1
j =1
j

You might also like