Sei sulla pagina 1di 9

ChE 390 Experiment 5 MATLAB I 1/9

Department of Chemical Engineering



ChE 390 Experiment 5: MATLAB Module I

Process Model Discrimination and Simulation of Pipeline Network


5.1. Lab Introduction

The design, simulation, and optimization of many chemical engineering processes often come down to a
series of constrained or non-constrained nonlinear process equations. Solving these nonlinear equations
requires a computing tool that is powerful, robust, and versatile in computing and programming. MATLAB is
such a computing tool which readily meets all aforementioned requirements in solving large-scale non-
constrained and constrained nonlinear equations. As well, MATLAB has other built-in functions such as
regression and optimization functions which enable the construction of reliable process models out of
experimental data to become a relatively easy routine task. In terms of engineering learning and research,
MATLAB offers a variety of capability and flexibility for dealing with all types of complex and real chemical
engineering problems with minimal programming effort required, and can therefore greatly enhance and
extend the understanding of basic chemical engineering theories and their applications to real processes.
In this computing lab, you will use MATLAB functions of nonlinear regression and nonlinear equation solver
to discriminate process models based on experimental data and to simulate pipeline network. The main
objectives of this lab are:

To reinforce the understanding of chemical engineering concepts by applying them to formulating
process equations for complex chemical engineering process.
To enhance engineering problem-solving skills by using MATLAB functions to discriminate process
models and find the solutions to nonlinear process equations.
To familiarize with MATLAB programming skills in functions and sub-functions.


5.2. Lab Problem Statement

Problem 1. Process Model Discrimination

The prediction of vapor-liquid equilibrium (VLE) of a non-ideal solution depends on the accurate prediction
of activity coefficients of components in the liquid mixture. Table 1 lists three most commonly used model
equations for the prediction of activity coefficients of a non-ideal binary system. In these equations, the
parameters, s A' , s B' , and s G' , are adjustable parameters which must be determined from an
experimentally derived set of vapor-liquid equilibrium data (i.e., values of activity coefficients
1
and
2
at
different liquid compositions
1
x and
2
x ). For a specified system, one model equation is usually more
accurate than others for predicting the activity coefficients. Hence, there is a need to discern the best model
for a given system based on the experimental data. This problem requires you to use the most reliable
regression method, nonlinear regression, with statistical inferences to discriminate the thermodynamic
models and determine the confidence interval of the model parameters for a binary system of toluene and
acetic acid based on experimental VLE data.

ChE 390 Experiment 5 MATLAB I 2/9



Table 1. Model equations for binary liquid activity coefficients.

Model

Model Equations



