In [2]:

```
#given data
P1 = 100.; #Pressure at volume V1 = 100 ft**3 #Unit:psia
V1 = 100.; #Unit:ft**3 #V1 = Volume at 100 psia
P2 = 30. # Reduced Pressure #Unit:psia
# Calculations
#Boyle's law,P1*V1 = P2*V2
V2 = (P1*V1)/P2; #Volume occupied by the gas #ft**3
# Results
print "Volume occupied by the gas = %.2f ft**3"%(V2);
```

In [3]:

```
# given data
P1 = 10.**6; #Pressure at volume V1 = 2 m**3 #Unit:Pa
V1 = 2.; #Unit:m**3 #V1 = Volume at 10**6 Pa
P2 = 8.*10**6 # Increased Pressure #Unit:Pa
# Calculations
#Boyle's law,P1*V1 = P2*V2
V2 = (P1*V1)/P2; #Volume occupied by gas #unit:m**3
# Results
print "Volume occupied by gas = %.2f m**3"%(V2);
```

In [4]:

```
# Given value
T1 = 32.+460; #Temperature at volume V1 = 150 ft**3 #Unit:R
V1 = 150.; #Unit:ft**3 #V1 = Volume at 32 F
T2 = 100.+460 # Increased Temperature #Unit:R
# Calculations
#Charles's law,V1/V2 = T1/T2
V2 = (T2*V1)/T1; #Volume occupied by gas #unit:m**3
# Results
print "Volume occupied by gas = %.2f m**3"%(V2);
```

In [5]:

```
#If for this process T2 = 1.25*T1,
# T2/T1 = 1.25
#Therefore,
# p2/p1 = T2/T1 #Charles's law(volume constant)
#Thus,
print "The absolute gas pressure increases by 25 percent";
```

In [6]:

```
#given data
V1 = 4.; #m**3 #initial volume
T2 = 0.+273; #celsius converted to kelvin #gas is cooled to 0 C #final temperature
T1 = 100+273; #celsius converted to kelvin #initial temperature
# Calculations
V2 = V1*(T2/T1); #final volume #Charles's law(pressure constant) #unit:m**3
# Results
print "The final volume is %.2f m**3"%(V2);
```

In [7]:

```
#Let us first put each of the given variables into a consistent set of units:
p = (200+14.7)*(144); #Unit:psfa*(lbf/ft**2) #1 ft**2 = 144 in**2 #pressure
T = (460.+73); #Fahrenheit temperature converted to absolute temperature #unit:R
V = 120./1728; #1 ft**3 = 1728 in**3 #total volume #unit:ft**3
R = 1545./28; #Unit:ft*lbf/lbm*R #because the molecular weight of nitrogen is 28 #constant of proportionality
#Applying, p*v = R*T, #ideal gas law
v = (R*T)/p; #Unit:ft**3/lbm #specific volume
print "The specific volume is %.2f ft**3/lbm"%(v);
#The mass of gas is the total volume divided by the specific volume
print "The gas in the container is %.2f lbm"%(V/v);
#The same result is obtained by direct use of eq. p*V = m*R*T
m = (p*V)/(R*T); #The gas in the container #unit:lbm #ideal gas law
print "The gas in the container is %.2f lbm"%(m);
```

In [8]:

```
#Applying , (p1*V1)/T1 = (p2*V2)/T2
#and p2 = p1*(T2/T1) because V1 = V2
p1 = 200+14.7; #Unit:psia #initial pressure
T2 = 460.+200; #final temperature is 200 F #Fahrenheit temperature converted to absolute temperature #unit:R
T1 = 460+73; #Fahrenheit temperature converted to absolute temperature #unit:R
# Calculations
p2 = p1*(T2/T1); #final pressure #Unit:psia #Charles's law(volume constant)
# Results
print "The final pressure is %.2f psia"%(p2);
```

In [9]:

```
#For CO2,
R = 8.314/44; #Unit:kJ/kg*K #constant of proportionality #Molecular weight of CO2 = 44
p = 500; #Unit:kPa #pressure
V = 0.5; #Unit:m**3 #volume
T = (100.+273); #Unit:K #Celsius converted to kelvin
# Calculations
#Applying p*V = m*R*T ,
m = (p*V)/(R*T); #mass #kg #ideal gas law
# Results
print "The mass of gas in the math.tank is %.2f kg"%(m);
```

In [10]:

