In [12]:

```
from __future__ import division
print "Example: 3.1 - Page: 88\n\n"
# Solution
#*****Data*****
P = 2*10**5## [Pa]
T = 273 + 37## [K]
R = 8.314## [J/mol K]
#****************
# Since the gas behaves ideally:
V = R*T/P## [cubic metres]
print "Molar Volume of the gas is %.2e cubic metres"%(V)#
```

In [13]:

```
from __future__ import division
print "Example: 3.2 - Page: 89\n\n"
# Solution
#*****Data*****
V1 = 8## [cubic m]
P1 = 300## [kPa]
V2 = 2## [cubic m]
#**************
# Apptying the ideal gas Eqn. & since the Temperature remains constant:
P2 = P1*V1/V2## [kPa]
print "The pressure of air after compression is %d kPa\n"%(P2)#
```

In [14]:

```
from __future__ import division
print "Example: 3.3 - Page: 89\n\n"
# Solution
#*****Data*****
V1 = 6## [cubic m]
P1 = 500## [kPa]
R = 0.287## [kJ/kg K]
#*************
# Applying the charectarstic equation to the gas initially:
# P1*V1 = m1*R*T1.......................................(i)
# Applying the charectarstic equation to the gas which was left in the vessel after one-fifth of the gas has been removed:
# P2*V2 = m2*R*T2.......................................(ii)
# V2 = V1# T2 = T1# m2 = (4/5)*m1# Eqn (ii) becomes:
# P2*V1 = (4/5)*m1*R*T1..................................(iii)
# Dividing eqn (i) by eqn (iii), we get:
P2 = (4/5)*P1## [kPa]
print "The pressure of the remaining air is %d kPa\n"%(P2)#
```

In [15]:

```
from __future__ import division
print "Example: 3.4 - Page: 90\n\n"
# Solution
#*****Data*****
T1 = 450 + 273## [K]
P1 = 3## [bar]
#***************
# Soluton(a)
# From Fig. 3.7, (Page 90)
# Since the weight remains the same, therefore, the final pressure is equal to the initial pressure.
# Therefore it is a constant pressure process.
P2 = P1## [bar]
# Volumetric Ratio:
V2_by_V1 = 2.5/(2.5 + 2.5)# Applying ideal gas law & P1 = P2
T2 = T1*V2_by_V1## [K]
print "Final Temperature of the air when the piston reaches stop is %.1f K\n"%(T2)
# Solution (b)
# When the piston rests ot the stops, the pressure exerted by the weight, air & the atmosphere will be different. But there will beno further decrease in volume.
# This is a constant volume process.
T3 = 273 + 30## [K]
# Applying ideal gas law & V2 = V3
P3 = T3*P2/T2## [bar]
print "Pressure of air inside the cylinder is %.2f bar\n"%(P3)#
```

In [16]:

```
from __future__ import division
print "Example: 3.5 - Page: 95\n\n"
# Solution
#*****Data*****
m = 1.373## [kg]
P = 1.95*10**(6)## [Pa]
V = 0.1## [cubic m]
a = 422.546*10**(-3)## [cubic m/square mol]
b = 37*10**(-6)## [cubic m/mol]
M = 17*10**(-3)## [kg/mol]
R = 8.314## [J/mol K]
#****************
n = m/M## [moles]
Vm = V/n## [molar volume, cubic m]
# Applying Van der Waals equation of state:
T = (P + (a/Vm**2))*((Vm - b)/R)## [K]
print "The temperature at which ammonia exists in the cylinder is %.1f K\n"%(T)
```

In [17]:

