# Variables
per_ethanol = 60. #mole percent of ethanol in a ethanol-water system
per_water = 40. #mole percent of water in a ethanol-water system
v1 = 57.5*10**-6 #partial molar volume of ethanol in the ethanol-water system in m**3
rho = 849.4; #density of the mixture in kg/m**3
M_ethanol = 46*10**-3 #molar mass of ethanol in kg/mol
M_water = 18*10**-3 #molar mass of ethanol in kg/mol
# Calculations
X1 = per_ethanol/100
X2 = per_water/100
M = (X1*M_ethanol)+(X2*M_water)
v = M/rho
v2 = (v-(X1*v1))/(X2);
# Results
print " The partial molar volume of water = %f m**3/mol"%(v2);
# Variables
V = 3. #volume of mixture to be prepared in m**3
per_ethanol = 60. #mole percent of ethanol in a ethanol-water system
per_water = 40. #mole percent of water in a ethanol-water system
v1 = 57.5*10**-6; #partial molar volume of ethanol in the ethanol-water system in m**3/mol
v2 = 16*10**-6 #partial molar volume of water in the ethanol-water system in m**3/mol
v1_pure = 57.9*10**-6 #molar volume of pure ethanol in m**3/mol
v2_pure = 18*10**-6 #molar volume of pure water in m**3/mol
# Calculations
X1 = per_ethanol/100; # Calculations of the mole fraction of ethanol (no unit)
X2 = per_water/100; # Calculations of the mole fraction of water (no unit)
v = (X1*v1)+(X2*v2); # Calculations of the molar volume of the solution using Eq.(9.10) in m**3/mol
N = V/v # Calculations of the mole number of solution required in mol
N1 = N*X1 # Calculations of the mole number of ethanol in solution in mol
N2 = N*X2; # Calculations of the mole number of water in solution in mol
V1 = N1*v1_pure; # Calculations of the volume of pure ethanol required in m**3
V2 = N2*v2_pure; # Calculations of the volume of pure water required in m**3
# Results
print " The volume of pure ethanol required = %0.3f m**3"%(V1);
print " The volume of pure water required = %0.3f m**3"%(V2);
import math
# Variables
T = 427.85; #temperature of n-octane vapour in K
P = 0.215; #pressure of n-octane vapour in MPa
a = 3.789; #van der Waals constant in Pa(m**3/mol)**2
b = 2.37*10**-4; #van der Waals constant in m**3/mol
v = 15.675*10**-3; #molar volume of n-octane saturated vapour taken from Example 3.8 in m**3/mol
R = 8.314; #universal gas constant in J/molK
# Calculations
Z = (P*10**6*v)/(R*T) # Calculations of the compressibility factor (no unit)
# Calculations of the fugacity coefficient (f/P) using the expression derived in Example 9.3 (no unit)
phi = math.exp(Z-1-math.log (((P*10**6)*(v-b))/(R*T))-a/(R*T*v));
f = (P*10**6*phi)*10**-6
# Results
print " The fugacity coefficient of n-octane vapour = %0.2f "%(phi);
print " The fugacity of n-octane vapour = %0.4f MPa"%(f);
# Variables
T = 427.85; #temperature of n-octane vapour in K
P = 0.215; #pressure of n-octane vapour in MPa
Tc = 569.4; #critical temperature of n-octane in K
Pc = 24.97; #critical pressure of n-octane in bar
w = 0.398; #acentric factor (no unit)
# Calculations
Tr = T/Tc
Pr = (P*10**6)/(Pc*10**5)
log_phi0 = -0.032;
log_phi1 = -0.025;
phi = round(log_phi0 + 0.398*log_phi1,3)
phie = 1.1014
f = P*phie
# Results
print " The fugacity coefficient of n-octane vapour = %.3f "%(phi);
print " The fugacity of n-octane vapour = %.4f MPa"%(f);
import math
# Variables
T = 339.7 #temperature of ethylene in K
P = 1. #pressure of ethylene in bar
Tc = 283.1 #critical temperature of ethylene in K
Pc = 51.17 #critical pressure of ethylene in bar
w = 0.089 #acentric factor (no unit)
# Calculations
Tr = T/Tc
Pr = P/Pc
B0 = 0.083-(0.422/(Tr**1.6))
B1 = 0.139-(0.172/(Tr**4.2))
phi = math.exp((B0+(w*B1))*(Pr/Tr))
f = P*phi
# Results
print " The fugacity coefficient of ethylene = %0.4f "%(phi);
print " The fugacity of ethylene = %0.4f bar"%(f);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
Tc = [425.2,569.4]; #critical temperature of n-butane and n-octane in K
Pc = [37.97,24.97]; #critical pressure of n-butane and n-octane in bar
vc = [255.0*10**-6,486.0*10**-6]; #critical molar volume of n-butane and n-octane in m**3/mol
Zc = [0.274,0.256]; #compressibility factor of n-butane and n-octane corresponding to Tc,Pc (no unit)
w = [0.199,0.398]; #acentric factor of n-butane and n-octane (no unit)
R = 8.314 #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
K_12 = 1-((8*((vc[0]*vc[1])**(1./2)))/((((vc[0])**(1./3))+((vc[1])**(1./3)))**3))
Tc_12 = (((Tc[0])*(Tc[1]))**(1./2))*(1-K_12);
w_12 = (w[0]+w[1])/2
Zc_12 = (Zc[0]+Zc[1])/2
vc_12 = ((((vc[0])**(1./3))+((vc[1])**(1./3)))/2)**3
Pc_12 = ((Zc_12*R*Tc_12)/vc_12)*10**-6;
Tr_12 = T/Tc_12
B_12_0 = 0.083-(0.422/(Tr_12**(1.6)));
B_12_1 = 0.139-(0.172/(Tr_12**(4.2)));
B_12 = ((R*Tc_12)/(Pc_12*10**6))*(B_12_0+(w_12*B_12_1))
Tr1 = T/Tc[0]
B_11_0 = 0.083-(0.422/(Tr1**(1.6)));
B_11_1 = 0.139-(0.172/(Tr1**(4.2)));
B_11 = ((R*Tc[0])/(Pc[0]*10**5))*(B_11_0+(w[0]*B_11_1))
Tr2 = T/Tc[1]
B_22_0 = 0.083-(0.422/(Tr2**(1.6)))
B_22_1 = 0.139-(0.172/(Tr2**(4.2)))
B_22 = ((R*Tc[1])/(Pc[1]*10**5))*(B_22_0+(w[1]*B_22_1))
Bm = ((y1**2)*B_11)+((2*y1*y2)*B_12)+((y2**2)*B_22);
# Results
print " The second virial coefficient for an equimolar mixture of n-butane and n-octane at\
600K = %.2e m**3/mol"%(Bm);
import math
# Variables
a = [1.3874,3.7890]; #van der Waals constant of n-butane and n-octane in Pa(m**3/mol)**2
b = [0.1163*10**-3,0.237*10**-3]; #van der Waals constant of n-butane and n-octane in m**3/mol
# Calculations
y1 = 0.5
y2 = 0.5
a_m = ((y1**2)*a[0])+((2*y1*y2)*math.sqrt(a[0]*a[1]))+((y2**2)*a[1])
b_m = (y1*b[0])+(y2*b[1])
# Results
print " The van der Waals constant for an equimolar mixture of n-butane and n-octane,\
a_m = %0.4f Pam**3/mol)**2"%(a_m);
print " The van der Waals constant for an equimolar mixture of n-butane and n-octane,\
b_m = %f m**3/mol"%(b_m);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tc = [425.2,569.4]; #critical temperature of n-butane and n-octane in K
Pc = [37.97,24.97]; #critical pressure of n-butane and n-octane in bar
R = 8.314; #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
Tr1 = T/Tc[0]
Pr1 = P/Pc[0]
Z1_0 = 0.95
Tr2 = T/Tc[1]
Pr2 = P/Pc[1]
Z2_0 = 0.785
Zm = (y1*Z1_0)+(y2*Z2_0)
vm = (Zm*R*T)/(P*10**5)
P1 = y1*P
P2 = y2*P
Pr1 = P1/Pc[0]
Pr2 = P2/Pc[1]
Z1_0 = 0.97
Z2_0 = 0.91
Zm = (y1*Z1_0)+(y2*Z2_0)
vm_dalton = (Zm*R*T)/(P*10**5)
P1 = ((Z1_0*y1*R*T)/(vm_dalton))*10**-2
P2 = ((Z2_0*y2*R*T)/(vm_dalton))*10**-2
Pr1 = P1/Pc[0]
Pr2 = P2/Pc[1]
Z1_0_new = 0.97
Z2_0_new = 0.91
if Z1_0_new == Z1_0 and Z2_0_new == Z2_0:
vm_new = vm_dalton;
else:
Zm = (y1*Z1_0_new)+(y2*Z2_0_new)
vm_new = (Zm*R*T)/(P*10**5);
# Results
print " The molar volume of an equimolar mixture of n-butane and n-octane found using the\
Amagats law of additive volumes = %0.4e m**3/mol"%(vm);
print " The molar volume of an equimolar mixture of n-butane and\
n-octane found using the Daltons law of additive pressures = %0.2e m**3/mol"%(vm_new);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tc = [425.2,569.4]; #critical temperature of n-butane and n-octane in K
Pc = [37.97,24.97]; #critical pressure of n-butane and n-octane in bar
R = 8.314; #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
Tcm = (y1*Tc[0])+(y2*Tc[1]);
Pcm = (y1*Pc[0])+(y2*Pc[1])
Trm = T/Tcm;
Prm = P/Pcm;
Zm0 = 0.9;
vm = (Zm0*R*T)/(P*10.**5)
# Results
print " The molar volume of an equimolar mixture of n-butane and n-octane using the\
pseudocritical properties estimated through Kays rule = %0.2e m**3/mol"%(vm);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tc = [425.2,569.4]; #critical temperature of n-butane and n-octane in K
Pc = [37.97,24.97]; #critical pressure of n-butane and n-octane in bar
vc = [255.0*10**-6,486.0*10**-6]; #critical molar volume of n-butane and n-octane in m**3/mol
Zc = [0.274,0.256]; #compressibility factor of n-butane and n-octane corresponding to Tc,Pc (no unit)
R = 8.314; #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
Tcm = (y1*Tc[0])+(y2*Tc[1]);
Pcm = ((R*((y1*Zc[0])+(y2*Zc[1]))*Tcm)/((y1*vc[0])+(y2*vc[1])))*10**-5
Trm = T/Tcm
Prm = P/Pcm
Zm0 = 0.89
vm = (Zm0*R*T)/(P*10**5)
# Results
print " The molar volume of an equimolar mixture of n-butane and n-octane at 600K\
and 16bar estimated using the Prausnitz-Gunn rule = %0.2e m**3/mol"%(vm);
import math
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
a_m = 2.4405 #van der Waals constant for the mixture as determined in Example 9.8 in Pa(m**3/mol)**2
b_m = 0.1767*10**-3 #van der Waals constant for the mixture as determined in Example 9.8 in m**3/mol
R = 8.314; #universal gas constant in J/molK
# Calculations
A = (a_m*P*10**5)/(R*T)**2
B = (b_m*P*10**5)/(R*T)
alpha = -1-B
beeta = A
gaamma = -(A*B)
p = beeta-((alpha**2)/3)
q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma
D = (((q)**2)/4)+(((p)**3)/27)
if D>0 :
Z = (((-(q)/2)+(math.sqrt(D)))**(1./3))+(((-(q)/2)-(math.sqrt(D)))**(1./3))-(alpha/3);
elif D == 0:
Z1 = ((-2*(q/2))**(1./3))-(alpha/3)
Z2 = ((q/2)**(1./3))-(alpha/3)
Z3 = ((q/2)**(1./3))-(alpha/3)
Za = [Z1 ,Z2, Z3];
Z = max(Za);
else:
r = math.sqrt((-(p**3)/27));
theta = amath.cos((-(q)/2)*(1./r));
Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);
Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3)
Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3)
Za = [Z1, Z2, Z3];
Z = max(Za);
vm = (Z*R*T)/(P*10**5)
# Results
print " The molar volume of an equimolar mixture of n-butane and n-octane at 600K and 16bar found \
using the van der Waals equation of state = %e m**3/mol"%(vm);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Bm = -309.*10**-6; #second virial coefficient for the mixture taken from Example(9.7) in m**3/mol
R = 8.314; #universal gas constant in J/molK
# Calculations
Zm = 1+((Bm*P*10**5)/(R*T))
vm = (Zm*R*T)/(P*10**5)
# Results
print " The molar volume of an equimolar mixture of n-butane and n-octane\
found using the generalized virial coefficient correlation = %0.4e m**3/mol"%(vm);
import math
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
am = 2.4405 #van der Waals constant for the mixture taken from Example 9.8 in Pa(m**3/mol)**2
bm = 0.1767*10**-3; #van der Waals constant for the mixture taken from Example 9.8 in m**3/mol
vm = 2.8933*10**-3; #molar volume of the mixture taken from Example 9.12 in m**3/mol
R = 8.314; #universal gas constant in J/molK
# Calculations
dep_h = ((P*10**5*vm)-(R*T)-(am/vm))*10**-3
dep_s = R*(math.log ((P*10**5*(vm-bm))/(R*T)))
# Results
print " The enthalpy departure of an equimolar mixture of n-butane and n-octane = %0.3f kJ/mol"%(dep_h);
print " The entropy departure of an equimolar mixture of n-butane and n-octane = %0.3f J/mol K"%(dep_s);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tcm = 497.3; #pseudocritical temperature of mixture taken from Example(9.10) in K
Pcm = 31.47; #pseudocritical pressure of mixture taken from Example(9.10) in bar
Trm = 1.21; #pseudoreduced temperature of the mixture taken from Example(9.10) (no unit)
Prm = 0.51; #pseudoreduced pressure of the mixture taken from Example(9.10) (no unit)
w_butane = 0.199; #acentric factor for n-butane (no unit)
w_octane = 0.398; #acentric factor for n-octane (no unit)
R = 8.314; #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
wm = (y1*w_butane)+(y2*w_octane)
del_h0 = 0.380;
del_h1 = 0.188;
del_s0 = 0.22;
del_s1 = 0.18;
dep_h = ((R*Tcm)*(del_h0+(wm*del_h1)))*10**-3;
dep_s = (R)*(del_s0+(wm*del_s1));
# Results
print " The enthalpy departure of an equimolar mixture of n-butane and n-octane using\
the generalized compressibility factor correlation = %0.3f kJ/mol"%(dep_h);
print " The entropy departure of an equimolar mixture of n-butane and n-octane using \
the generalized compressibility factor correlation = %f J/mol K"%(dep_s);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tc = [425.2,569.4]; #critical temperature of n-butane and n-octane in K
Pc = [37.97,24.97]; #critical pressure of n-butane and n-octane in bar
w = [0.199,0.398]; #acentric factor of n-butane and n-octane (no unit)
Tr1 = 1.411; #reduced temperature of n-butane (no unit) taken from Example (9.7)
Tr2 = 1.054; #reduced temperature of n-octane (no unit) taken from Example (9.7)
Tr_12 = 1.24; #reduced temperature for computing the mixture interaction virial coefficient (no unit) taken from Example(9.7)
Pc_12 = 2.978; #Pc_ij in MPa taken from Example(9.7)
Tc_12 = 483.9; #Tc_ij in K taken from Example(9.7)
w_12 = 0.2985; # w_ij (no unit) taken from Example(9.7)
Bm = -309*10**-6; #second virial coefficient in m**3/mol taken from Example (9.7)
R = 8.314; #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
dB0_dTr1 = 0.675/(Tr1**2.6);
dB0_dTr2 = 0.675/(Tr2**2.6);
dB1_dTr1 = 0.722/(Tr1**5.2);
dB1_dTr2 = 0.722/(Tr2**5.2);
dB0_dTr12 = 0.675/(Tr_12**2.6);
dB1_dTr12 = 0.722/(Tr_12**5.2);
dB1_dT = (R/(Pc[0]*10**5))*((dB0_dTr1)+(w[0]*(dB1_dTr1)));
dB2_dT = (R/(Pc[1]*10**5))*((dB0_dTr2)+(w[1]*(dB1_dTr2)));
dB12_dT = (R/(Pc_12*10**6))*((dB0_dTr12)+(w_12*(dB1_dTr12)));
dBm_dT = ((y1**2)*(dB1_dT))+((2*y1*y2)*(dB12_dT))+((y2**2)*(dB2_dT));
dep_h = ((Bm-(T*dBm_dT))*P*10**5)*10**-3
dep_s = -P*10**5*(dBm_dT);
# Results
print " The enthalpy departure of an equimolar mixture of n-butane and n-octane\
using the virial coefficient correlation = %f kJ/mol"%(dep_h);
print " The entropy departure of an equimolar mixture of n-butane and n-octane\
using the virial coefficient correlation = %0.3f J/mol K"%(dep_s);
import math
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
a_m = 2.4405 #van der Waals constant (a_m) in Pa(m**3/mol)**2 taken from Example(9.8)
b_m = 0.1767*10**-3 #van der Waals constant (b_m) in m**3/mol taken from Example(9.8)
Z = 0.928; #compressibility factor taken from Example(9.12)
vm = 2.8933*10**-3; #molar volume of the equimolar mixture in m**3/mol taken from Example(9.12)
R = 8.314; #universal gas constant in J/molK
# Calculations
phi = math.exp(Z-1-math.log ((P*10**5*(vm-b_m))/(R*T))-(a_m/(R*T*vm)));
f = phi*P;
# Results
print " The fugacity coefficient of an equimolar mixture of n-butane and n-octane\
using the van der Waals equation of state = %0.4f "%(phi);
print " The fugacity of an equimolar mixture of n-butane and n-octane using the van der Waals \
equation of state = %0.2f bar"%(f);
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tcm = 497.3; #pseudocritical temperature of mixture in K taken from Example(9.10)
Pcm = 31.47; #pseudocritical pressure of mixture in bar taken from Example(9.10)
Trm = 1.21; #pseudoreduced temperature of the mixture (no unit) taken from Example(9.10)
Prm = 0.51; #pseudoreduced pressure of the mixture (no unit) taken from Example(9.10)
w = [0.199,0.398]; #acentric factor of n-butane and n-octane (no unit)
# Calculations
wm = (w[0]+w[1])/2
log_phi0 = -0.042
log_phi1 = 0.01
phi = 10**(log_phi0+(wm*log_phi1));
f = P*phi;
# Results
print " The fugacity coefficient of an equimolar mixture of n-butane and n-octane \
using the pseudocritical constants method = %0.3f "%(phi);
print " The fugacity of an equimolar mixture of n-butane and n-octane using\
the pseudocritical constants method = %f bar"%(f);
import math
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Bm = -309.*10**-6; #second virial coefficient in m**3/mol taken from Example (9.7)
R = 8.314; #universal gas constant in J/molK
# Calculations
phi = math.exp((Bm*P*10**5)/(R*T))
f = phi*P;
# Results
print " The fugacity coefficient of an equimolar mixture of n-butane and n-octane using\
the virial coefficient correlation = %.3f "%(phi);
print " The fugacity of an equimolar mixture of n-butane and n-octane using\
the virial coefficient correlation = %f bar"%(f);
# Note : answers in book is wrong please check manually.
import math
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
Tc = [425.2,569.4]; #critical temperature of n-butane and n-octane in K
Pc = [37.97,24.97]; #critical pressure of n-butane and n-octane in bar
R = 8.314; #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
a1 = (0.42748*R**2*Tc[0]**2.5)/(Pc[0]*10**5*math.sqrt(T))
a2 = (0.42748*R**2*Tc[1]**2.5)/(Pc[1]*10**5*math.sqrt(T))
b1 = (0.08664*R*Tc[0])/(Pc[0]*10**5);
b2 = (0.08664*R*Tc[1])/(Pc[1]*10**5);
a = ((y1**2)*a1)+(2*y1*y2*math.sqrt(a1*a2))+((y2**2)*a2)
b = (y1*b1)+(y2*b2)
A = (a*P*10**5)/(R*T)**2
B = (b*P*10**5)/(R*T);
alpha = -1.
beeta = A-B-B**2
gaamma = -(A*B)
p = beeta-(alpha**2)/3
q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma
D = (((q)**2)/4)+(((p)**3)/27)
if D>0:
Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3); #One real root given by Eq.(3.32)
elif D == 0:
Z1 = ((-2*(q/2))**(1./3))-(alpha/3)
Z2 = ((q/2)**(1./3))-(alpha/3);
Z3 = ((q/2)**(1./3))-(alpha/3);
Za = [Z1, Z2, Z3];
Z = max(Za);
else:
r = math.sqrt((-(p**3)/27));
theta = amath.cos((-(q)/2)*(1./r));
Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);
Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3)
Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);
Za = [Z1, Z2, Z3];
Z = max(Za);
phi1 = math.exp(((b1/b)*(Z-1))-math.log(Z-B)+((a/(b*R*T))*((b1/b)-(2*math.sqrt(a1/a)))*math.log((Z+B)/Z)));
phi2 = math.exp(((b2/b)*(Z-1))-math.log(Z-B)+((a/(b*R*T))*((b2/b)-(2*math.sqrt(a2/a)))*math.log((Z+B)/Z)));
# Results
print " The fugacity coefficient of n-butane in the equimolar mixture using the\
Redlich-Kwong Equation of state = %0.4f "%(phi1);
print " The fugacity coefficient of n-octane in the equimolar mixture using the\
Redlich-Kwong Equation of state = %0.4f "%(phi2);
import math
# Variables
T = 600. #temperature of the equimolar n-butane and n-octane mixture in K
P = 16. #pressure of the equimolar n-butane and n-octane mixture in bar
B_11 = -131*10**-6 #pure component (n-butane) second virial coefficient in m**3/mol taken from Example(9.7)
B_22 = -577*10**-6 #pure component (n-octane) second virial coefficient in m**3/mol taken from Example(9.7)
B_12 = -264*10**-6 #mixture interaction virial coefficient in m**3/mol taken from Example(9.7)
Bm = -309*10**-6 #second virial coefficient in m**3/mol taken from Example(9.7)
R = 8.314 #universal gas constant in J/molK
# Calculations
y1 = 0.5
y2 = 0.5
Zm = (1./2)*(1+math.sqrt(1+((4*Bm*P*10**5)/(R*T))))
phi1 = math.exp((((2*P*10**5)/(Zm*R*T))*((y1*B_11)+(y2*B_12)))-math.log(Zm))
phi2 = math.exp((((2*P*10**5)/(Zm*R*T))*((y1*B_12)+(y2*B_22)))-math.log(Zm))
# Results
print " The fugacity coefficient of n-butane in the equimolar mixture using the\
Virial Equation of state = %0.3f "%(phi1);
print " The fugacity coefficient of n-octane in the equimolar mixture using the Virial\
Equation of state = %f "%(phi2);
import math
# Variables
T = 427.85 #temperature of n-octane vapour in K
Psat = 0.215; #saturation pressure of n-octane vapour at T in MPa
P = 1. #pressure at which the fugacity of liquid n-octane is to be determined in MPa
f_sat = 0.2368; #fugacity of n-octane vapour at T and Psat taken from Example(9.5) in MPa
vl = 0.2003*10**-3; #molar volume of n-octane liquid at T and Psat taken from Example(3.16) in m**3/mol
R = 8.314; #universal gas constant in J/molK
# Calculations
f_l = (0.2368*math.exp((vl*(P-Psat)*10**6)/(R*T)));
# Results
print " The fugacity of liquid n-octane at 427.85K and 1MPa = %0.4f MPa"%(f_l);