```
# given data
T2 = 500+460; #absolute final temperature #unit:R
T1 = 80+460; #absolute initial temperature #unit:R
#The equation cpbar = 0.338-(1.24*10**2/T)+(4.15*10**4)/T**2 has a form , cbar = Adash+(Bdash/T)+(Ddash/T**2)
#So,
Adash = 0.338; #constant
Bdash = -1.24*10**2; #constant
Ddash = 4.15*10**4; #constant
# Calculations
#Therefore,from equation,cbar = Adash+((Bdash*math.log(T2/T1))/(T2-T1))+(Ddash/(T2*T1))
cpbar = Adash+((Bdash*math.log(T2/T1))/(T2-T1))+(Ddash/(T2*T1)); #The mean specific heat #Btu/lbm*R
# Results
print "The mean specific heat at constant pressure between 80F and 500F is %.2f Btu/lbm*R"%(cpbar);
```

In [12]:

```
#The table in Appendix 3 does not give us the enthalpy data at 960R and 540R that we need.Interpolating yields
# T hbar T hbar
# 537 3729.5 900 6268.1
# 540 3750.4 960 6694.0
# 600 4167.9 1000 6977.9
#So,
hbar540 = 3729.5+(3./63)*(4167.9-3729.5); #enthalpy #unit:Btu/lbm
hbar960 = 6268.1+(60./100)*(6977.9-6268.1); #enthalpy #unit:Btu/lbm
#Note that hbar is given for a mass of 1 lb mole.To obtain the enthalpy per pound,it is necessary to divide the values og h by the molecular weight,28.
h2 = 6694.0; #enthalpy #unit:Btu/lbm
h1 = 3750.4; #enthalpy #unit:Btu/lbm
T2 = 500.+460; #absolute final temperature #unit:R
T1 = 80.+460; #absolute initial temperature #unit:R
# Calculations
cbar = (h2-h1)/(28*(T2-T1)); #The mean specific heat at constant pressure #unit:Btu/lbm*R
# Results
print "The mean specific heat at constant pressure is %.2f Btu/lbm*R"%(cbar);
#With the more extesive Gas tables,these interpolations are avoided.The Gas Tables provide a relatively easy and accurate method of obtaining average specific heats.Also,these tables have been computerized for ease of application.
```

In [13]:

```
# given data
T2 = 500+460; #absolute final temperature #unit:R
T1 = 80+460; #absolute initial temperature #unit:R
#cp = 0.219 + (3.42*10**-5*T) - (2.93*10**-9*T**2); #Unit:Btu/lbm*R
#Comparing with c = A+(B*T)+(D*T**2)
A = 0.219; #constant
B = 3.42*10**-5; #constant
D = 2.93*10**-9; #constant
# Calculations
#Using these values and equation cbar = A+((B/2)(T2+T1))+((D/3)*(T2**2+(T2*T1)+T1**2))
cpbar = A+((B/2)*(T2+T1))+((D/3)*(T2**2+(T2*T1)+T1**2)); #The mean specific heat #Btu/lbm*R
# Results
print "The mean specific heat at constant pressure for air between 80F and 500F is %.2f Btu/lbm*R"%(cpbar);
```

In [14]:

```
#The molecular weight of oxygen is 32.Therefore,
R = 1545./32; #Unit:ft*lbf/lbm*R #constant of proportionality
J = 778.; #conversion factor
cp = 0.24; #Unit:Btu/lbm*R #specific heat at constant pressure
# Calculations
#cp-cv = R/J
cv = cp-(R/J); #specific heat at constant volume #unit:Btu/lbm*R
# Results
print "Specific heat at constant volume is %.2f Btu/lbm*R"%(cv);
```

In [15]:

```
#From equation,cv = R/(k-1) ,
R = 8.314/32; #constant of proportionality #kJ/kg*K #The molecular weight of oxygen is 32
k = 1.4 #for oxygen #given #k = cp/cv
cv = R/(k-1); #Specific heat at constant volume #unit:kJ/kg*K
print "Specific heat at constant volume is %.2f kJ/kg*K"%(cv);
cp = k*cv; #specific heat at constant pressure #Unit:kJ/kg*K
print "Specific heat at constant pressure is %.2f kJ/kg*K"%(cp);
```

In [16]:

```
# given data
R = 60.; #Unit:ft*lbf/lbm*R #constant of proportionality
deltah = 500.; #Btu/lbm #change in enthalpy
deltau = 350.; #Btu/lbm #change in internal energy
J = 778.; #conversion factor
#Because deltah-(cp*deltaT) and deltau = cv*deltaT
# deltah/deltau = (cp*deltaT)/(cv*deltaT) = cp/cv = k
k = deltah/deltau; #Ratio of specific heats
print "Ratio of specific heats k is %.2f"%(k);
#From equation cv = R/(J*(k-1))
cv = R/(J*(k-1)); #specific heat at constant volume #Btu/lbm*R
print "Specific heat at constant volume is %.2f Btu/lbm*R"%(cv);
cp = k*cv; #Specific heat at constant pressure #Btu/lbm*R
print "Specific heat at constant pressure is %.2f Btu/lbm*R"%(cp);
```

