# Variables
x = 1.5
P = 14.696 #psia
m = 28.96
# Calculations
mf = 114. # lbm/mol fuel
ma = x*12.5*(1+3.76)*m
AF = ma/mf
n1 = 8.
n2 = 9.
n3 = (x-1)*12.5
n4 = x*3.76*12.5
np = n1+n2+n3+n4
x1 = n1/np
x2 = n2/np
x3 = n3/np
x4 = n4/np
ph = x2*P
Td = 113.5 #F
# Results
print "Air fuel ratio = %.1f lbm air/lbm fuel"%(AF)
print " Mole fraction of CO2 = %.2f percent"%(x1*100)
print " Mole fraction of H2O = %.2f percent"%(x2*100)
print " Mole fraction of O2 = %.2f percent"%(x3*100)
print " Mole fraction of N2 = %.2f percent"%(x4*100)
print ("From tables of saturation pressure")
print "Dew point = %.1f F"%(Td)
# Variables
x1 = 9.
x2 = 1.2
x3 = 1.5
x4 = 88.3
# Calculations
a = x1+x2
b = 2*a
xO = (2*x1 + x2+ 2*x3 + b)/2
xN = x4/3.76
ratio = xO/a
percent = ratio/2 *100
# Results
print "Percent theoretical air = %.1f percent"%(percent)
# Variables
T = 440. #F
# Calculations
h1 = -169290
h2 = 7597.6
h3 = 4030.2
ht = h1+h2-h3
# Results
print "Molal enthalpy of CO2 = %d Btu/lbm mole"%(ht)
# Variables
T = 77. #F
# Calculations
Hr = -36420. #B
hc = -169290. #B/lb mol
hh = -122970. #B/lb mol
Hp = 2*hc+3*hh
Q = Hp-Hr
# Results
print "Heat transfer = %d B/mol fuel"%(Q)
# Variables
T2 = 440. #F
T1 = 77. #F
Mch4 = 16.
Mw = 18.
# Calculations
h77 = 3725.1
ht = 6337.9
ht2 = 7597.6
h772 = 4030.2
hwt = 1260.3
h77w = 45.02
hr77 = -383040. #B/lbm mol
dHR = 1*Mch4*0.532*(T1-T2) + 2*(h77-ht)
dHp = 1*(ht2-h772) + 2*Mw*(hwt - h77w)
hrp = dHp+hr77+dHR
# Results
print "Enthalpy of combustion of gaseous methane = %d B/lbm mol fuel"%(hrp)
#The calculation in textbook is wrong Please check it using a calculator.
# Variables
Hr = -107530. #B/mol fuel
print ("By iteration of temperatures, T = 2700 R")
T = 2700. #R
# Results
print "Adiabatic flame temperature = %d R"%(T)
from numpy import poly1d,roots
# Variables
import math
Kp = 0.668
y = Kp**2
# Calculations
x = poly1d(0)
vec = roots([y,2,-y,-2,0]) #x**3 + y*x**3 + 2*y*x**2 -y*x -2*y)
eps = vec[0]
x1 = (1-eps)/(1+ eps/2)
x2 = eps/(1+eps/2)
x3 = eps/2/(1+ eps/2)
# Results
print "degree of reaction = %.3f "%(eps)
print " Equilibrium concentration of CO2 = %.3f "%(x1)
print " Equilibrium concentration of CO = %.3f "%(x2)
print " Equilibrium concentration of O2 = %.3f "%(x3)
#the answers are different due to approximation in textbook
from numpy import roots
# Variables
Kp = 15.63
y = Kp
# Calculations
vec = roots([y+1,0,-y])#x**2 + y*x**2 - y)
eps = vec[0]
x1 = (1-eps)/(1+eps)
x2 = eps/(1+eps)
x3 = eps/(1+eps)
# Results
print " Equilibrium concentration of Cs = %.4f "%(x1)
print " Equilibrium concentration of Cs+ = %.4f "%(x2)
print " Equilibrium concentration of e- = %.4f "%(x3)
#the answers are a bit different due to approximation in textbook