Académique Documents
Professionnel Documents
Culture Documents
Prepared by
Dr. Hong-ming Ku
q, P, T
P, V, T
(a) Let V, P, and T be the volume, the pressure, and the temperature of the drum,
respectively. Write a model (one differential equation) to describe how the
pressure in the tank varies with time. Assume ideal gas and isothermal
operation.
(b) Solve for P analytically using the following data:
qf = 2.0 + 0.1t kmol/min
V = 50 m3
R = 8314 m3-Pa/kmol-K
q = 3.0 kmol/min
T = 300 K
if the drum initially contains 10 kmol of methane. Assuming that the vessel was
built to withstand a maximum pressure of 50 atm, how long can we run this
operation before the inlet gas flow must be shut off?
(c) The ideal gas law is a poor assumption because of high pressure in the drum.
Suppose the methane gas stream obeys the virial equation of state as follows:
PV
B (T ) C (T ) D (T )
= 1+
+ 2 +
+ .....
3
RT
V
V
V
For simplicity, we will truncate all terms after the second virial coefficient B(T).
Repeat the calculations in Part (b). For methane, B(T=300 K) = 0.04394
m3/kmol.
Solution:
(a) Ideal gas law:
Mass balance:
PV = RT
or
PV = nRT
where n is the number of moles of gas in the drum and R is the
universal gas constant
Rate of accumulation = rate in rate out
dn/dt = qf q
d(PV/RT)/dt = qf q
49884(0.1t 1.0) dt
= 49884 (0.05t2 t) 0
= (RT/V)(1 + 0.08788n/V)(dn/dt)
dn/dt = qf q
dP/dt = [(RT/V)(1 + 0.08788n/V)]( qf q)
A = 578.9575
P = 1.4190939x107 {[578.9575 + (0.05t2 t)]2/323712.6368 1}
5.06625 x 106 = 1.4190939x107 {[578.9575 + (0.05t2 t)]2/323712.6368 1}
0.357 = [578.9575 + t(1 0.05t)]2/323712.6368 1
578.9575 + t(1 0.05t) = 662.7805
0.05t2 t 83.823 = 0
t = 52.15 minutes
The concentration of hydrogen ion (H+) in the water determines its acidity. A
higher concentration of H+ means higher acidity. The acidity of a rain or cloud
droplet is usually quantified by the pH of the droplet, which is related with the
concentration of H+ ([H+]) using the following equation: pH = log10[H+]. Thus,
lower pH means higher acidity.
Based on the above equilibrium relationships and the principle of charge balance in
an aqueous solution, the [H+] in the CO2/H2O system (and thus the pH) can be
determined using the following equation:
where pCO2 is the partial pressure of CO2 in the atmosphere (in units of atm);
KH,CO2, Ka1,CO2, Ka2,CO2 are Henrys law constant (in units of M/atm), and first and
second acid dissociation constants for CO2, respectively, and Kw is the water
dissociation constant (which varies with temperature). For a given value of the
partial pressure of CO2, the concentration of H+ and thus the pH can be
determined.
(a) Given that Kw = 1.810-14 (when T = 30C) KH,CO2 = 10-1.46, Ka1,CO2 = 10-6.3,
Ka2,CO2 = 10-10.3, and pCO2 = 280 ppm (atm), use function solve in MATLAB
to determine the pH of natural rain water. Use format short in all your
calculations.
(b) Verify the answer in Part (a) by using the function roots in MATLAB.
(c) Equation (1) which is nonlinear can be solved using a root-finding algorithm.
One such method discussed in class is Newton-Raphson whose iterative
formula for one variable is given by:
x k +1 = x k
f ( xk )
f ( x k )
k = 1, 2, 3, ...
Answers:
Solution:
MATLAB Script File:
%
% CHE654: pH of Natural Rain Water
%
clc
clear
format short
% Part (a)
kw = 1.8e-14;
khco2 = 10^(-1.46);
ka1co2 = 10^(-6.3);
ka2co2 = 10^(-10.3);
pco2 = 280e-6;
syms H
F = kw/H + ka1co2*khco2*pco2/H + 2*ka1co2*ka2co2*khco2*pco2/H^2 - H;
answer = solve(F);
HConc = double(answer);
pH = -log10(HConc);
fprintf ('pH of natural rain water from solve = %8.4f \n\n', pH(1))
c = [1 0 -(kw+ka1co2*khco2*pco2) -2*ka1co2*ka2co2*khco2*pco2];
HConc = roots(c);
pH = -log10(HConc);
fprintf ('pH of natural rain water from roots = %8.4f \n\n', pH(1))
% Part (b)
for i = 1:8
if i == 1
HC_1 = 5.0e-6;
else
HC_1 = HC_2;
end
pH_1 = -log10(HC_1);
f = HC_1^3-(kw+ka1co2*khco2*pco2)*HC_1-2*ka1co2*ka2co2*khco2*pco2;
fp = 3*HC_1^2-(kw+ka1co2*khco2*pco2);
HC_2 = HC_1 - f/fp;
pH_2 = -log10(HC_2);
while abs((pH_2-pH_1)/pH_2)*100 > 0.0001
HC_1 = HC_2;
pH_1 = -log10(HC_1);
f = HC_1^3-(kw+ka1co2*khco2*pco2)*HC_1-2*ka1co2*ka2co2*khco2*pco2;
fp = 3*HC_1^2-(kw+ka1co2*khco2*pco2);
HC_2 = HC_1 - f/fp;
pH_2 = -log10(HC_2);
end
pH(i) = pH_2;
fprintf ('At pCO2 = %3g ppm, pH = %6.4f \n', pco2*1e6, pH(i))
pco2 = pco2 + 20e-6;
end
pco2 = [280 300 320 340 360 380 400 420];
plot(pco2,pH)
title('pH of Natural Rain Water at Various CO2 Partial Pressure')
xlabel('CO2 Partial Pressure (ppm atm)')
ylabel('pH of Natural Rain Water')
grid on
MATLAB Output :
pH of natural rain water from solve = 5.6556
pH of natural rain water from roots = 5.6556
At pCO2 = 280 ppm, pH = 5.6556
At pCO2 = 300 ppm, pH = 5.6407
At pCO2 = 320 ppm, pH = 5.6267
At pCO2 = 340 ppm, pH = 5.6136
At pCO2 = 360 ppm, pH = 5.6012
At pCO2 = 380 ppm, pH = 5.5895
At pCO2 = 400 ppm, pH = 5.5784
At pCO2 = 420 ppm, pH = 5.5678
Solution:
The MATLAB Script File:
%
% CHE654: Problem #17
%
% Solving 2 simultaneous 1st-order ODEs using ODE45
%
clear
clc
inity = [0, 0];
% initial conditions
xspan = [0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 ... % span and values of x
0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0];
[x,y] = ode45('ode4a',xspan,inity);
% solve the ODEs
plot(x,y);
xlabel('Values of x');
ylabel('Values of y1 and y2');
legend('y1','y2');
%
% Compare analytical solutions with MATLAB solutions
%
fprintf ('Value of x Exact y1 MATLAB y1 Percent Error Exact y2 MATLAB y2
Percent Error\n');
x = 0.1;
for i = 1:20
y1 = exp(x)+exp(-x)-2;
y2 = exp(x)-exp(-x)-x;
erry1 = abs((y1-y(i+1,1)))*100.0/y1;
erry2 = abs((y2-y(i+1,2)))*100.0/y2;
fprintf ('%5.2f
',x);
fprintf ('%8.6f ',y1);
fprintf ('%8.6f ',y(i+1,1));
fprintf ('%10.6f
',erry1);
fprintf ('%8.6f ',y2);
fprintf ('%8.6f ',y(i+1,2));
fprintf ('%10.6f\n',erry2);
x = x + 0.1;
end
10
11
y = ty + (t 3 2t 2 5t 3)e t
0 t 1,
s.t.
Use ode45 in MATLAB to solve for numerical solutions of the above ODE between
t = 0 and t = 1, showing a step size of 0.1.
The analytical (exact) solution of the above ODE is: y(t) = t(a + bt)exp(ct)
where a, b, and c are constant coefficients. Also, use MATLAB and the numerical
answers from ode45 to determine the correct values of a, b, and c, without taking
any derivatives of y(t).
Answers:
y(t=0) = ______0______
y(t=0) = ______1______
y(t=0) = _____0_______
b = __1___
Solution:
MATLAB Script File:
%
% Solving a 3rd-Order Linear ODE: Boundary-Value Problem
%
clc
clear
format short
%
% Integrating backward from t=1 to t=0
%
g1 = -5;
g2 = 5;
target = 0;
% first trial
simtime = [1:-0.1:0];
initz = [0, -exp(1), g1];
[t, z] = ode45('f3rd', simtime, initz);
r1 = z(11,1);
% second trial
initz = [0, -exp(1), g2];
[t, z] = ode45('f3rd', simtime, initz);
r2 = z(11,1);
% third trial
g3 = g1 + (g2-g1)/(r2-r1)*(target-r1);
initz = [0, -exp(1), g3];
[t, z1] = ode45('f3rd', simtime, initz);
[t, z1]
% Determine coefficients a, b, and c in the exact solution
12
c = __1__
syms a b c
F1 = 0.2*(a+b*0.2)*exp(0.2*c)-0.1954;
F2 = 0.5*(a+b*0.5)*exp(0.5*c)-0.4122;
F3 = 0.8*(a+b*0.8)*exp(0.8*c)-0.3561;
abc = solve(F1,F2,F3);
a = double(abc.a);, fprintf ('a = %4.2f \n', a(1))
b = double(abc.b);, fprintf ('b = %4.2f \n', b(1))
c = double(abc.c);, fprintf ('c = %4.2f \n', c(1))
ODE M-File:
function fz = ode(t, z)
%
% Define
% z1 = y
% z2 = dz1/dt = y'
% z3 = dz2/dt = y''
% z4 = dz3/dt = y'''
% subject to z1(0)=0 (target), z2(1)=e, z3(1)=guess
%
% Initialize fy as 3x1 matrix to zeros
fz = zeros(3,1);
fz(1) = z(2);
fz(2) = z(3);
fz(3) = t*z(1)+(t^3-2*t^2-5*t-3)*exp(t);
-2.7183
-1.7463
-0.9792
-0.3826
0.0729
0.4122
0.6564
0.8234
0.9283
0.9836
1.0000
-10.8731
-8.6332
-6.7656
-5.2156
-3.9358
-2.8853
-2.0289
-1.3364
-0.7817
-0.3426
0.0000
a = 1.00
b = -1.00
c = 1.00
13
and
dCA (z = L) = 0
dz
C A = C A0
1 z
cosh L
D AB L
k
cosh L
D AB
Solution:
The ODE is linear in Part (a) but nonlinear in Part (c).
14
15
[t, ca]
1.0000e-001
0
1.0042e-001 -8.3449e+000
1.0167e-001 -1.6759e+001
1.0377e-001 -2.5314e+001
1.0674e-001 -3.4079e+001
1.1060e-001 -4.3128e+001
1.1538e-001 -5.2537e+001
1.2112e-001 -6.2384e+001
1.2787e-001 -7.2751e+001
1.3569e-001 -8.3725e+001
1.4464e-001 -9.5397e+001
ans =
1.0000e-003
9.0000e-004
8.0000e-004
7.0000e-004
6.0000e-004
5.0000e-004
4.0000e-004
3.0000e-004
2.0000e-004
1.0000e-004
0
2.0000e-001
0
2.0083e-001 -1.6690e+001
2.0334e-001 -3.3519e+001
2.0755e-001 -5.0627e+001
2.1348e-001 -6.8157e+001
2.2119e-001 -8.6256e+001
2.3075e-001 -1.0507e+002
2.4224e-001 -1.2477e+002
2.5574e-001 -1.4550e+002
2.7138e-001 -1.6745e+002
2.8928e-001 -1.9079e+002
CA(0.001) in kmol/m3 in Part (a)
ans =
1.0000e-003
9.0000e-004
8.0000e-004
7.0000e-004
6.0000e-004
5.0000e-004
4.0000e-004
3.0000e-004
2.0000e-004
1.0000e-004
0
1.3828e-001
0
1.3885e-001 -1.1539e+001
1.4059e-001 -2.3174e+001
1.4349e-001 -3.5003e+001
1.4760e-001 -4.7123e+001
1.5293e-001 -5.9636e+001
1.5954e-001 -7.2646e+001
1.6748e-001 -8.6262e+001
1.7681e-001 -1.0060e+002
1.8762e-001 -1.1577e+002
2.0000e-001 -1.3191e+002
16
0.0010
0.0009
0.0008
0.0007
0.0006
0.0005
0.0004
0.0003
0.0002
0.0001
0.0000
0.138273
0.138849
0.140584
0.143490
0.147594
0.152928
0.159537
0.167477
0.176814
0.187624
0.200000
0.138276
0.138853
0.140587
0.143493
0.147596
0.152930
0.159539
0.167478
0.176814
0.187625
0.200000
0.002562
0.002453
0.002167
0.001884
0.001605
0.001329
0.001056
0.000785
0.000516
0.000248
0.000061
ans =
1.0000e-003
9.0000e-004
8.0000e-004
7.0000e-004
6.0000e-004
5.0000e-004
4.0000e-004
3.0000e-004
2.0000e-004
1.0000e-004
0
9.5925e-002
0
9.6693e-002 -1.5418e+001
9.9023e-002 -3.1335e+001
1.0299e-001 -4.8293e+001
1.0873e-001 -6.6918e+001
1.1645e-001 -8.7985e+001
1.2644e-001 -1.1249e+002
1.3910e-001 -1.4178e+002
1.5500e-001 -1.7769e+002
1.7493e-001 -2.2287e+002
2.0000e-001 -2.8121e+002
17
P
V
T
R
TC
PC
=
=
=
=
=
=
=
pressure in bar
molar volume in L/gmole
temperature in K
gas constant (0.08315 bar-L/gmole-K)
critical temperature in K (305.556 K for ethane)
critical pressure in atm (48.2989 bar for ethane)
Pitzer acentric factor (0.1064 for ethane)
18
Answers:
(a) Work (ideal gas) = ____123.74____ bar-L/gmole
(b) Work (RKS gas) = ____109.77____ bar-L/gmole
Solution:
MATLAB Script File:
%
% CHE654
%
% Problem #26: Isothermal Compression of Ethane Using Ideal Gas Law and RKS Equation
of State
%
clc
clear
global R T a b
% Part (a): Assume ideal gas
R = 0.08315;
T = (50+273.15);
P1 = 1.01325;
V1 = R*T/P1;
V2 = V1/100;
% Integrating gives W = -RTln(V2/V1)
Wideal = -R*T*log(V2/V1)
%
% Part (b): Use Redlich-Kwong-Soave equation of state
%
% First must solve for V1 using solve function
Tc = 305.556;
Pc = 48.2989;
w = 0.1064;
Tr = T/Tc;
m = 0.480+1.574*w-0.176*w^2;
a = 0.42748*((R*Tc)^2*(1+m*(1-sqrt(Tr)))^2)/Pc;
b = 0.08664*R*Tc/Pc;
syms V
F = R*T/(V-b)-a/(V*(V+b))-1.01325;
V1 = solve(F);
V1real = double(V1)
V1real = V1real(1)
% Now use ode45 to integrate the work differential equation
V2 = V1real/100
sim = [V1real V2];
W0 = 0;
[V,W] = ode45('fwork',sim,W0);
[V,W]
19
MATLAB Output:
Wideal =
123.7406
V1real =
26.3587
0.0799 + 0.0548i
0.0799 - 0.0548i
V1real =
26.3587
V2 =
0.2636
ans =
26.3587
26.3586
26.3586
26.3585
26.3585
26.3582
26.3580
26.3577
26.3575
26.3563
26.3550
26.3538
26.3525
26.3463
26.3401
26.3339
26.3278
26.2968
26.2658
26.2348
26.2038
26.0489
0
0.0001
0.0001
0.0002
0.0002
0.0005
0.0007
0.0010
0.0012
0.0025
0.0037
0.0050
0.0062
0.0125
0.0188
0.0251
0.0314
0.0628
0.0943
0.1258
0.1574
0.3158
20
25.8939 0.4751
25.7390 0.6354
25.5840 0.7966
24.9317 1.4863
24.2793 2.1942
23.6269 2.9212
22.9745 3.6684
22.3222 4.4370
21.6698 5.2282
21.0174 6.0435
20.3650 6.8842
19.7126 7.7521
19.0603 8.6490
18.4079 9.5769
17.7555 10.5379
17.1031 11.5346
16.4508 12.5697
15.7984 13.6463
15.1460 14.7678
14.4936 15.9382
13.8412 17.1618
13.1889 18.4439
12.5365 19.7902
11.8841 21.2075
11.2317 22.7038
10.5794 24.2882
9.9270 25.9721
9.2746 27.7686
8.6222 29.6937
7.9698 31.7673
7.3175 34.0147
6.6651 36.4678
6.0127 39.1661
5.3603 42.1658
4.7080 45.5444
4.0556 49.4176
3.4032 53.9206
2.7508 59.3352
2.0984 66.1553
1.6397 72.4234
1.1810 80.0123
0.7223 90.7894
0.2636 109.7716
21