In [17]:

```
#When solving this type of problem,it is necessary to note carefully the information given and to write the correct energy equation for this process.Because the process is carried out at constant volume,the heat added equals the change in inernal energy.Because the change in internal energy per pound for the ideal gas is cv*(T2-T1),the total change in internal energy for m pounds must equals the heat added.Thus,
#data given
Q = 0.33; #heat
#Initial conditions
V = 60; #in**3 #volume
m = 0.0116; #lbs #mass
p1 = 90; #psia #pressure
T1 = 460+40; #Fahrenheit temperature converted to absolute temperature
#Final condition = Initial condition + heat
V = 60; #in**3 #volume
m = 0.0116; #lbs #mass
p2 = 108; #psia #pressure
T2 = 460+140; #Fahrenheit temperature converted to absolute temperature #unit:R
#Q = m*(u2-u1) = m*cv*(T2-T1)
# Calculations and Results
cv = Q/(m*(T2-T1)); #specific heat at constant volume #Btu/lbm*R
print "Specific heat at constant volume is %.2f Btu/lbm*R"%(cv);
#To obtain cp,it is first necessary to obtain R.Enough information was given in the initial conditions of the problem to apply eqn. p*V = m*R*T
R = (144*p1*(V/1728.))/(m*T1); #1 ft**2 = 144 in**2 #1 ft**3 = 1728 in**3 #Unit:ft*lbf/lbm*R #constant of proportionality
print "Consmath.tant of proportionality R is %.2f ft*lbf/lbm*R"%(R);
#cp-cv = (R/J)
J = 778.; #conversion factor
cp = cv+(R/J); #Specific heat at constant pressure #Btu/lbm*R
print "Specific heat at constant pressure is %.2f Btu/lbm*R"%(cp);
```

In [19]:

```
import math
#data
cp = 0.24; #Specific heat at constant pressure #Btu/lbm*R
p2 = 15.; #psia #final pressure
p1 = 100.; #psia #initial pressure
T2 = 460.+0; #absolute final temperature #unit:R
T1 = 460.+100; #absolute initial temperature #unit:R
J = 778.; #conversion factor
R = 1545./29; #moleculer weight = 29 #Unit:ft*lbf/lbm*R #constant of proportionality
# Calculations
#On the basis of the data given,
deltas = (cp*(math.log(T2/T1)))-((R/J)*(math.log(p2/p1))); #change in entropy #Btu/lbm*R
# Results
print "The change in enthalpy is %.2f Btu/lbm*R"%(deltas);
```

In [21]:

```
import math
#data of problem6.16
cp = 0.24; #Specific heat at constant pressure #Btu/lbm*R
p2 = 15.; #psia #final pressure
p1 = 100.; #psia #initial pressure
T2 = 460.+0; #absolute final temperature #unit:R
T1 = 460.+100; #absolute initial temperature #unit:R
J = 778.; #conversion factor
R = 1545./29; #moleculer weight = 29 #Unit:ft*lbf/lbm*R #constant of proportionality
#Because cp and R are given,let us first solve for cv,
#cp = (R*k)/(J*(k-1))
k = (cp*J)/((cp*J)-R); #k = cp/cv #ratio of specific heats
print "Ratio of specific heats k is %.2f"%(k);
#k = cp/cv
cv = cp/k; #Specific heat at constant volume #Btu/lbm*R
print "Specific heat at constant volume is %.2f Btu/lbm*R"%(cv);
#Now, deltas = (cv*math.log(p2/p1))+(cp*math.log(v2/v1));
#But, v2/v1 = (T2*p1)/(T1*p2)
v2byv1 = (T2*p1)/(T1*p2); # v2/v1 #unitless
deltas = (cv*math.log(p2/p1))+(cp*math.log(v2byv1)); #The change in enthalpy #unit:Btu/lbm*R
print "The change in enthalpy is %.2f Btu/lbm*R"%(deltas);
#The agreement is very good.
```

In [23]:

