Vous êtes sur la page 1sur 21

CHE654

Modeling Chemical Processes


Using MATLAB

Homework Set #2 Solutions


Class-16

Prepared by

Dr. Hong-ming Ku

King Mongkuts University of Technology Thonburi


Chemical Engineering Department
Chemical Engineering Practice School
July 2004-2012 Use with Permission of the Author Only

15. Dynamics of a Gas Surge Drum


Surge drums are often used as intermediate storage capacity for gas streams that
are transferred between chemical process units. Consider a drum in the figure
below, where qf is inlet molar flowrate and q is the outlet molar flowrate.
q f , Pf , T

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

But V and T are constant:

dP/dt = RT(qf q)/V

(b) First, must find the initial P (i.e. P at t = 0):


P(t=0) = n(t=0)RT/V = (10 kmol)(8314 m3-Pa/kmol-K)(300 K)/(50 m3)
= 4.9884 x 105 Pascal
dP/dt = (8314)(300)(2.0+0.1t 3.0)/50 = 49884(0.1t 1.0)
t
P 499840 =

49884(0.1t 1.0) dt

= 49884 (0.05t2 t) 0

P = 49984(0.05t2 t) + 499840 = 49984[t(0.05t 1) + 10]


If maximum P = 50 atm = 5.06625 x 106 Pa = 49984(0.05t2 t) + 499840

 0.05t2 t = 91.3574  0.05t2 t 91.3574 = 0


t = 53.9 minutes

(c) Expressing the equation of state explicitly in terms of P:

P = (1 + 0.04394/V)RT / V = RTn(1 + 0.04394n/V) / V


dP/dt = (RT/V)(dn/dt) + (0.08788RTn/V2)(dn/dt)

= (RT/V)(1 + 0.08788n/V)(dn/dt)

dn/dt = (dP/dt)/[(RT/V)(1 + 0.08788n/V)]

dn/dt = qf q
dP/dt = [(RT/V)(1 + 0.08788n/V)]( qf q)

Must express n in terms of P and other constants:


PV/RT = n + 0.04394n2/V  (0.04394/V)n2 + n PV/RT = 0
n = 1 + [1 + (4)(0.04394/V)(PV/RT)]1/2
(0.08788/V)
n = 568.9577{1 + [1 + 7.04675x10-8P] }
dP/dt = 49884(1 1 + [1 + 7.04675x10-8P] )(0.1t 1)
dP/dt = 49884[1 + 7.04675x10-8P] (0.1t 1)
dP/[1 + 7.04675x10-8P] = 49884(0.1t 1)dt
2.8381878x107 [1 + 7.04675x10-8P] = 49884(0.05t2 t) + C
568.9575[1 + 7.04675x10-8P] = (0.05t2 t) + A
At t = 0, P = 5.03224x105 Pascal

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

16. pH of Natural Rain Water


CO2 is a trace yet important constituent of the atmosphere that keeps the earth
warm enough for life in their current forms. The concentration of CO2 before the
industrial revolution has been relatively constant over a long period. CO2 is slightly
water soluble, which makes the natural rain in a clean atmosphere slightly acidic
due to the dissolution of CO2 into the cloud droplets. The partitioning of CO2 into a
droplet can be
described by the
following equilibrium
relations:

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, ...

Write a MATLAB program to generate a plot of CO2 partial pressure (ppm)


vs. pH of natural rain water using Newton-Raphson. Provide a title and label
your x-axis and y-axis properly. The pH should be calculated at CO2 partial
pressures between the range of 280 ppm and 420 ppm using an increment of
20 ppm (use a FOR loop). At pCO2 = 280 ppm, use an initial guess of [H+] =
5.010-6 to solve Equation (1). For subsequent pCO2s, use the answer from
the previous increment as the initial guess, e.g. use the [H+] solution from the
case where pCO2 = 280 ppm as a starting point for the case where pCO2 = 300
ppm. You may rearrange Equation (1), f ([H+]) = 0, into another form in order
to help determine f ([H+]) more easily. The termination criterion for NewtonRaphson is when the absolute relative percent error of the pH (not [H+])
between two successive iterations is less than 10-4.
pH (pCO2 = 280 ppm) = ___5.6556____

