#calculate the entropy in parts ab,ac and efficiency
#Initialization of variables
import math
cv=0.175 #Btu/lbm R
R0=1.986
M=29
T2=1040 #R
T1=520 #R
#calculations
cp=cv+R0/M
sab=cv*math.log(T2/T1)
sac=cp*math.log(T2/T1)
dqab=cv*(T2-T1)
dqca=cp*(T1-T2)
dqrev=T2*(sac-sab)
eta=(dqab+dqrev+dqca)/(dqab+dqrev)*100
#results
print '%s %.4f %s' %("Entropy in ab part =",sab,"Btu/lbm R")
print '%s %.4f %s' %("\n Entropy in ac part =",sac," Btu/lbm R")
print '%s %.2f %s' %("\n Efficiency =",eta," percent")
print '%s' %("The answers are a bit different due to rounding off error in textbook")
#calculate the change in entropy of the process
#Initialization of variables
import math
tc=32. #F
th=80. #F
mw=5 #lbm
mi=1 #lbm
P=14.7 #psia
cp=1
#calculations
t= (-144*mi+tc*mi+th*mw)/(mw+mi)
ds1=144/(tc+460)
ds2=cp*math.log((460+t)/(460+tc))
dsice=ds1+ds2
dswater=mw*cp*math.log((t+460)/(460+th))
ds=dsice+dswater
#results
print '%s %.4f %s' %("Change in entropy of the process =",ds,"Btu/R")
print '%s' %("The answer is a bit different due to rounding off error in textbook")
#calculate the change in available energy
#Initialization of variables
import math
cp=1
T2=60. #F
T1=100. #F
ta=32. #F
#calculations
dq=cp*(T2-T1)
ds=cp*math.log((460+T2)/(460+T1))
dE=dq-ds*(ta+460)
#results
print '%s %.1f %s' %("Change in available energy =",dE,"Btu/lbm")
print '%s' %("The answer is a bit different due to rounding off error in textbook")