```
import math
#data,
cp = 0.9093; #Specific heat at constant pressure #kJ/kg*R
p2 = 150.; #kPa #final pressure
p1 = 500.; #kPa #initial pressure
T2 = 273.+0; #final temperature #Celsius converted to kelvin
T1 = 273.+100; #initial temperature #Celsius converted to kelvin
#J = 778; #conversion factor
R = 8.314/32; #moleculer weight of oxygen = 32 #Unit:ft*lbf/lbm*R #constant of proportionality
# Calculations
#Using equation, and dropping J gives,
deltas = (cp*(math.log(T2/T1)))-((R)*(math.log(p2/p1))); #change in entropy #kJ/kg*K
#For 2 kg,
deltaS = 2*deltas; #The change in enthalpy in kJ/K
# Results
print "For 2 kg oxygen, The change in enthalpy is %.2f kJ/K"%(deltaS);
```

In [25]:

```
#from the equation, deltas/cv = (k*math.log(v2/v1))+ math.log(p2/p1) #change in entropy
k = 1.4; #k = cp/cv #ratio of specific heats
#deltas = (1/4)*cv #so,
# 1/4 = (k*math.log(v2/v1))+ math.log(p2/p1)
v2 = 1./2; #Because,v2 = (1/2)*v1 #initial specific volume
v1 = 1.; #final specific volume
# Calculations
p2byp1 = math.exp((1./4)-(k*math.log(v2/v1))); #increase in pressure
# Results
print "p2/p1 = %.2f"%(p2byp1);
print "So, increase in pressure is %.2f "%(p2byp1);
```

In [27]:

```
#data
T2 = 460+270; #Fahrenheit temperature converted to absolute final temperature #unit:R
T1 = 460+70; #Fahrenheit temperature converted to absolute initial temperature #unit:R
cv = 0.17; #specific heat at constant volume #Btu/lbm*R
# Calculations
#Now,
deltas = cv*math.log(T2/T1); #change in entropy #Unit:Btu/lbm*R
#For 1/2 lb,
deltaS = (1./2)*deltas; #The change in enthalpy in Btu/R
# Results
print "For 1/2 lb of gas, The change in enthalpy is %.2f Btu/R"%(deltaS);
```

In [29]:

```
#data
T2 = 100.+273; #Celsius temperature converted to Kelvin #final temperature
T1 = 20+273; #Celsius temperature converted to Kelvin #initial temperature
cv = 0.7186; #specific heat at constant volume #kJ/kg*K
#Now,
deltas = cv*math.log(T2/T1); #change in entropy #Unit:kJ/kg*K
#For 0.2 kg,
deltaS = (0.2)*deltas; #The change in enthalpy in kJ/K
print "For 0.2 kg of air, The change in enthalpy is %.2f kJ/K"%(deltaS);
```

In [30]:

```
#data
deltas = 0.0743; #change in entropy #Unit:Btu/lbm*R
T1 = 460+100; #Fahrenheit temperature converted to absolute initial temperature
cv = 0.219; #specific heat at constant volume #Btu/lbm*R
#Now,
# Calculations
#deltas = cv*math.log(T2/T1);
T2 = T1*math.exp(deltas/cv); #higher temperature #absolute temperature #unit:R
# Results
print "The higher temperature is %.2f R"%(T2)
```

In [31]:

```
#data
deltaS = 0.4386; #change in entropy #Unit:kJ/K
T2 = 273+425; #Celsius temperature converted to kelvin #initial temperature
cv = 0.8216; #specific heat at constant volume #kJ/kg*K
m = 1.5; #mass #kg
#Now,
# Calculations
#deltas = m*cv*math.log(T2/T1);
T1 = T2/(math.exp(deltaS/(m*cv))) #initial temperature #unit:K
# Results
print "The initial temperature of the process is %.2f K or %.2f C"%(T1,T1-273)
```

In [32]:

```
#data given
T2 = 460.+400; #Fahrenheit temperature converted to absolute final temperature #unit:R
T1 = 460.+70; #Fahrenheit temperature converted to absolute initial temperature #unit:R
cp = 0.24; #specific heat at constant pressure #Btu/lbm*R
J = 778.; #conversion factor
R = 1545./29; #moleculer weight = 29 #Unit:ft*lbf/lbm*R #constant of proportionality
#From the energy equation for the constant-pressure process,the heat transferred is deltah.Therefore,
#q = deltah = cp*(T2-T1)
deltah = cp*(T2-T1); #heat transferred #Btu/lb #into system
print "The heat transferred is %.2f Btu/lbinto system)"%(deltah);
deltas = cp*math.log(T2/T1); #increase in entropy #Btu/lbm*R
print "The increase in entropy is %.2f Btu/lbm*R"%(deltas);
#The flow work change is (p2*v2)/J - (p1*v1)/J = (R/J)*(T2-T1)
flowworkchange = (R/J)*(T2-T1); #Btu/lbm #The flow work change per pound of air
print "The flow work change per pound of air is %.2f Btu/lbm"%(flowworkchange);
#In addition to each of the assumptions made in all the process being considered,it has further been tacitly assumed that these processes are carried out quasi- statically and without friction.
```

