#calculate the amount of dissociation
#Initalization of variables
import math
import numpy
kp=math.pow(10,(1.45))
#calculations
s=[1-kp*kp , 0, -3, 2]
vec=numpy.roots(s)
X=numpy.real(vec[2])
xper=X*100
#results
print '%s %.1f %s' %("Amount of dissociaton =",xper,"percent")
print '%s %.3f %s %.3f %s %.3f %s' %("\n Of each original mole of CO2, there will be",X,"mole of CO ",X/2.," mol of Oxygen and",(1-X),"mol of CO2")
#calculate the max. temperature reached
#Initalization of variables
U=121200. #Btu/mol
Uco2=51635. #Btu/mol
Un2=27589. #Btu/mol
Uco22=57875. #Btu/mol
Un22=21036. #Btu/mol
T1=5000. #R
T2=5500. #R
#calculations
Ut1=Uco2+1.88*Un2
Ut2=Uco22 + 1.88*Un22
print '%s' %("By extrapolation,")
Tx=5710 #R
#results
print '%s %d %s' %("Max. Temperature reached =",Tx,"R")
print '%s' %("The calculation for Ut2 is wrong in textbook. Please use a calculator.")
#calculate the max. obtainable temperature
#Initalization of variables
print '%s' %("By trial and error,")
import math
X=0.201
X1=0.2
R=59.3 #universal gas constant
T=5000 #R
U=121200 #Btu/mol
Uco2=51635. #Btu/mol
Un2=27907. #Btu/mol
U3=29616. #Btu/mol
U4=27589. #Btu/mol
#calculations
kp1=R*(1-X1)/math.pow(X1,1.5) /math.pow(T,0.5)
kp2=R*(1-X)/math.pow(X,1.5) /math.pow(T,0.5)
q=(1-X)*Uco2 + X*Un2+ X/2 *U3 +1.88*U4 + X*U
print '%s' %("Interpolating between T=4500 R and T=5000 R, we get")
T2=4907 #R
#results
print '%s %d %s' %("Max. obtainable temperature =",T2," R")