# Variables
P = 70.e5 #Pa
T = 150. + 273 #K
Z = 0.55 #Compressibility factor
R = 8314.3/44 #J/kgK
# Calculations and Results
#For propane
v = Z*R*T/P #m**3/kg
print "Specific volume for propane = %.2e m**3/kg"%(v)
#ideal gas
v = R*T/P #m**3/kg
print "Specific volume for ideal gas = %2.3e m**3/kg"%(v)
# Variables
Z = 1.04 #Compressiblity factor
pc = 3.77e6 #Pa #crticial pressure
Tc = 132.5 #K
vc = 0.0883 #m**3/kmol
p = 10.e5 #Pa
T = 300. #K
# Calculations and Results
R = 287. #J/kgK
pR = p/pc #reduced pressure
TR = T/Tc #reduced temperature
v = Z*R*T/p #m**3/kg
vR = v/vc #reduced volume
print "Reduced pressure = %.5f "%(pR)
print "Reduced temperature = %.5f "%(TR)
print "Reduced volume = %.3f "%(vR)
# Variables
pR = 0.26525 #reduced pressure
TR = 2.26415 #reduced temperature
pc = 22.09 #bar #critical pressure of water
Tc = 647.3 #K #critical temperature of water
# Calculations and Results
p = pR*pc #bar
T = TR*Tc #K
print "Temperature at which steam would beahve similar to air at 10 bar and 27°C = %.1f K"%(T)
print "Pressure at which steam would beahve similar to air at 10 bar and 27°C = %.2f bar"%(p)
# Variables
pc = 3.77e6 #Pa #critical pressure
p = 5.65e6 #Pa
Tc = 132.5 #K #critical temperature
T = 300 #K
# Calculations and Results
pR = p/pc #reduced pressure
TR = T/Tc #reduced temperature
#from generalized compressibilty chart
Z =0.97
print "From the generalized compressiblity chart,\
at reduced pressure of %.1f and reduced temperature of %.2f, Z = %.2f"%(pR,TR,Z)
# Variables
T =150.+273 #K
p = 7e6 #Pa
#Part (i)
print "Parti"
v = (8314.3/44)*T/p #m**3/kg
print "Specific volume for gaseous propane using ideal gas equation = %.4f m**3/kg"%(v)
#Part(ii)
print "Partii"
pc = 4.26e6 #Pa #critical pressure
Tc = 370. #K #critical temperature
pR = p/pc #reduced pressure
TR = T/Tc #reduced temperature
Z = 0.56 #compressibility factor
print "From the generalized compressiblity chart,\
at reduced pressure of %.1f and reduced temperature of %.2f, Z = %.2f"%(pR,TR,Z)
v = Z*v
print "Specific volume for gaseous propane using generalized compressiblity chart = %.5f m**3/kg"%(v)
# Variables
m = 5. #kg #mass of CO2
T = 300. #K
R = 8314.3/44 #J/kgK
V = 1.5 #m**3
#Part(i)
print "Parti"
p = m*R*T/V
print "Pressure exerted by CO2using ideal gas equation) = %.2f kPa"%(p*.001)
#Part(ii)
print "Partii"
R = 8.3143 #J/kmolK
a = 0.3658e3 #kPam**6/kmol**2
b = 0.0428 #m**3.kmol
v = 44*V/m #m**3/kmol
p = T*R/(v-b) - a/v**2
print "Pressure exerted by CO2using van der Waals equation) = %.1f kPa"%(p)
import math
# Variables
M = 28. #g/mol
m = 3.5 #kg
V = 0.015 #m**3
v = V/m #m**3/kg
T = 473. #K
R = 8314.3/M #J/kgK
# Calculations and Results
#Part(i)
print "Parti"
p = m*R*T/V #Pa
print "Pressure using ideal gas equation of state) = %.2f MPa"%(p*1e-6)
#Part(ii)
print "Partii"
pc = 3.39e6 #Pa #critical pressure
Tc = 126.2 #K #critical temperature
vc = 0.0899 #m**3/kmol #critical volume
TR = T/Tc #reduced temperature
vR = v/(R*Tc/pc) #reduced volume
Z = 1.1 #Compressibility factor
print "From the generalized compressiblity chart, \
at reduced volume of %.4f and reduced temperature of %.2f, Z = %.2f"%(vR,TR,Z)
p = Z*R*T/v #Pa
print "Pressure using generalised compressibility chart) = %.3f MPa"%(p*1e-6)
#Part(iii)
print "Partiii"
a = 0.1366e6 #Pam**5/kmol**2
b = 0.0386 #m**3/kmol
p = (8314.3*T/(v*M - b)) - a/(v*M)**2
print "Pressure using van der Waals equation) = %.2f MPa"%(p*1e-6)
#Part(iv)
print "Partiv"
a = (0.427*(R*M)**2*Tc**2.5/pc)
b = 0.0866*(R*M*Tc/pc)
p = (R*M*T/(v*M-b))-(a/(((v*M)**2 + v*M*b)*(T**0.5)))
print "Pressure using Redlich-Kwong equation of state) = %.2f MPa"%(p*1e-6)
#Part(v)
print "Partv"
A0 = 136.2315
a = 0.02617
B0 = 0.05046
b = -0.00691
c = 42000
A = A0*(1 - a/(v*M))
B = B0*(1 - b/(v*M))
eps = c/(T**3 * v*M)
p = ((8314.3)*T*(1-eps)*(v*M+B))/(v*M)**2 - 1e3*A/(v*M)**2
print "Pressure using ideal gas equation of state) = %.2f MPa"%(p*1e-6)
#---Note---
# Calculations and Results to Part(iv) in the textbook is 40.58 MPa which is wrong.
# The correct solution (38.13 MPa) is computed here.