In [33]:

```
#data given
T2 = 500.+273; #Celsius temperature converted to Kelvin #final temperature
T1 = 20+273; #Celsius temperature converted to Kelvin #initial temperature
cp = 1.0062; #specific heat at constant pressure #kJ/kg*K
#From the energy equation for the constant-pressure process,the heat transferred is deltah.Therefore,
#q = deltah = cp*(T2-T1)
deltah = cp*(T2-T1); #heat transferred #kJ/kg #into system
print "The heat transferred is per kimath.logram of air %.2f kJ/kg"%(deltah);
deltas = cp*math.log(T2/T1); #increase in entropy #kJ/kg*K
print "The increase in entropy per kimath.logram of air is %.2f kJ/kg*K"%(deltas);
```

In [34]:

```
#data given
v2 = 2.; #Because,v2 = (2)*v1 #volume increases to its twice its final volume
v1 = 1.; #initial volume
T = 460.+200; #Fahrenheit temperature converted to absolute temperature
J = 778.; #conversion factor
R = 1545./28; #moleculer weight of nitrogen = 28 #Unit:ft*lbf/lbm*R #constant of proportionality
#From the equation, w/J = q = T*deltas = ((R*T)/J)*math.log(v2/v1)
q = ((R*T)/J)*math.log(v2/v1); #Btu/lbm #the heat added to system
#For 0.1 lb,
Q = 0.1*q; #Btu #the heat added to system
print "The heat added to system is %.2f Btu"%(Q);
#The work out of the system is equal to the heat added;thus,
WbyJ = Q; #The work out of the system(out of the system) #unit:Btu
print "The work out of the system is %.2f Btuout of the system)"%(WbyJ);
```

In [35]:

```
#data given
T = 50+273; #Celsius temperature converted to Kelvin #final temperature #unit:K
v2 = 1./2; #Because,v2 = (1/2)*v1 #volume increases to its half its final volume
v1 = 1.;
R = 8.314/32; #moleculer weight of oxygen = 32 #Unit:kJ/kg*K #constant of proportionality
#From the equation, q = ((R*T))*math.log(v2/v1)
q = R*T*math.log(v2/v1); #heat added #kJ/kg
print "The heat added to system is %.2f kJ/kgheat out of system)"%(q);
#The work out of the system is equal to the heat added;thus,
W = q; #The work out of the system #unit:kJ/kg
print "The work out of the system is %.2f kJ/kginto system)"%(W);
```

In [36]:

```
#data given in problem 6.27
T = 50+273; #Celsius temperature converted to Kelvin #final temperature
v2 = 1./2; #Because,v2 = (1/2)*v1 #volume increases to its half its final volume
v1 = 1;
R = 8.314/32; #moleculer weight of oxygen = 32 #Unit:kJ/kg*K #constant of proportionality
#From the equation, q = ((R*T))*math.log(v2/v1)
q = R*T*math.log(v2/v1); #heat added #kJ/kg
print "The heat added to system is %.2f kJ/kgheat out of system)"%(q);
#For a constant temperature,
deltas = q/T; #Change in entropy #unit:kJ/kg*K
print "The change in entropy is %.2f kJ/kg*K"%(deltas);
```

In [37]:

```
#data given
T1 = 1000; #absolute initial temperature #unit:R
p2 = 1.; #unit:atm #absolute final pressure
p1 = 5.; #unit:atm #absolute initial pressure
J = 778.; #conversion factor
R = 1545./29; #moleculer weight = 29 #Unit:ft*lbf/lbm*R #constant of proportionality
k = 1.4; #k = cp/cv #ratio of specific heats
# Calculations and Results
#From the equation,
T2 = T1*((p2/p1)**((k-1)/k)); #Unit:R #The absolute final temperature
print "The absolute final temperature is %.2f R"%(T2);
work = (R*(T2-T1))/(J*(1-k)); #Btu/lbm #The work done by air(out)
print "The work done by air is %.2f Btu/lbmout)"%(work)
```

In [38]:

```
#data given
#mass of 1 kg
T1 = 500+273; #Celsius temperature converted to Kelvin #final temperature
p2 = 1.; #atm #absolute final pressure
p1 = 5.; #atm #absolute initial pressure
J = 778.; #conversion factor
R = 8.314/29; #moleculer weight = 29 #Unit:kJ/kg*K #constant of proportionality
k = 1.4; #k = cp/cv #ratio of specific heat
#From the equation,
T2 = T1*((p2/p1)**((k-1)/k)); #Unit:Kelvin #The absolute final temperature
print "The absolute final temperature is %.2f K or %.2f C"%(T2,T2-273);
work = (R*(T2-T1))/((1-k)); #kJ/kg #The work done by air(out)
print "The work done by air is %.2f kJ/kgout)"%(work)
```