Answers:

pH (pCO2 = 360 ppm) = __5.6012_ pH (pCO2 = 420 ppm) = ___5.5678____

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

17. Solving a System of ODEs Using MATLAB


Solve the following set of 1st-order ODEs, which is an initial-value problem, using
MATLABs ode45 function from x = 0 to x = 2 with an increment of 0.1:
dy1
= y2 + x
dx
dy 2
= y1 + 1
dx
subject to: y1(0) = y2(0) = 0
Make a plot of the 2 equations (y1 and y2 versus x solutions from MATLAB).
Then, compare your MATLAB solution with the analytical solution below by
reporting the relative % differences. Include 6 decimal places in reporting all your
numbers.
y1(x) = c1ex + c2e-x 2
y2(x) = c1ex c2e-x x

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

The MATLAB M-file for the ODE:


function dydx = ode(x,y)
dydx = zeros(2,1);
dydx(1) = y(2) + x;
dydx(2) = y(1) + 1;

The MATLAB Output:


Value of x Exact y1 MATLAB y1 Percent Error Exact y2 MATLAB y2 Percent Error
0.10
0.010008 0.010008 0.000027
0.100334 0.100334 0.000030
0.20
0.040134 0.040134 0.000011
0.202672 0.202672 0.000096
0.30
0.090677 0.090677 0.000001
0.309041 0.309041 0.000055
0.40
0.162145 0.162145 0.000049
0.421505 0.421505 0.000048
0.50
0.255252 0.255252 0.000027
0.542191 0.542191 0.000033
0.60
0.370930 0.370931 0.000042
0.673307 0.673307 0.000034
0.70
0.510338 0.510338 0.000028
0.817167 0.817168 0.000025
0.80
0.674870 0.674870 0.000036
0.976212 0.976212 0.000029
0.90
0.866173 0.866173 0.000026
1.153033 1.153034 0.000023
1.00
1.086161 1.086162 0.000032
1.350402 1.350403 0.000027
1.10
1.337037 1.337037 0.000025
1.571295 1.571295 0.000022
1.20
1.621311 1.621312 0.000030
1.818923 1.818923 0.000026
1.30
1.941828 1.941829 0.000024
2.096765 2.096765 0.000022
1.40
2.301797 2.301798 0.000028
2.408603 2.408604 0.000026
1.50
2.704819 2.704820 0.000023
2.758559 2.758560 0.000022
1.60
3.154929 3.154930 0.000027
3.151136 3.151137 0.000026
1.70
3.656631 3.656632 0.000023
3.591264 3.591265 0.000022
1.80
4.214946 4.214947 0.000026
4.084349 4.084350 0.000026
1.90
4.835463 4.835464 0.000023
4.636326 4.636327 0.000023
2.00
5.524391 5.524392 0.000016
5.253721 5.253722 0.000015

10

11

22. Solving a 3rd-Order ODE Boundary-Value Problem


Consider the following 3rd-order ODE which is a boundary-value problem

y = ty + (t 3 2t 2 5t 3)e t

0 t 1,

s.t.

y (0) = 0, y (1) = 0, y (1) = e1

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_______

y(t=0.5) = ___0.4122____ y(t=0.5) = ___0.4122____ y(t=0.5) = ___2.8853__


y(t=1) = ______0______

y(t=1) = ___2.7183____ y(t=1) = __10.8731___

The values of coefficients are: a = __1__

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);

Output from MATLAB


ans =
1.0000
0
0.9000 0.2214
0.8000 0.3561
0.7000 0.4229
0.6000 0.4373
0.5000 0.4122
0.4000 0.3580
0.3000 0.2835
0.2000 0.1954
0.1000 0.0995
0
-0.0000

-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

24. Solving a 2nd-Order Boundary-Value ODE Using the Shooting Method