```
from scipy.optimize import fsolve
from __future__ import division
print "Example: 3.6 - Page: 96\n\n"
# Solution
#*****Data*****
P = 15*10**5## [Pa]
T = 773## [K]
R = 8.314## [J/mol K]
#**************
# Solution (a)
print "Ideal Equation of State\n"
# Applying ideal Eqn. of State:
Vm = R*T/P## [cubic m/mol]
print "Molar Volume of the gas is %.3e cubic m/mol\n"%(Vm)
print "\n"
# Solution (b)
print "Van der Wall Equation of State\n"
a = 0.2303## [Nm**4/square mol]
b = 4.3073*10**(-5)## [cubic m/mol]
#deff('[y] = f1(Vm)','y = P - (R*T/(Vm-b)) + (a/Vm**2)')
def f1(Vm):
y = P - (R*T/(Vm-b)) + (a/Vm**2)
return y
Vm = fsolve(f1,Vm)## [cubic m/mol]
print "Molar Volume of the gas is %.3e cubic m/mol\n"%(Vm)
print "\n"
#Solution (c)
print "Virial Equation of State\n"
# Z = 1 + B/V
# (P*V/(R*T)) = (1 + B/V)
# V**2 - V*R*T/P - B*R*T/P = 0
B = 1.3697*10**(-5)## [cubic m/mol]
#deff('[y] f2(Vm)','y = Vm**2 - (Vm*R*T/P) - (B*R*T/P)')
def f2(vm):
y = Vm**2 - (Vm*R*T/P) - (B*R*T/P)
return y
Vm = fsolve(f2,7)## [cubic m/mol]
print "Molar Volume of the gas is %.3e cubic m/mol\n"%(Vm)
print "\n"
# Solution (d)
print "Redlich Kwong Equation of State\n"
Tc = 190.6## [K]
Pc = 45.99*10**5## [Pa]
a = 0.4278*R**2*Tc**2.5/Pc## [N/m**4 square mol]
b = 0.0867*R*Tc/Pc## [cubic m/mol]
#deff('[y] = f3(Vm)','y = P - (R*T/(Vm - b)) + (a/((T**0.5)*Vm*(Vm+b)))')
def f3(vm):
y = P - (R*T/(Vm - b)) + (a/((T**0.5)*Vm*(Vm+b)))
return y
Vm = fsolve(f3,Vm+0.5)## [cubic m/mol]
print "Molar Volume of the gas is %.3e cubic m/mol\n"%(Vm)#
```

In [18]:

```
from scipy.optimize import fsolve
from __future__ import division
print "Example: 3.8 - Page: 101\n\n"
# Solution
#*****Data*****
T = 500## [K]
P = 8*10**6## [Pa]
R = 8.314## [J/mol K]
#*************
# Solution (a)
# By ideal gas equation of state:
print "Ideal Equation of State\n"
Vm = R*T/P## [cubic m/mol]
print "Molar Volume of gas is %.3e cubic m/mol\n"%(Vm)
print "\n"
# Solution (b)
# By Virial Equation of State:
print "Virial Equation of State\n"
B = -0.265*10**(-3)## [cubic m/mol]
C = 0.3025*10**(-7)## [m**6/square mol]
#deff('[y] = f(Vm)','y = (P*Vm/(R*T)) - 1 -(B/Vm) - (C/Vm**2)')
def f(vm):
y = (P*Vm/(R*T)) - 1 -(B/Vm) - (C/Vm**2)
return y
Vm = fsolve(f,Vm)
print "Molar Volume of gas is %.2e cubic m/mol\n"%(Vm)#
```

In [19]:

```
from __future__ import division
from math import exp
print "Example: 3.10 - Page: 103\n\n"
# Solution
#*****Data*****
beeta = 1.487*10**(-3)## [1/OC]
alpha = 62*10**(-6)## [1/bar]
V1 = 1.287## [cubic cm /g]
#************
# Solution (a)
# The value of derivative (dP/dT) at constant V:
# dV/V = beeta*dT - alpha*dP
# dV = 0
# dP/dT = beeta/alpha
# Value = dP/dT
Value = beeta/alpha## [bar/OC]
print "Value of derivative is %.2f bar/OC\n"%(Value)
# Solution (b)
P1 = 1## [bar]
T1 = 20## [OC]
T2 = 30## [OC]
# Applying the same equation:
P2 = P1 +(beeta/alpha)*(T2 - T1)## [bar]
print "The pressure generated by heating at constant Volume is %.2f Pa\n"%(P2)
# Solution (c)
T2 = 0## [OC]
T1 = 20## [OC]
P2 = 10## [bar]
P1 = 1## [bar]
# The change in Volume can be obtained as:
V2 = V1*exp((beeta*(T2 - T1)) - alpha*(P2 - P1))## [cubic cm/g]
deltaV = V2 - V1## [cubic cm/g]
print "The change in Volume is %.3f cubic cm/g\n"%(deltaV)#
```

In [20]:

```
from __future__ import division
from math import log10
print "Example: 3.11 - Page: 107\n\n"
# Solution
#*****Data*****
Tc = 513.9## [K]
Pc = 61.48*10**5## [Pa]
#************
Tr = 0.7
T = Tr*Tc - 273.15## [OC]
P_sat = 10**(8.112 - (1592.864/(T + 226.184)))## [mm Hg]
P_sat = P_sat*101325/760## [Pa]
Pr_sat = P_sat/Pc## [Pa]
omega = -1 - log10(Pr_sat)## [Acentric factor]
print "Acentric factor is %.4f"%(omega)#
```