In [3]:

```
from numpy.linalg import inv
import math
#data given
T1 = 800.+273; #Celsius temperature converted to Kelvin #initial temperature
T2 = 500.+273; #Celsius temperature converted to Kelvin #final temperature
p2 = 1.; #atm #absolute final pressure
p1 = 5.; #atm #absolute initial pressure
# Calculations
#A gas expands isentropically
#From the equation,
#T2/T1 = ((p2/p1)**((k-1)/k));
#rearranging,
k = inv([[1-((math.log(T2/T1)/math.log(p2/p1)))]]); #k = cp/cv #Ratio of specific heats
# Results
print "Ratio of specific heats k) is %.2f"%(k);
```

In [42]:

```
#data given
n = 1.3; #p*v**1.3 = constant
k = 1.4; #k = cp/cv Ratio of specific heats
cp = 0.24; #specific heat at constant pressure #Btu/lbm*R
T2 = 600.; #absolute final temperature #unit:R
T1 = 1500.; #absolute initial temperature #unit:R
R = 53.3; #Unit:ft*lbf/lbm*R #constant of proportionality
J = 778.; #conversion factor
cv = cp/k; #specific heat at constant volume #Btu/lbm*R
#Therefore,
cn = cv*((k-n)/(1-n)); #Polytropic specific heat #Btu/lbm*R
print "Polytropic specific heatcn, is %.2f Btu/lbm*R"%(cn);
#The negative sign of cn indicates that either the heat transfer for the process comes from the system or there is a negative temperature change while heat is transferred to the system.
#The heat transferred is cn*(T2-T1).Therefore,
q = cn*(T2-T1); #heat transferred #Btu/lbm(to the system)
print "The heat transferred is %.2f Btu/lbmto the system"%(q);
#The work done can be found Using equation,
w = (R*(T2-T1))/(J*(1-n)); #Btu/lbm #the workdone(from the system)
print "The work done is %.2f Btu/lbmfrom the system"%(w);
deltas = cn*math.log(T2/T1) #change in entropy #Btu/lbm*R
print "The change in enthalpy is %.2f Btu/lbm*R"%(deltas);
```

In [43]:

```
#data given in problem 6.32,
n = 1.3; #p*v**1.3 = constant
k = 1.4; #k = cp/cv #ratio of specific heats
cp = 0.24; #specific heat at constant pressure #Btu/lbm*R
T2 = 600.; #absolute final temperature #unit:R
T1 = 1500.; #absolute initial temperature #unir:R
R = 53.3; #Unit:ft*lbf/lbm*R #constant of proportionality
J = 778.; #conversion factor
#Equation,
# T1/T2 = ((p1/p2)**((n-1)/n));
#rearranging,
p1byp2 = math.exp(math.log(T1/T2)/((n-1)/n)); #The ratio of inlet to outlet pressure
print "The ratio of inlet to outlet pressure is %.2f"%(p1byp2);
```

In [44]:

```
#From the table at 1000 R: #From the table at 500 R:
h2 = 240.98;
h1 = 119.48;
#Btu/lbm #enthalpy #Btu/lbm #enthalpy
u2 = 172.43;
u1 = 85.20;
#Btu/lbm #internal energy #Btu/lbm #internal energy
fy2 = 0.75042;
fy1 = 0.58233;
#Btu/lbm*R #Btu/lbm*R
#The change in enthalpy is
deltah = h2-h1; #Btu/lbm
#The change in internal energy is
deltau = u2-u1; #Btu/lbm
print "The change in enthalpy is %.2f Btu/lbm & the change in internal energy is %.2f Btu/lbm"%(deltah,deltau);
#Because in the constant-pressure process -R*math.log(p2/p1) is zero,
deltas = fy2-fy1; #Btu/lbm*R #The entropy when air is heated at constant pressure
print "The entropy when air is heated at constant pressure is %.2f Btu/lbm/R"%(deltas);
```

In [45]:

