#calculate the work done
#Initialization of variables
n=1.3
T1=460+60. #R
P1=14.7 #psia
P2=125. #psia
R=1545.
M=29.
#calculations
T2=T1*(P2/P1)**((n-1)/n)
wrev=R/M *(T2-T1)/(1-n)
#results
print '%s %d %s' %("Work done =",wrev,"ft-lbf/lbm")
print '%s' %("The answer is a bit different due to rounding off error in textbook")
#calculate the Change in kinetic energy
#Initialization of variables
P2=10 #psia
P1=100 #psia
T1=900 #R
w=50 #Btu/lbm
k=1.39
cp=0.2418
#calculations
T2=T1*(P2/P1)**((k-1)/k)
T2=477
KE=-w-cp*(T2-T1)
#results
print '%s %.1f %s' %("Change in kinetic energy =",KE,"Btu/lbm")
#calculate the Final temperature
#Initialization of variables
T1=900 #R
P1=100 #psia
P2=10 #psia
#calculations
print '%s' %("From table B-9")
pr1=8.411
pr2=pr1*P2/P1
T2=468 #R
#results
print '%s %.1f %s' %("Final temperature =",T2,"R ")
#calculate the final temperature and pressure, work done and enthalpy
#Initialization of variables
cr=6
p1=14.7 #psia
t1=60.3 #F
M=29
R=1.986
#calculations
print '%s' %("from table b-9")
vr1=158.58
u1=88.62 #Btu/lbm
pr1=1.2147
vr2=vr1/cr
T2=1050 #R
u2=181.47 #Btu/lbm
pr2=14.686
p2=p1*(pr2/pr1)
dw=u1-u2
h2=u2+T2*R/M
#results
print '%s %d %s' %("final temperature =",T2,"R")
print '%s %.1f %s' %("\n final pressure =",p2," psia")
print '%s %.2f %s' %("\n work done =",dw," Btu/lbm")
print '%s %.1f %s' %("\n final enthalpy =",h2," Btu/lbm")
#calculate the mole fractions of oxygen and nitrogen, Average molecular weight and partial pressures, densities, volumes
#Initialization of variables
m1=10. #lbm
m2=15. #lnm
p=50. #psia
t=60.+460 #R
M1=32.
M2=28.02
R0=10.73
#calculations
n1=m1/M1
n2=m2/M2
x1=n1/(n1+n2)
x2=n2/(n1+n2)
M=x1*M1+x2*M2
R=1545/M
V=(n1+n2)*R0*t/p
rho=p/(R0*t)
rho2=M*rho
p1=x1*p
p2=x2*p
v1=x1*V
v2=x2*V
#results
print '%s' %("part a")
print '%s %.3f %s %.3f %s' %("Mole fractions of oxygen and nitrogen are",x1," and",x2," respectively")
print '%s' %("part b")
print '%s %.1f' %("Average molecular weight = ",M)
print '%s' %("part c")
print '%s %.2f %s' %("specific gas constant =",R,"psia ft^3/lbm R")
print '%s' %("part d")
print '%s %.1f %s' %("volume of mixture =",V,"ft^3")
print '%s %.5f %s %.3f %s' %("density of mixture is",rho, "mole/ft^3 and",rho2, "lbm/ft^3")
print '%s' %("part e")
print '%s %.2f %s %.2f %s' %("partial pressures of oxygen and nitrogen are",p1,"psia and",p2,"psia respectively")
print '%s %.2f %s %.2f %s' %("partial volumes of oxygen and nitrogen are",v1,"ft^3 and",v2,"ft^3 respectively")
#calculate the gravimetric and ultimate analysis
#Initialization of variables
m1=5.28
m2=1.28
m3=23.52
#calculations
m=m1+m2+m3
x1=m1/m*100
x2=m2/m*100
x3=m3/m*100
C=12./44 *m1/ m*100
O=(32./44 *m1 + m2)/m*100
N=m3/m*100
#results
print '%s %.1f %s %.1f %s %.1f %s' %("From gravimetric analysis, co2 =",x1,"percent , o2 =",x2,"percent and n2 =",x3,"percent")
print '%s %.2f %s %.2f %s %.2f %s' %("\n From ultimate analysis, co2 =",C,"percent , o2 =",O," percent and n2 =",N," percent")
#calculate the Entropy of the mixture
#Initialization of variables
import math
x1=1/3.
n1=1.
n2=2.
x2=2/3.
p=12.7 #psia
cp1=7.01 #Btu/mole R
cp2=6.94 #Btu/mole R
R0=1.986
T2=460+86.6 #R
T1=460. #R
p0=14.7 #psia
#calculations
p1=x1*p
p2=x2*p
ds1= cp1*math.log(T2/T1) - R0*math.log(p1/p0)
ds2= cp2*math.log(T2/T1) - R0*math.log(p2/p0)
S=n1*ds1+n2*ds2
#results
print '%s %.2f %s' %("Entropy of mixture =",S,"Btu/R")
print '%s' %("\n the answer given in textbook is wrong. please check using a calculator")
#calculate the change in internal energy and entropy
#Initialization of variables
import math
c1=4.97 #Btu/mol R
c2=5.02 #Btu/mol R
n1=2
n2=1
T1=86.6+460 #R
T2=50.+460 #R
#calculations
du=(n1*c1+n2*c2)*(T2-T1)
ds=(n1*c1+n2*c2)*math.log(T2/T1)
#results
print '%s %d %s' %("Change in internal energy =",du," Btu")
print '%s %.3f %s' %("\n Change in entropy =",ds,"Btu/R")
#calculate the Pressure of the mixture
#Initialization of variables
n1=1
n2=2
c1=5.02
c2=4.97
t1=60. #F
t2=100. #F
R0=10.73
p1=30. #psia
p2=10. #psia
#calcualtions
t=(n1*c1*t1+n2*c2*t2)/(n1*c1+n2*c2)
V1= n1*R0*(t1+460)/p1
V2=n2*R0*(t2+460)/p2
V=V1+V2
pm=(n1+n2)*R0*(t+460)/V
#results
print '%s %.1f %s' %("Pressure of mixture =",pm," psia")
#calculate the change in entropy of gas
#Initialization of variables
import math
T2=546.6 #R
T1=520 #R
T3=560 #R
v2=1389.2
v1=186.2
R0=1.986
c1=5.02
c2=4.97
n1=1
n2=2
v3=1203
#calculations
ds1=n1*c1*math.log(T2/T1) + n1*R0*math.log(v2/v1)
ds2=n2*c2*math.log(T2/T3)+n2*R0*math.log(v2/v3)
ds=ds1+ds2
#results
print '%s %.3f %s' %("Change in entropy for gas 1 =",ds1," Btu/R")
print '%s %.3f %s' %("\n Change in entropy for gas 1 =",ds2,"Btu/R")
print '%s %.3f %s' %("\n Net change in entropy =",ds,"Btu/R")
print '%s' %("The answer is a bit different due to rounding off error in the textbook")
#calculate the Final temperature and change in entropy of air and water.
#Initialization of variables
import math
m1=1. #lbm
m2=0.94 #lbm
M1=29.
M2=18.
p1=50. #psia
p2=100. #psia
t1=250 +460. #R
R0=1.986
cpa=6.96
cpb=8.01
#calculations
xa = (m1/M1)/((m1/M1)+ m2/M2)
xb=1-xa
t2=t1*(p2/p1)**(R0/(xa*cpa+xb*cpb))
d=R0/(xa*cpa+xb*cpb)
k=1/(1.-d)
dsa=cpa*math.log(t2/t1) -R0*math.log(p2/p1)
dSa=(m1/M1)*dsa
dSw=-dSa
dsw=dSw*M2/m2
#results
print '%s %d %s' %("Final temperature =",t2," R")
print '%s %.3f %s %.5f %s' %("\n Change in entropy of air =",dsa," btu/mole R and",dSa, "Btu/R")
print '%s %.4f %s %.5f %s' %("\n Change in entropy of water =",dsw,"btu/mole R and",dSw," Btu/R")
print '%s' %("The answers are a bit different due to rounding off error in textbook")
#calculate the volume occupied and mass of steam
#Initialization of variables
T=250. + 460 #R
p=29.825 #psia
pt=50 #psia
vg=13.821 #ft^3/lbm
M=29.
R=10.73
#calculations
pa=pt-p
V=1/M *R*T/pa
ma=V/vg
xa=p/pt
mb=xa/M *18./(1.-xa)
#results
print '%s %.2f %s' %("In case 1, volume occupied =",V," ft^3")
print '%s %.2f %s' %("\n In case 1, mass of steam =",ma," lbm steam")
print '%s %.3f %s' %("\n In case 2, mass of steam =",mb," lbm steam")
#calcualte the percentage
#Initialization of variables
ps=0.64 #psia
p=14.7 #psia
M=29.
M2=46.
#calculations
xa=ps/p
mb=xa*9./M *M2/(1-xa)*100
#results
print '%s %.1f %s' %("percentage =",mb,"percent")
#calculate the partial pressure of water vapor
#Initialization of variables
ps=0.5069 #psia
p=20 #psia
m1=0.01
m2=1
M1=18.
M2=29.
#calculations
xw= (m1/M1)/(m1/M1+m2/M2)
pw=xw*p
#results
print '%s %.3f %s' %("partial pressure of water vapor =",pw,"psia")