You are on page 1of 10

Cain Department of Chemical Engineering

210 Chemical Engineering, South Stadium Road


Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

Midterm Exam I
Feb 27, 2014

CHEG 2176 Mathematical Modeling of Chemical Engineering Systems

Spring 2014

(Closed book examination)

I pledge that I have neither given nor received any unauthorized assistance on this exam.
________________________

____________________________

Student Name

1. MATLAB

(Student Signature)

25 points

What would the following sequence of commands produce?


>>a=8.7
>>b=single(a)
>>c=a-b
1.9073e-07

or

What will the class of c be?

[circle the correct one]

_Single_________________________

The Colon operator: What will the following commands produce as output?
>>i=21:-1:15

_21 20 19 18 17 16 15 ______________________

>>length(i) ___7________________________________________________
>>j=[0.3:0.2:1.2] _____________________________________________
j =
0.3000
0.5000
0.7000
0.9000
1.1000
>>k=i-j
______________________________________________________
Error using Matrix dimensions must
agree
>>k=-(12:-1:8) -12 -11 -10 -9 -8
>>k=-15:-1:20 Empty matrix: 1-by-0
Calculations past maximum and minimum ranges, NaN, Inf and others

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

>>realmax(single)*4 Inf
>>realmin('single')-4 -4
Precedence ordering
>>8+4^2--1/3*3

25

>>8+4^2---1/3*3

23

diag function and its use. Let A=[1 2 3;4 5 6;7 8 9];b=[1;1;1] or = [ ] , = []

>>diag(A) ___________________________________________________
1
5
9
>>diag(diag(A)) _____________________________________________
1
0
0
0
5
0
0
0
9

Array addressing/manipulation. Let A=[7 8 9;4 5 6;1 2 3;] or = [ ]

______________________________________

>> A(2:3,3:-1:2)
ans =
6
3

5
2

>> A(3:2,3:-1:2)
______________________________________
Empty matrix: 0-by-2
>>fliplr(A)

_____________________________________________

ans =
9
6
3

8
5
2

7
4
1

>>sum(A) _________________________________________________
12
15
18

Logical:

2|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

Let the following variables be the only variables defined in the workspace.
A=[1 2;3 4 ]
B=[2 4; 3 5 ]
What will the following expressions produce in MATLAB?
A==B
ans =
0
1

0
0

________________________________________________

A~=B
ans =
1
0

1
1

________________________________________________

~(A>=B)
ans =
1
0

1
1

_________________________________________________

(A>2 & A<5)


ans =
0
1

0
1

_________________________________________________

(A>2 | B<5)
ans =
1
1

1
1

_________________________________________________

3|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

Determine the number of times the for loop will be executed in


each case below. What will be the output.
for time=1:-0.2:0
fprintf('Time => %g \n',time)
end
Six times
Time => 1
Time => 0.8
Time => 0.6
Time => 0.4
Time => 0.2
Time => 0
________________________________________________

if (all(B>0))
display(All elements are positive)
end
All elements are positive
________________________________________________

4|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

2. Pipeline network turbulent flow 25 points

Consider turbulent flow through the network shown above. The governing equations are the
pressure drop equations for each pipe element i j and the mass balance equation at each
node. They are given for laminar flow by,
2
=

Where = .02 .

The mass balance at node 2 for example is given by,


2
2
2
12
12 = 23
23 + 24
24
Similar balance equation applies at each of the other nodes, taking proper account of the
direction of flow.
Element
12
23
24
34
35
46
0.1
0.08
0.08
0.1
.09
.09
(m)
1000
800
800
900
1000
1000
(m)
(a) It is desired to solve the problem using fsolve in MATLAB for 1 = 30,000 , 5 =
6 = 10, 000
Arrange the unknowns as = [2 3 4 12 23 24 34 35 46 ]. A MATLAB
function stored in file PipeTurb.m is shown. Study it. Find at least five errors in the
functions. Identify them and correct them.

5|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

function PipeTurb
%x=[p_2 p_3 p_4 v_12 v_23 v_24 v_34 v_35 v_46]
%Provide the guess vector
options=optimset('Display','off','TolFun',1.e-12);
x=[25000 20000 20000 ones(1,7)]
x=fsolve(@PipeF,x,options)
res=PipeF(x);
fprintf(1,'Solution for turbulent flow\n\n')
for i=1:9
fprintf(1,'x(%2i)= %16.6e; res(%2i)= %16.6e\n', i,x(i),i,res(i) )
end
end
%==============================
function g f =PipeF(x)
l12=1000; l23=800; l24=800; l34=900; l35=1000; l46=1000; %Lengths
d12=0.10; d23=0.08; d24=0.08; d34=0.10; d35=0.09; d46=0.09; %Diameters
%part
p1=30000; p5=10000; p6=100000; %Pressures
% Alphas
Areas
a12=.02*l12/d12; aa12=pi*d12^2/4;
a23=.02*l23/d23; aa23=pi*d23^2/4;
a24=.02*l24/d24 3; aa24=pi*d24^2/4;
a34=.02*l34/d34; aa34=pi*d34^2/4;
a35=.02*l35/d35; aa35=pi*d35^2/4;
a46=.02*l46/d46; aa46=pi*d346^2/4;
%Load the guess vector into appropriate variables.
p2=x(1); p3=x(2);p4=x(3);
v12=x(4); v23=x(5); v24=x(6);v34=x(7);v35=x(8);v46=x(9);
%Assemble the equations
f(1) = p1 - p2 -a12*v12^2;
f(2) = p2 - p3 -a23*v23^2;
f(3) = p2 - p4 -a24*v24^2;
f(4) = p3 - p4 -a34*v234^2;
f(5) = p3 - p5 -a35*v35^2;
f(6) = p4 - p6 -a46*v46^2;
f(7)=d12^2*v12 - d23^2*v23 - d24^2*v24;
F f(8)=d23^2*v23 a d34^2*v34 - d35^2*v35;
f(9)=d24^2*v24 + d34^23*v34 - d46^2*v46;
end