```
#In this problem,the air expands from 5 atm absolute to 1 atm absolute from an initial temperature of 1000R,
pr = 12.298; #relative pressure #unit:atm
h = 240.98; #Btu/lbm #enthalpy
pr = 12.298/5; #The value of the final relative pressure #unit:atm
#Interpolation in the air table yields the following:
# T pr
# 620 2.249
# 2.4596
# 640 2.514
T = 620+(((2.4596-2.249)/(2.514-2.249))*20); #the final temperature #unit:R
print "The absolute final temperature is %.2f R"%(T);
u1 = 172.43; #initial internal energy #Btu/lbm
u2 = 108.51; #final internal energy #Btu/lbm
work = u1-u2; #Btu/lbm The work done by air in an isentropic nonflow expansion #where the value of u2 is obtained by interpolation at T temperature and the value of u1 is read from the air table at 1000 R.
print "The work done by air in an isentropic nonflow expansion is %.2f Btu/lbmout)"%(work)
```

In [46]:

```
import math
# given data
T = 1000+460; #Fahrenheit temperature converted to absolute temperature
#The velocity of sound in air at 1000 F is
Va = 49.0*math.sqrt(T); #velocity #ft/s
print "The velocity of sound air at 1000 F is %.2f ft/s"%(Va);
#Hydrogen has a specific heat ratio of 1.41 and R = 766.53.Therefore,
khydrogen = 1.41; #specific heats ratio for air
kair = 1.40; #specific heats ratio for air
Rhydrogen = 766.53; #gas constant #ft*lbf/lbm*R
Rair = 53.36; #gas constant #ft*lbf/lbm*R
# Vahydrogen/Vaair = math.sqrt((Rhydrogen*khydrogen)/(Rair*kair))
#rearranging,
Vahydrogen = Va*math.sqrt((Rhydrogen*khydrogen)/(Rair*kair)); #The velocity of sound in hydrogen at 1000 F #unit:ft/s
print "The velocity of sound in hydrogen at 1000 F is %.2f ft/s"%(Vahydrogen);
```

In [47]:

```
import math
# given data
T = 200+460.; #Fahrenheit temperature converted to absolute temperature #unit:R
V = 1500; #ft/s #the local velocity
Va = 49.0*math.sqrt(T); #velocity of sound air at 200 F #unit:ft/s
print "The velocity of sound air at 200 F is %.2f ft/s"%(Va);
M = V/Va; #The Mach number = the local velocity/velocity of sound #unitless
print "The Mach number is %.2f"%(M);
```

In [48]:

```
#data given
V = 1000; #ft/s #the fluid velocity
gc = 32.17; #Unit:(LBm*ft)/(LBf*s**2) #gc is constant of proportionality
J = 778; #conversion factor
h = 1204.4; #Btu/lbm #enthalpy of saturated steam
#h0-h = V**2/(2*gc*J)
h0 = h+((V**2)/(2*gc*J)); #Btu/lbm #h0 = stagnation enthalpy
print "The total enthalpy is %.2f Btu/lbm"%(h0);
#It will be noted for this problem that if the initial velocity had been 100ft/s,deltah would have been 0.2 Btu/lbm,and for most practical purpposes,the total properties and those of the flowing fluid would have been essentially the same.Thus,for low-velocity fluids,the difference in total and steam properties can be neglected.
```

In [4]:

```
import math
from numpy.linalg import inv
# given data
k = 1.4; #the specific heats ratio #k = cp/cv
M = 1; #(table 6.5) #The Mach number = the local velocity/velocity of sound
T0 = 800; #absolute temperature #unit:R
gc = 32.17; #Unit:(LBm*ft)/(LBf*s**2) #gc is constant of proportionality
R = 53.35; #gas constant #ft*lbf/lbm*R
p0 = 300; #psia #pressure
# * or "star" subscripts to conditions in which M = 1;
# "0" subscript refers to isentropic stagnation
#Refer to figure 6.26,
#Tstar/T0 = 0.8333
Tstar = T0*0.8333; #temperature when M = 1 #unit:R
print "If the mach number at the outlet is unity, temperature is %.2f R"%(Tstar);
Vat = math.sqrt(gc*R*Tstar*k); #ft/s #Vat = V2 #local velocity of sound
print "If the mach number at the outlet is unity, velocity is %.2f ft/s"%(Vat)
#For A/Astar = 2.035
#The table yields
M1 = 0.3; #mach number at inlet
print "At inlet, The mach number is %.2f"%(M1)
#pstar/p0 = 0.52828
pstar = p0*0.52828; #pressure when M = 1 #psia
#also,
#T1/T0 = 0.98232 and p1/p0 = 0.93947
#Therefore,
T1 = T0*0.982332; #unit:R #T1 = temperature at inlet
print "At inlet, The temperature is %.2f R"%(T1);
p1 = p0*0.93947; #psia #p1 = pressure at inlet
print "At inlet, The pressure is %.2f psia"%(p1);
#From the inlet conditions derived,
Va1 = math.sqrt(gc*k*R*T1); #ft/s #V1 = velocity at inlet
V1 = M1*Va1; #ft/s #velocity
print "At inlet, The velocity is %.2f ft/s"%(V1);
#The specific volume at inlet is found from the equation of state for an ideal gas:
v = (R*T1)/(p1*144); #ft**3/lbm #1 ft**2 = 144 in**2(for conversion of unit) #specific volume
rho = inv([[v]]); #inverse of specific volume #density
A = 2.035; #area #ft**2
m = rho*A*V1; #mass flow #unit:lbm/s
print "At inlet, The mass flow is %.2f lbm/s"%(m);
```