Margules Equation
| |
1 12 21 12
2
2 1
) ( 2 ln x A A A x + =

| |
2 21 12 21
2
1 2
) ( 2 ln x A A A x + =



van Laar Equation
| |
2
2 21 1 12
12
1
) / ( 1
ln
x B x B
B
+
=

| |
2
1 12 2 21
21
2
) / ( 1
ln
x B x B
B
+
=


Wilson Equation
|
|
.
|

\
|
+

+
+ + =
21 1 2
21
12 2 1
12
2 12 2 1 1
) ln( ln
G x x
G
G x x
G
x G x x

|
|
.
|

\
|
+

+
+ =
21 1 2
21
12 2 1
12
1 21 1 2 2
) ln( ln
G x x
G
G x x
G
x G x x


Problem 2. Pipeline Network Simulation

Pipeline networks such as water distribution systems, natural gas distribution systems, and chemical
distribution systems in various chemical plants are some of most encountered engineering systems. Figure
1 shows a typical pipeline network for chilled water distribution at 6C.


Figure 1. Schematic of water pipeline network

ChE 390 Experiment 5 MATLAB I 3/9



The supply pressure at the exit of the pump (node 0) is Pa
5
10 5 . 6 above the atmospheric pressure.
The chilled water can be withdrawn from nodes 1~7 at variable flow rates if needed, and the unused chilled
water is discharged at the atmospheric pressure at the end of the pipeline (node 9). All the pipes are 6-inch
schedule 40 steel with an inside diameter of m 154 . 0 and roughness of m
5
10 62 . 4

= . The
equivalent lengths of the pipes connecting different nodes are as follows: m L 400
01
= ;
m L L L 800
45 23 12
= = = ; m L 1500
34
= ; m L L L L L 750
78 68 57 56 27
= = = = = ; m L 780
18
= and
m L 400
89
= . The viscosity and density of water at 6C are s Pa
3
10 473 . 1 and
3
/ 0 . 1000 m kg ,
respectively.

Based on the results from computation tasks in Section 5.4, you need to answer the following questions in
your lab final report:
1. In the report introduction, give at least two examples from your core courses where process
models or correlations need to be determined by nonlinear regression.
2. Tabulate the parameter values and their statistical inferences (
2
R

values, SSE , and confidence
intervals) for each model, and determine the best model for toluene and acetic acid system.
Comment on your selection based on above results and residual plots.
3. Compare and discuss the simulation results obtained by using the explicit correlation (Churchill
equation) and using the implicit correlation (the Colebrook and White equation) for the two
operation cases. Why do we want to use the implicit correlation (the Colebrook and White
equation) when the explicit correlations (e.g. Churchill equation) are available?
4. Compare and discuss all the steady state flow rates and pressures for the two operation cases.
5. Based on your experience, what recommendation do you have to improve the solution process of
this computing lab?

5.3. Theories and Formulation of Process Equations for MATLAB
5.3.1. Process Model Discrimination Using Nonlinear Regression

Nonlinear regression is based on the same principle, as linear regression, of minimizing the sum of squared
errors (SSE) between experimentally measured values and model predicted values, i.e.,
2
, , exp
1
) (
i pred i t
N
i
y y SSE =

=


Where

i t
y
, exp

denotes the experimental value at independent variable
i
x ; and
i pred
y
,
is the corresponding
value predicted by a model ) , (
,

i i pred
x f y = with being the model parameters.

Since we have two sets of measured activity coefficients in this binary system, we can combine them to
create a single measured quantity or an objective function. Considering the physical significance of activity
coefficient, a simple combination of the two activity coefficients can be used for nonlinear regression
analysis, i.e.,
2 1
+ =

(1)


ChE 390 Experiment 5 MATLAB I 4/9



Alternatively, a rather more meaningful thermodynamic quantity defined by the activity coefficients and
referred to as the excess Gibbs free energy, g , can be used for the nonlinear regression,

2 2 1 1
ln ln x x g + =

(2)

With all the experimentally measured values for the problem, the MATLAB function nlinfit can be used to
compute the values of the model parameters, and the function nlparci can be used to estimate the
confidence level of the model parameters. Check Page 7 or MATLAB help for the usages of those
functions.

5.3.2. Pipeline Network Simulation

One of the governing equations for fluid system design and simulation in chemical engineering processes is
the general mechanical energy balance equation, which is, for an incompressible fluid between any two
points, written as,
0 ) ( ) (
2
1
21
1 2
2
1
2
2
= + +

+ +
s
W F
P
z z g v v

(3)

Where

v
:
Fluid velocity in

s m/
.

z
: Fluid position in m.

1 2 21
P P P = : Pressure loss inPa .

:
Fluid density in

3
/m kg
.

F : Sum of energy loss per unit fluid mass due to friction in
2 2
/ s m .

s
W : Mechanical energy to the fluid per unit fluid mass in
2 2
/ s m .

Equation 3 indicates that the pressure loss in the absence of mechanical energy ( 0 =
s
W ) is a result of
friction loss of fluid flow, and is therefore often predicted through friction factor. For isothermal fluid flow in
pipes, the friction factor, f , is defined as the ratio of inertia energy to kinetic energy of flowing fluid,

L v
PD
v
DL
D P
v
f
w
2
2
2
2
2
) 2 / /(
4 /
2 /

= =
(4)


Where

P : Pressure loss in Pa .

f : The Fanning friction factor.

L
: Pipe length in m.

D: Pipe diameter in m.

Thus, the pressure drop can be calculated through friction factor for a flow system defined in terms of flow
rate, pipe geometry, and fluid properties, i.e.,

D
L
v f P
2
2 =

(5)



ChE 390 Experiment 5 MATLAB I 5/9



The friction factor for different flow regimes is generally correlated in terms of pipe surface roughness
factor, in m

and the Reynolds number which is defined as,

vD
= Re

(6)
With being the fluid viscosity in s Pa .

Table 2. Common correlations of friction factor in pipes
Equation formula

flow range

accuracy
rating*
Hagen-Poiseuille
Re
16
= f

2100 Re

Laminar flow
A
Nikuradse
equation (1932)

4 . 0 ) log(Re 0 . 4
1
= f
f

6
10 4 . 3 Re 3000 < <

Smooth pipe,
0 / = D

B
Blasius
25 . 0
Re
079 . 0
= f

5
10 Re 4000 < <

Smooth pipe and
turbulent flow
B
Colebrook and
White equation
(1939)
28 . 2 )
Re
647 . 4
log( 0 . 4
1
+ + =
f D f


7
10 0 . 1 Re 4000 < <

Turbulent flow (also used
for transition flow with no
better correlations
A

Churchill Equation
(1977)
| |
12 / 1
2 / 3 12
) /( 1 Re) / 8 ( 2 B A f + + =

16
9 . 0
) / ( 27 . 0 Re) / 7 (
1
ln 457 . 2
(

+
=
D
A


16
Re) / 37530 ( = B

7
10 0 . 1 Re 0 < <

Smooth and rough pipes,
and all flow regimes.

C
* Accuracy rating from the highest to lowest in alphabetical order.


Table 2 summarizes some explicit and implicit correlations commonly used for predicting the friction factor
in pipes for different flow regimes. Once the friction factor for a flow system is known, the pressure drop can
be determined using Equation 5, and Equation 3 can be solved for design and simulation.

Just like any other chemical engineering problems, the underlying equations we can rely on to formulate
the process equations for MATLAB simulation in the pipeline network are mass balance equation and the
energy balance equation. For the pipeline network in Figure 1, the steady-state mass balance requires the
sum of the flow rates at each node must be zero. The steady-state energy balance (Equation 3) requires
that the sum of all pressure drops surrounding a closed loop must be balanced and therefore be zero. As
such, we can use 8 nodes and 4 loops in the network system to come up with 12 equations with 12
unknowns to be solved.


ChE 390 Experiment 5 MATLAB I 6/9



Mass balance equations at the 8 nodes:
Node 1: 0 1
8 2 1
= qs q q q
Node 2: 0 2
7 3 2
= qs q q q

Node 3: 0 3
4 3
= qs q q
Node 4: 0 4
5 4
= qs q q
Node 5: 0 5
6 9 5
= + qs q q q

Node 6: 0 6
10 6
= qs q q


Node 7:
0 7
11 9 7
= qs q q q

Node 8:
0
12 11 10 8
= + + q q q q


Where qsi is the side flow withdrawn from node i .

Energy balance equations for all 4 loops:
Loop 1:
0
89 18 01
= + +
pump
P P P P
Loop 2:
0
78 27 12 18
= P P P P
Loop 3:
0
45 34 23 57 27
= + P P P P P
Loop 4: 0
68 56 57 78
= P P P P


As shown above, the pressure drop in each pipe section is related to its flow rate and friction factor
(Equation 5), and the friction factor can be evaluated based on Reynolds number or flow rate and
appropriate correlation in Table 1, so essentially, we have 12 equations for 12 unknown flow rates, which
suffice to be solved for the flow rates first, then pressure at each node can be calculated sequentially from
the pressure at the exit of the pump.

5.4. Computing Tasks and Recommended MATLAB Functions

5.4.1. Lab Computation Tasks

The lab includes the following computation tasks:

Task 1. Use the experimental VLE data of toluene and acetic acid binary system at a pressure of 20 kPa in
Excel file on the course page of LEARN to do the following calculations:
a. Use Equation 2 and nlinfit to determine the values of the two parameters in the Margules
model and their 95% confidence intervals. Calculate the goodness of the fit by computing
2
R
value.
b. Use Equation 1 and nlinfit to determine the values of the two parameters in the Margules
model and their 95% confidence intervals. Which objective function produces better result
(Hints: compare
2
R

values, residual plots, sum of squared errors, and confidence intervals
between part (a) and part (b)).
c. Repeat (a) with the van Laar and Wilson model, respectively. Which model best represents the
system and why?


ChE 390 Experiment 5 MATLAB I 7/9



Task 2. Use the pipeline network theory to do the following calculations for two operation cases:
Case 1: the side flows from all side flow nodes: min / 120 7 6 5 2 1 L qs qs qs qs qs = = = = =
and min / 240 4 3 L qs qs = = .
Case 2: the side flows from all side flow nodes: min / 120 7 6 5 2 1 L qs qs qs qs qs = = = = =
and min / 360 4 3 L qs qs = = .
a. Compute all the steady-state flow rates and pressures at all nodes using the explicit Churchill
equation for the two operation cases.
b. Repeat part (a) using the Colebrook and White equation (note that if any flow falls into laminar
region, the Hagen-Poiseuille equation should be used).



5.4.2. Recommended MATLAB Functions

The following MATLAB functions should work adequately for these problems, although there are
other MATLAB functions that may also suitable.

1. MATLAB Function for Nonlinear Regression nlinfit

Function nlinfit syntax:

) , , , ( inf
o
b fun y X it nl b =

) , , , , ( inf ] , , , , [ options b fun y X it nl MSE COVB J resid b
o
=

Where
b : 1 p

vector of p parameters or coefficients in the nonlinear model equation.

X : m n

matrix of n observations for mindependent variables

y : 1 n

vector of n observations for the dependent variable.

fun : The m file that specifies the nonlinear model in the form of ). , ( X b fun y =

o
b : The initial guessed vector of b .

resid : Residuals.


J : Output J acobian matrix.

COVB: The estimated covariance matrix.
Of all the computation tasks, Task 1a and 2a are in-class exercise which is due at 11:59
P.M. one day after your lab session, the remainder of the computation tasks is the lab
assignment which is due two weeks after the lab session.

For the in-class exercise, you only need to submit your MATLAB script file and a
summary of your results. For the assignment, you need to submit your code in
MATLAB script file and a lab report in word file that must include a summary and
discussion of your results as well as answers to all the questions in Section 5.2.



ChE 390 Experiment 5 MATLAB I 8/9




MSE : The mean squared errors.

options : Structure which uses optimset to set tolerance, among other parameters, e.g.,
) 12 1 , ' (' = e TolFun optimset options

With the known residuals and J acobian matrix, the confidence interval of the estimated
coefficients can be calculated using MATLAB function nlparci,

) , , ( J resid b nlparci ci =


2. MATLAB Function for Solving Single Nonlinear Algebraic Equation fzero

Function fzero syntax:
) , (
o
x fun fzero x =

) , , ( ] , [ options x fun fzero fval x
o
=

Where

x
:
Unknown scalar.


fun : The m file that specifies the nonlinear equation in the form of 0 ) ( = x f .

o
x : Initial guessed values of x .

fval : Values of the function at solution x .

options : Structure which uses optimset to set tolerance, among other parameters, e.g.,
) 12 1 , ' ' , 4 1 , ' (' = e TolFun e TolX optimset options

3. MATLAB Function for Solving a Series of Nonlinear Algebraic Equation fsolve

Function fsolvesyntax:

) , (
o
x fun fsolve x =

) , , ( ] , [ options x fun fsolve fval x
o
=

Where

x
:
Vector of unknowns.


fun : The m file that specifies the nonlinear equation in the form of 0 ) ( = x f .

o
x : Vector of initial guessed values of x .

fval : Values of the functions at solution x .

options : Structure which uses optimset to set tolerance, among other parameters, e.g.,
) 12 1 , ' ' , 4 1 , ' (' = e TolFun e TolX optimset options