6|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

3. Flow in parallel pipelines (2+3+ 20=25 points)

A pipe carrying water splits into two segments at node P and joins back at node Q. Properties
of water are: = 1000 kg/m3 , = 0.001 Pa. s. Here is the density of the water and is
the viscosity of water. The lengths ( ), diameters ( ), roughness ( ) for the two pipe
segments between P and Q, as well as the total flow rate are as shown in figure. The
problem is to determine the individual velocities (1 , 2 ) in each of the pipe segments 1 and
2. The equation to be satisfied is obtained based on the fact that the pressure drop between
points P and Q is the same no matter which path the fluid takes. This principle leads to the
following equation.
12

1 (1 ) 1

22

= 2 (2 ) 2

(1)

Where (1 , 2 ) are the velocities in the two pipes and (1 , 2 ) are called the friction factors
given by the following Churchill equation.
1/12

8 12
1
( ) = 8 [( ) +
]
( + )1.5

where
= [2.457 ln ((7/(

1
0.9
)) +0.27( /

16

)] , = [
)

37530 16

and =

Finally the mass balance equation at the nodes (P or Q) provides another equation as,

(12 1 + 22 2 ) =
4

(2)

(a) Is it a linear or nonlinear problem?


Nonlinear
(b) Identify the dependent variables for a given and the corresponding equations that you
would solve to get the unknowns.
x=[v_1 v_2]
Eqns to solve are (1) and (2)

7|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

(c) For the case = [1000 900], = [0.1 0.09], it is required to find that value of
which makes 1 = 2 using fsolve The following MATLAB functions are claimed to
solve this problem. Will it solve the problem? Explain? There are several errors in the
functions find at least 5 errors and fix them.
It is posed as three unknowns in three equations. So it will work. The three unknowns are
= [1 2 ]
The three equations are:
1 12
2 22
(
)
(
)
1 = 1 1
2 2
=0
1 2
2 2

2 = (12 1 + 22 2 ) = 0
4
3 = 1 2 = 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

function MidP1
%% Problem - parallel pipe using "fsolve"
%unknown vector x=[v1 v2 qt]
clear;clc
options=optimset('TolFun',1.e-4);
sol=fsolve(@ParrPipe,[1 1 0.002],Options);
fprintf('Velocity (1) %g \nVelocity(2) %g \nQt

%g \n',sol);

end
function f=ParPipe(x)
%unknown vector x=[v1 v2 qt]
v(1)=x(1);
v(2)=x(2);
qt=x(3);
L=[1000 900]; %m
D=[0.1 0.09]; %m
e=[0.000046 0]; %Roughness in meters
rho=1000;
%density kg/m^3
mu =0.001;
%viscosity Pa.s
%Note that the following are all vectors: area, Re, A, B, ff,
area=(pi/4)*D.^2; %area
Re = (D .*v)*rho/mu;

8|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

29
30
31
32
33
34
35

A=(2.457*log(1.0 /((1 7./Re).^0.9 + 0.27*(e./D))) ).^(16);


B=(37530./Re).^16;
ff= 8*( (8.0./Re).^12 + 1.0./(A+B).^1.5 ).^(1/12);
f(1)=ff(1)*(L(1)/D(1)) * v(1)^2/2 + - ff(1 2)*(L(2)/D(2)) * v(2)^2/2 ;
f(2)=pi*(D(1)^2*v(1)+D(2)^2*v(2))/4 Q qt;
f(3)=v(1)-v(2);
end

9|Page

Cain Department of Chemical Engineering


210 Chemical Engineering, South Stadium Road
Baton Rouge, LA, 70803, USA
K. Nandakumar
Phone (Office): +1 225 578 2361, Cell: +1 225 278 7174, e-mail: nandakumar@lsu.edu

4. Differential equation model

(2+3+2+15+3=25 points)

Consider the following third order differential equation model.


3
2

2
+
7
+5
+ 10 = 5 sin()
3
2

( = 0) = 0;
|
= 1;
=0
One is interested in finding the solutions ()

2
|
=0
2 =0

(a) Is this an initial value problem or a boundary value problem?


IVP
(b) What are the independent and dependent variables?
Independent => t
Dependent => u(t)
(c) Is it a linear or non-linear model?
nonlinear
(d) Convert this into a system of first order differential equations together with the
appropriate conditions.
Let
1 =
2 =
3 =

1 = 2 = 1
2 = 3 = 2
3 = 5 sin() 10 1 5 1 2 712 3 = 3
1 (0) = 0
2 (0) = 1
3 (0) = 0
(e) What MATLAB tool will you use to solve the above problem?
Ode45

10 | P a g e

You might also like