import math
# Variables
T = 154.5 #C
P = 8620.*10**3 #Pa
Tc = 135. #C
T0 = 273.1 #C
Pc = 3648.*10**3 #Pa
w = 0.1756
V = 0.154
R = 8.3143*10**3
# Calculations
Tr = (T+T0)/(T0+Tc)
Pr = P/Pc
Z = P*V/(R*(T+T0))
a = 0.42747*R**2 *(Tc+T0)**2 /Pc *(1+ (0.48508 + 1.55171*w - 0.15613*w**2)*(1-math.sqrt(Tr)))**2
b = 0.08664*R*(Tc+T0)/Pc
A = a*P/(R**2 *(T+T0)**2)
B = b*P/(R*(T+T0))
lnphi = (Z-1) - math.log(Z-B) - A/B *math.log((Z+B)/Z)
phi = math.exp(lnphi)
f = phi*P
# Results
print "fugacity = %d kPa"%(f/10**3)
#The answer is a bit different due to rounding off error in textbook
# Variables
T = 154.5 #C
P = 8620.*10**3 #Pa
Tc = 135. #C
T0 = 273.1 #C
Pc = 3648.*10**3 #Pa
w = 0.1756
V = 0.154
R = 8.3143*10**3
D = 0.35
Vc = 0.263 #m**3/kmol
# Calculations
Tr = (T+T0)/(T0+Tc)
Pr = P/Pc
Zc = Pc*Vc/(R*(Tc+T0))
phi1 = 0.44
phi2 = phi1*10**(D*(Zc-0.27))
f = phi2*P
# Results
print "fugacity = %d kPa"%(f/10**3)
# rounding off error.
import math
# Variables
f0 = 0.7
V = 5.1e-2
P1 = 0.77 #Mpa
P2 = 10. #Mpa
R = 8.3143*10**3
T = 298. #K
# Calculations
lnr = V/(R*T) *(P2-P1)*10**6
f = math.exp(lnr) *f0
# Results
print "Fugacity = %.3f Mpa"%(f)
import math
# Variables
Pt = 0.1013
ya = 0.605
P1 = 0.1373
P2 = 0.06
xa = 0.4
# Calculations
if ya*Pt == xa*Pt and (1-ya)*Pt == (1-xa)*Pt:
print "The system is ideal"
else:
print "The system is not ideal"
# Variables
Y = 0.06
X = 0.0012
P = 2.53 #Mpa
# Calculations
y = Y/(1+Y)
x = X/(1+X)
H = y*P/x
# Results
print "Henrys law constant = %.2f Mpa"%(H)
# Variables
Hi = 55.
Pi = 11.8
xi = 0.514
H2 = 18.1
H3 = 26.9
Pi2 = 17.4
# Calculations
ai = Pi/Hi
gam = ai/xi
a2 = Pi/H2
gam2 = a2/xi
a3 = Pi2/H3
gam3 = a3/(1-xi)
# Results
print ("part a")
print "Activity of acetic acid = %.4f "%(ai)
print " Activity coefficient = %.4f "%(gam)
print ("part b")
print "Activity of acetic acid = %.4f "%(a2)
print " Activity coefficient = %.4f "%(gam2)
print ("part c")
print "Activity of toluene = %.4f "%(a3)
print " Activity coefficient = %.4f "%(gam3)