5.5. Some Useful MATLAB Programming Tips and Solution Techniques

1. The goodness or adequacy of the fit for nonlinear regression,
2
R , can be calculated from the
MATLAB output as follows:
First calculate the Sum of Squared Errors (SSE),

ChE 390 Experiment 5 MATLAB I 9/9



) 2 ).^ (( y y sum SSE
pred
=

Where
pred
y is the vector of model predicted values at parameter solution, and

y is the
corresponding vector of experimental values.
Next, calculate the Total Sum of Squares (SST),
) 2 ).^ (( y y sum SST =

Where y is the average value of the experimentally measured y .
Last,
2
R is defined and calculated by,

SST
SSE
R =1
2


2. To take advantage of the array and matrix operations in MATLAB, we can assign the lengths of all
the 12 pipe sections into a vector which matches flow rate vector, i.e.,
] [
89 78 68 57 18 27 56 45 34 23 12 01
L L L L L L L L L L L L L =


Which matches with the unknown flow rate vector,
] ) 12 ( ) 11 ( ) 10 ( ) 9 ( ) 8 ( ) 7 ( ) 6 ( ) 5 ( ) 4 ( ) 3 ( ) 2 ( ) 1 ( [ q q q q q q q q q q q q q =

Now according to Table 1 and Equation 5, we need to use the same set of equations to evaluate
friction factor and then pressure drops in pipes based on chosen correlation and flow regime. It is
therefore much more convenient and efficient to write a MATLAB sub-function for evaluating friction
factor and pressure drop. The sub-function should include the following equations:
1.
D
i q
i

) ( 4
) Re( =

2. Proper correlation in Table 1 to evaluate ) (i f
3.
D
i L
D
i q
i f
D
i L
i v i f i P
) ( ) ( 4
) ( 2
) (
) ( ) ( 2 ) (
2
2
2
|
.
|

\
|
= =



Once all the pressure drops are evaluated in terms of corresponding flow rates, the above simulation
equations can be solved simultaneously using the MATLAB fsolve function for the seven flow rates.
The pressure at all nodes can then be calculated sequentially as,

01 1
P P P
pump
=

(dont forget to add atmospheric pressure).

12 1 2
P P P =

23 2 3
P P P =

34 3 4
P P P =

.
18 1 8
P P P =

Potrebbero piacerti anche