The diffusion and simultaneous first-order irreversible chemical reaction in a
single phase containing only reactant A and product B results in a second-order
ODE given by:
d 2C A
k
=
CA
2
D AB
dz
where CA is the concentration of reactant A (kmol/m3), z is the distance variable
(m), k is the homogeneous reaction rate constant (s-1), and DAB is the binary
diffusion coefficient (m3/s). A typical geometry for the above ODE is that of a
one-dimensional layer that has its surface exposed to a known concentration and
allows no diffusion across its bottom surface. Thus, the initial and boundary
conditions are:
CA(z = 0) = CA0

and

dCA (z = L) = 0
dz

where CA0 is the constant concentration at the surface (z = 0) and there is no


transport across the bottom surface (z = L) so the derivative is zero. This
differential equation has an analytical solution given by:

C A = C A0

1 z
cosh L

D AB L
k

cosh L

D AB

(a) Is the above ODE linear or nonlinear? Write a MATLAB program to


implement the shooting method to solve the above ODE (use ode23), in which
CA0 = 0.2 kmol/m3, k = 0.001 s-1, DAB = 1.2x10-9 m2/s, and L = 0.001 m. Use
format short e.
(b) Compare the concentration profiles over the thickness as predicted by the
numerical solution of (a) with the analytical solution by reporting the relative
percentage differences accurate to 6 decimal places with an increment of z =
10-4.
(c) Obtain a numerical solution for a second-order reaction that requires the CA
term on the right side of the ODE to become squared. The second-order rate
constant is given by k = 0.02 m3/(kmole-s). Use format short e and ode23. Is
this new ODE linear or nonlinear?

Solution:
The ODE is linear in Part (a) but nonlinear in Part (c).

14

The MATLAB Script File:


%
% CHE654: Problem #24
%
% Solving a 2nd-Order Boundary-Value ODE Using the Shooting Method
%
% Part (a):
%
clc
clear
format short e
% first trial
simtime = [0.001:-1e-4:0];
g1 = 0.1;
initca = [g1, 0];
[t, ca] = ode23('fshoot1', simtime, initca);
[t, ca]
r1 = ca(11,1);
% second trial
g2 = 0.2;
initca = [g2, 0];
[t, ca] = ode23('fshoot1', simtime, initca);
[t, ca]
r2 = ca(11,1);
% third trial and the solution
g3 = g1 + (g2-g1)/(r2-r1)*(0.2-r1);
initca = [g3, 0];
[t, ca] = ode23('fshoot1', simtime, initca);
[t, ca]
%
% Part (b):
%
z = 0.001;
fprintf('Length Analytical CA Numerical CA %% Error \n');
fprintf('------ ------------- ------------ ------- \n');
for i = 1:11
ca_exact = 0.2*cosh(0.001*sqrt(0.001/1.2e-9)*(1z/0.001))/cosh(0.001*sqrt(0.001/1.2e-9));
percent_err = 100*abs(ca_exact-ca(i))/ca_exact;
fprintf('%6.4f %12.6f %17.6f %14.6f \n', t(i), ca_exact, ca(i), percent_err);
z = z - 1e-4;
end
%
% Part (c):
%
simtime = [0.001:-1e-4:0];
guess = 0.095925;
initca = [guess, 0];
[t, ca] = ode23('fshoot2', simtime, initca);

15

[t, ca]

The MATLAB Output:


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.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

Length Analytical CA Numerical CA % Error


------ ------------------------------

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

CA(0.001) in kmol/m3 in Part (c)

26. Isothermal Compression of Ethane


Ethane is being compressed isothermally at 50 C (323.15 Kelvin) to 1/100th (i.e.
1%) of its initial volume in a closed vessel. The initial pressure of the gas is
1.01325 bar.
We wish to calculate the work per gmole required in this compression. For a
closed system in a reversible isothermal compression from V1 to V2, the work W
done on the system can be calculated from:
dW = P
dV
Use MATLAB to do the following:
(a) Calculate the work W using the ideal gas assumption.
(b) Calculate the work W using the Redlich-Kwong-Soave equation of state, which
is given by:

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]

MATLAB ODE M-File:


function fw = ode(V,W)
global R T a b
fw = zeros(1,1);
fw(1) = -R*T/(V(1)-b)+a/(V(1)*(V(1)+b));

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