In [50]:

```
# * or "star" subscripts to conditions in which M = 1;
# "0" subscript refers to isentropic stagnation
#This problem will be solved by two methods(A and B)
print "Method A"; #By equations:
k = 1.4; #the specific heat ratio #k = cp/cv
R = 53.3; #gas constant #ft*lbf/lbm*R
M = 2.5; #mach number = the local velocity/velocity of sound
print "Solution for a";
# T/Tstar = (k+1)/(2*(1+((1/2)*(k-1)*M**2)))
# Tstar/T0 = 2/(k+1)
#Therefore,
# (Tstar/T0)*(T/Tstar) = (T/T0) = 1/(1+((1/2)*(k-1)*M**2))
T0 = 560; #absolute temperature or stagnation temperature #unit:R
T = T0/(1+((1/2)*(k-1)*M**2)); #temperature at M = 2.5
print "The temperature is %.2f R"%(T);
print "Solution for b";
p = 0.5; #static pressure #unit:psia
# p0/p = (T0/T)**(k/(k-1))
p0 = p*14.7*((T0/T)**(k/(k-1))); #pressure at M = 2.5 #unit:psia
print "The pressure is %.2f psia"%(p0);
print "Solution for c";
gc = 32.17; #Unit:(LBm*ft)/(LBf*s**2) #gc is constant of proportionality
Va = math.sqrt(gc*k*R*T); #ft/s #local velocity of sound
V = M*Va; #valocity at M = 2.5 #unit:ft/s
print "The velocity is %.2f ft/s"%(V);
print "Solution for d";
v = (R*T)/(p*14.7*144); #ft**3/lbm #1 ft**2 = 144 in**2 #specific volume at M = 2.5
print "The specific volume is %.2f ft**3/lbm"%(v);
print "Solution for e";
#Mass velocity is definrd as the mass flow per unit area
# m/A = (A*V)/(v*A) = V/v
print "The mass velocity is %.2f lbm/s*ft**2)"%(V/v); #mass velocity at M = 2.5
print "Method B"; #By the gas tables: #table 6.5 gives
M = 2.5; #mach number = the local velocity/velocity of sound
print "Solution for a";
T0 = 560; #absolute temperature or stagnation temperature
#T/T0 = 0.44444
T = T0*0.44444; #temperature at M = 2.5
print "The temperature is %.2f R"%(T)
print "Solution for b";
p = 0.5; #static pressure
#p/p0 = 0.05853
p0 = (p*14.7)/0.05853; #pressure at M = 2.5
print "The pressure is %.2f psia"%(p0);
print "Solution for c";
print "As before %.2f ft/s"%(V)
print "Solution for d";
print "As before %.2f ft**3/lbm"%(v)
print "Solution for e";
print "As before %.2f lbm/s*ft**1)"%(V/v)
```

In [51]:

```
#For Methane(CH4,MW = 16)
p = 500; #evaluate specific volume at p pressure #Unit:psia
pc = 674; #critical temperature #Unit:psia
T = 50+460; #evaluate specific volume at T temperature #Unit:R
Tc = 343; #critical temperature #Unit:R
R = 1545./16; #gas constant R = 1545/Molecular Weight #ft*lbf/lbm*R
pr = p/pc; #reduced pressure #unit:psia
Tr = T/Tc; #reduced temperature #unit:R
#Reading figure 6.28 at these values gives
Z = 0.93; #compressibility factor
#Z = (p*v)/(R*T)
v = Z*((R*T)/(p*144)); #ft**3/lbm #1 ft**2 = 144 in**2(for conversion of unit) #specific volume
print "Using the value of Z = 0.93, the specific volume is %.2f ft**3/lbm"%(v);
#For ideal gas,
v = (R*T)/(p*144); #ft**3/lbm #1 ft**2 = 144 in**2(for conversion of unit) #specific volume
print "For the ideal gas, the specific volume is %.2f ft**3/lbm"%(v);
```