# Chapter 4: Fundamentals of Material Balances¶

## Example 4.2-1, page no. 85¶

In [1]:
#Initialization of variables
input=50000 #ppl/yr
generation=22000 #ppl/yr
consumption=19000 #ppl/yr
output=75000 #ppl/yr
print ("All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
#Calculations and printing:
accumulation = input+generation-output-consumption
print (" We know that accumulation=input+generation-output-consumption")
print '%s %d %s' %('Hence, Each year population decreases by', -accumulation, 'people')
raw_input("Press the Enter key to quit")

All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
We know that accumulation=input+generation-output-consumption
Hence, Each year population decreases by 22000 people
Press the Enter key to quit

Out[1]:
''

## Example 4.2-2, page no. 86¶

In [2]:
#Initilization of variables
inputBenzene=500 #kg/h
inputToluene=500 #kg/h
UpStreamBenzene=450 #kg/h
DownStreamToluene=475 #kg/h
#Calculations and printing:
print("All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("Using benzene balance,")
m2dot=inputBenzene-UpStreamBenzene
print ' %s %d %s' %(' m2dot= ', m2dot, '  kg B/h')
print("Using Toluene balance")
m1dot=inputToluene-DownStreamToluene
print ' %s %d %s' %(' m1dot= ', m1dot, '  kg T/h')
print("To check we can perform Overall mass balance")
raw_input("Press the Enter key to quit")

All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Using benzene balance,
m2dot=  50   kg B/h
Using Toluene balance
m1dot=  25   kg T/h
To check we can perform Overall mass balance
Press the Enter key to quit

Out[2]:
''

## Example 4.2-3, page no. 87¶

In [3]:
#Initialization of variables
m1=200 #g
m2=150 #g
x1=0.4  #methanol/g
x2=0.7  #methanol/g
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
m=m1+m2
print '%s %d %s' %(' Total mass after mixing m=',m, 'g',)
x=(m1*x1 + m2*x2)/m
print'%s  %.2f %s  %.2f' %(' The composition of the methanol in the product is', x ,' and water is', 1-x)
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Total mass after mixing m= 350 g
The composition of the methanol in the product is  0.53  and water is  0.47
Press the Enter key to quit

Out[3]:
''

## Example 4.2-4, page no. 88¶

In [5]:
#Initilization of variables
rate=0.1 #kmol/min
x1=0.1 #mole fraction hexane vapour
vol=10 #m^3
d=0.659 #kg/L
M=86.2 #Kg/kmol
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
ndot=rate/(1-x1)
deltaN= -vol*d*1000 /M
tf=deltaN/(-0.1 * ndot)
print '%s  %.2f %s' %(' The time Required for the Total process= ',tf, 'min')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
The time Required for the Total process=   6880.51 min
Press the Enter key to quit

Out[5]:
''

## Example 4.3-1, page no. 92¶

In [6]:
#Initilization of variables
Vdot=20 #CC/min
x=0.015
MH2O=18.02 #g
DH2O=1 #g/CC
x1=0.2
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
n2=Vdot*DH2O/MH2O
print'%s  %.2f %s' %('n2=', n2, ' mol/min')
print("Using Water Balance,")
n3=n2/x
print'%s  %.2f %s' %('n3=', n3, ' mol/min')
print("Using total mole balance,")
n1=(n3-n2)/(1+x1)
print'%s  %.2f %s' %('n1=', n1, ' mol/min')
print("Using N2 balance,")
y=1-x-0.79*n1/n3
print '%s  %.2f %s' %('y=',y,' mol O2/mol')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
n2=  1.11  mol/min
Using Water Balance,
n3=  73.99  mol/min
Using total mole balance,
n1=  60.73  mol/min
Using N2 balance,
y=  0.34  mol O2/mol
Press the Enter key to quit

Out[6]:
''

## Example 4.3-2, page no. 94¶

In [7]:
#Initilization of variables
basis=100 #mol
FinalBasis=1250.0 #lb-moles/h
#Calulations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
multiply=FinalBasis/basis
Feed=100*multiply
TopStream=50*multiply
BottomStream1=12.5*multiply
BottomStream2=37.5*multiply
print '%s  %.2f %s' %(' Final Basis=',Feed,' lb-moles /h')
print '%s  %.2f %s' %(' Final Top Stream Feed=',TopStream, 'lb-moles /h')
print '%s  %.2f %s' %(' Final Bottom Stream Feed 1 =', BottomStream1,'lb-moles A/h')
print '%s  %.2f %s' %(' Final Bottom Stream Feed 2 =' ,BottomStream2,' lb-moles B/h')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Final Basis=  1250.00  lb-moles /h
Final Top Stream Feed=  625.00 lb-moles /h
Final Bottom Stream Feed 1 =  156.25 lb-moles A/h
Final Bottom Stream Feed 2 =  468.75  lb-moles B/h
Press the Enter key to quit

Out[7]:
''

## Example 4.3-3, page no. 97¶

In [8]:
#Initilization of variables
basis=100 #kg
inputx=0.2
outputx=0.08
D=1 #kg/L
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("Using NaOH balance")
m2=inputx*basis/outputx
print '%s  %.2f %s' %('m2=',m2 ,'Kg NaOH')
print("Using Total mass balance")
m1=m2-basis
print '%s  %.2f %s' %('m1=',m1, 'Kg Water')
V1=m1/D
print '%s  %.2f %s' %(' V1=',V1 ,'Litres')
Ratio1=V1/basis
Ratio2=m2/basis
print '%s  %.2f %s' %(' Ratio of lt water/Kg Feed =', Ratio1,' lt water/Kg Feed')
print '%s  %.2f %s' %(' Ratio of Kg product/Kg Feed =', Ratio2 ,'Kg product/Kg Feed')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Using NaOH balance
m2=  250.00 Kg NaOH
Using Total mass balance
m1=  150.00 Kg Water
V1=  150.00 Litres
Ratio of lt water/Kg Feed =  1.50  lt water/Kg Feed
Ratio of Kg product/Kg Feed =  2.50 Kg product/Kg Feed
Press the Enter key to quit

Out[8]:
''

## Example 4.3-5, page no. 102¶

In [10]:
#Initilization of variables
inputx=0.45
outputx=0.95
basis=2000 #L/h
outputBasis=100 #Kmol
M1=78.11
M2=92.13
D=0.872
z=0.08
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
mass1=outputBasis*M1*outputx
mass2=outputBasis*M2*(1-outputx)
mass=mass1+mass2
yB2=mass1/mass
m1=basis*D
print '%s  %.2f %s' %(' m1=',m1,' Kg/h')
mB3=z*inputx*m1
print '%s  %.2f %s' %(' mB3=',mB3,' Kg/h')
print("Using Benzene balance,")
m2=(inputx*m1-mB3)/yB2
print '%s  %.2f %s' %(' m2=',m2, 'Kg/h')
print("Using Toluene balance,")
mT3=(1-inputx)*m1-(1-yB2)*m2
print '%s  %.2f %s' %(' mT3=',mT3,' Kg/h')
m3=mB3+mT3
print '%s  %.2f %s' %(' m3=',m3,' Kg/h')
yB3=mB3/m3
print '%s  %.2f %s' %(' yB3=',yB3,' kg B/kg')
yT3=1-yB3
print '%s  %.2f %s' %(' yT3=',yT3, 'kg T/kg')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
m1=  1744.00  Kg/h
mB3=  62.78  Kg/h
Using Benzene balance,
m2=  766.84 Kg/h
Using Toluene balance,
mT3=  914.38  Kg/h
m3=  977.16  Kg/h
yB3=  0.06  kg B/kg
yT3=  0.94 kg T/kg
Press the Enter key to quit

Out[10]:
''

## Example 4.4-1, page no. 105¶

In [12]:
#Initilization of variables
inputMass1=100 #Kg/h
inputMass2=30 #Kg/h
outputMass1=40 #Kg/h
outputMass2=30 #Kg/h
inputx1=0.5
inputx2=0.3
outputx1=0.9
outputx2=0.6
#Calculations and printing
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("using Overall Mass balance, ")
m3=inputMass1+inputMass2-outputMass1-outputMass2
print '%s %d %s' %('m3=',m3,' Kg/h')
print("using Overall balance on A, ")
x3=(inputMass1*inputx1+inputMass2*inputx2-outputMass1*outputx1-outputMass2*outputx2)/m3
print '%s  %.2f %s' %('x3=',x3,' Kg A/kg')
print("using Mass balance on Unit 1, ")
m1=inputMass1-outputMass1
print '%s %d %s' %('m1=',m1,' Kg/h')
print("using A balance on Unit 1, ")
x1=(inputMass1*inputx1-outputMass1*outputx1)/m1
print '%s  %.2f %s' %('x1=',x1,' Kg A/kg')
print("using Mass balance on mixing point, ")
m2=inputMass2+m1
print '%s %d %s' %('m2=',m2,'Kg/h')
print("using A balance on mixing point, ")
x2=(inputMass2*inputx2+m1*x1)/m2
print '%s  %.2f %s' %('x2=',x2 ,'Kg A/kg')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
using Overall Mass balance,
m3= 60  Kg/h
using Overall balance on A,
x3=  0.08  Kg A/kg
using Mass balance on Unit 1,
m1= 60  Kg/h
using A balance on Unit 1,
x1=  0.23  Kg A/kg
using Mass balance on mixing point,
m2= 90 Kg/h
using A balance on mixing point,
x2=  0.26 Kg A/kg
Press the Enter key to quit

Out[12]:
''

## Example 4.4-2, page no. 107¶

In [6]:
#Initilization of variables
from numpy import matrix, array, dot
from numpy.linalg import inv
import math
massin=100 #kg
M1=100 #kg
M2=75 #Kg
massout=43.1 #kg
inputx=0.5
outputxA=0.053
outputxM=0.016
m1xA=0.275
m1xM=0.725
m3xW=0.03
m3xA=0.09
m3xM=0.88
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("Using Balances around two-extraxtor system,")
print("Balance on total mass,")

A=array([[1,1],[m1xA,m3xA]])
b=array([[massin+M1+M2-massout],[massin*inputx - massout*outputxA]])
C=dot(inv(A),b)
m1=C[0,0]
m3=C[1,0]
print '%s  %.2f %s' %(' m1=',m1,' Kg')
print '%s  %.2f %s' %(' m3=',m3,' Kg')
print("Balance on M")
xM1=(massin+M2-massout*outputxM-m3*m3xM)/m1
print '%s  %.2f %s' %(' xM1=',xM1,' kg MIBK/kg')
print("Balances around Extract mixing point, ")
print("Balance on A")
mA4=m1*m1xA+m3*m3xA
print '%s  %.2f %s' %(' mA4=',mA4 ,'Kg Acetone')
print("Balance on M")
mM4=m1*xM1+m3*m3xM
print '%s  %.2f %s' %(' mM4=',mM4,' Kg MIBK')
print("Balance on W")
mW4=m1*(m1xM-xM1) + m3*m3xW
print '%s  %.2f %s' %(' mW4=',mW4 ,'Kg Water')
print("Balances around the First extractor")
print("Balance on  A")
mA2=massin*inputx-m1*m1xA
print '%s  %.2f %s' %(' mA2=',mA2,' Kg Acetone')
print("Balance on  M")
mM2=massin-m1*xM1
print '%s  %.2f %s' %(' xM1=',xM1, 'Kg MIBK')
print("Balance on  W")
mW2=massin*inputx- m1*(m1xM-xM1)
print '%s  %.2f %s' %(' mW2=',mW2,'Kg Water')

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Using Balances around two-extraxtor system,
Balance on total mass,
m1=  145.11  Kg
m3=  86.79  Kg
Balance on M
xM1=  0.67  kg MIBK/kg
Balances around Extract mixing point,
Balance on A
mA4=  47.72 Kg Acetone
Balance on M
mM4=  174.31  Kg MIBK
Balance on W
mW4=  9.87 Kg Water
Balances around the First extractor
Balance on  A
mA2=  10.10  Kg Acetone
Balance on  M
xM1=  0.67 Kg MIBK
Balance on  W
mW2=  42.73 Kg Water


## Example 4.5-1, page no. 110¶

In [15]:
#Initilization of variables
import math
import numpy
from numpy import linalg
x1=0.960
x2=0.977
x3=0.983
basis=100 #mol
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("Overall dry Air balance,")
n1=x3*basis/x1
print '%s  %.2f %s' %('n1=',n1,' mol Fresh feed')
print("Overall mole balance,")
n3=n1-basis
print '%s  %.2f %s' %('n3=',n3,' mol Water condensed')
print("Mole balance on mixing point,")
print("n1+n5=n2")
print("Water balance on mixing point")
print ' %.2f %s  %.2f %s  %.2f %s' %(1-x1,' n1+ ', 1-x3,' n5 =', 1-x2,'n2')
A=([[1 ,-1],[1-x2,-(1-x3)]])
b=([[n1],[(1-x1)*n1]])
C=numpy.dot(linalg.inv(A),b)
n2=C[0,0]
n5=C[1,0]
print '%s  %.2f %s' %(' \n n2=',n2,' mol')
print '%s  %.2f %s' %(' \n n5=',n5,' mol Recycled')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Overall dry Air balance,
n1=  102.40  mol Fresh feed
Overall mole balance,
n3=  2.40  mol Water condensed
Mole balance on mixing point,
n1+n5=n2
Water balance on mixing point
0.04  n1+   0.02  n5 =  0.02 n2

n2=  392.52  mol

n5=  290.12  mol Recycled
Press the Enter key to quit

Out[15]:
''

## Example 4.5-2, page no. 112¶

In [16]:
#Initilization of variables
import math
import numpy
from numpy import linalg
feed=4500 #kg/h
feedx=0.333
m3x=0.494
m5x=0.364
x=0.95
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
m6x=m5x
print '%s  %.2f %s' %('Given, m4=',x,' (m4+m5)')
print("using Overall K2CrO4 balance, ")
print ' %.2f %s  %.2f %s  %.2f %s' %(feedx,' *', feed ,'= m4+', m6x,'m5')
A=([[1-x,-x],[1,m6x]])
b=([[0],[feedx*feed]])
C=numpy.dot(linalg.inv(A),b)
m4=C[0,0]
m5=C[1,0]
print '%s  %.2f %s' %(' \n m4=',m4,' K2CrO4 crystals/h')
print '%s  %.2f %s' %(' \n m5=',m5,' entrained solution/h')
print("Overall Total mass balance , ")
m2=feed-m4-m5
print '%s  %.2f %s' %('m2=',m2,' Kg H2O evaporated/h')
print("Mass balance around the crystallizer,")
print("m3=m4+m5+m6")
print("Water balance around the crystallizer, ")
print ' %.2f %s  %.2f %s  %.2f %s' %(1-m3x, 'm3=', 1-m5x,' m5 + ',1-m6x,' m6')
D=([[1,-1],[1,(-1+m6x)/(1-m3x)]])
e=([[m4+m5],[(1-m5x)*m5/(1-m3x)]])
F=numpy.dot(linalg.inv(D),e)
m3=F[0,0]
m6=F[1,0]
print '%s  %.2f %s' %(' \n m3=',m3,' Kg/h fed to the crystallizer')
print '%s  %.2f %s' %(' \n m6=',m6,' Kg/h')
ratio=m6/feed
print  '%s  %.2f %s' %(' \n ratio=',ratio,' Kg recycle/ Kg fresh feed')
print("mass balance around Recycle-fresh feed mixing point, ")
m1=feed+m6
print '%s  %.2f %s' %('m1=',m1,' kg/h feed to the evaporator')
print("With out recycle, ")
print("m3=622 Kg/h")
print("m5=2380 Kg/h")
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Given, m4=  0.95  (m4+m5)
using Overall K2CrO4 balance,
0.33  *  4500.00 = m4+  0.36 m5

m4=  1470.33  K2CrO4 crystals/h

m5=  77.39  entrained solution/h
Overall Total mass balance ,
m2=  2952.28  Kg H2O evaporated/h
Mass balance around the crystallizer,
m3=m4+m5+m6
Water balance around the crystallizer,
0.51 m3=  0.64  m5 +   0.64  m6

m3=  7193.31  Kg/h fed to the crystallizer

m6=  5645.60  Kg/h

ratio=  1.25  Kg recycle/ Kg fresh feed
mass balance around Recycle-fresh feed mixing point,
m1=  10145.60  kg/h feed to the evaporator
With out recycle,
m3=622 Kg/h
m5=2380 Kg/h
Press the Enter key to quit

Out[16]:
''

## Example 4.6-1, page no. 120¶

In [17]:
#Initilization of variables
basis=100 #mol
xP=0.1
xN=0.12
xA=0.78
x=0.3
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
nP=basis*xP
nN=basis*xN
nO2=basis*xA*0.21
nN2=basis-nP-nN-nO2
if nN/nP>1:
print("NH3 is in excess")
else:
print("Propene is in excess")

if nO2/nP>1:
print("O2 is in excess")
else:
print("propene is in excess")

nO2reacted=nP*1.5
nNreacted=nP*1
ExcessAmmonia=(nN-nNreacted)*100/nNreacted
ExcessO2=(nO2-nO2reacted)*100/nO2reacted
print '%s  %.2f' %(' \n percentage excess Ammonia=',ExcessAmmonia)
print '%s  %.2f' %(' \n percentage excess Oxygen=',ExcessO2)
nPout=(1-x)*nP
print '%s  %.2f %s' %(' \n no.of moles of Propylene left=', nPout,' mol')
E=nP-nPout
nNout=nN-E
nO2out=nO2-1.5*E
nAc=E
nW=3*E
print'%s  %.2f %s' %(' \n no.of moles of Ammonia left=', nNout,' mol')
print'%s  %.2f %s' %(' \n no.of moles of oxygen left=' ,nO2out,' mol')
print'%s  %.2f %s' %(' \n no.of moles of ACN formed= ',nAc ,'mol')
print'%s  %.2f %s' %(' \n no.of moles of water formed=', nW ,'mol')
print'%s  %.2f %s' %(' \n no.of moles of Nirtogen present= ',nN2 ,'mol')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
NH3 is in excess
O2 is in excess

percentage excess Ammonia=  20.00

percentage excess Oxygen=  9.20

no.of moles of Propylene left=  7.00  mol

no.of moles of Ammonia left=  9.00  mol

no.of moles of oxygen left=  11.88  mol

no.of moles of ACN formed=   3.00 mol

no.of moles of water formed=  9.00 mol

no.of moles of Nirtogen present=   61.62 mol
Press the Enter key to quit

Out[17]:
''

## Example 4.6-2, page no. 122¶

In [18]:
#Initialization of variables
import math
import numpy
from numpy import linalg
print("Given, Reaction is CO(g)+ H2O(g) --> CO2(g)+ H2(g)")
nCO=1.
nH2O=2.
#Calculations and printing:
nt=nCO+nH2O
print("\n It is found that Ee=0.667")
Ee=0.667
yCO=(nCO-Ee)/nt
yH2O=(nH2O-Ee)/nt
yCO2=Ee/nt
yH2=Ee/nt
print("\n Ee is obtained by solving the quadratic yCO2*yH2/(yCO*yH2O)=1")
print("\n Limiting reactant is CO")
print '%s %.3f' %("\n yCO = ",yCO)
print '%s %.3f' %("\n yCO2 = ",yCO2)
print '%s %.3f' %("\n yH2O = ",yH2O)
print '%s %.3f' %("\n yH2 = ",yH2)
nCOF=yCO*nt
fCO=(nCO-nCOF)/nCO
print '%s %.3f' %("\n Fractional conversion of CO at equilibrium is ", fCO)
raw_input('press enter key to exit')

Given, Reaction is CO(g)+ H2O(g) --> CO2(g)+ H2(g)

It is found that Ee=0.667

Ee is obtained by solving the quadratic yCO2*yH2/(yCO*yH2O)=1

Limiting reactant is CO

yCO =  0.111

yCO2 =  0.222

yH2O =  0.444

yH2 =  0.222

Fractional conversion of CO at equilibrium is  0.667
press enter key to exit

Out[18]:
''

## Example 4.6-3, page no. 124¶

In [19]:
#Initilization of variables
basis=100 #mol
x=0.850
conv1=0.501
conv2=0.471
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
n1=(1-conv1)*basis*x
n2=conv2*basis*x
E1=n2
E2=basis*x - E1-n1
n3=E1-E2
n4=2*E2
n5=basis*(1-x)
nt=n1+n2+n3+n4+n5
selectivity=n2/n4
print '%s  %.2f %s ' %('selectivity=',selectivity,' mol Ethene/mol methane')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
selectivity=  7.85  mol Ethene/mol methane
Press the Enter key to quit

Out[19]:
''

## Example 4.7-2, page no. 135¶

In [20]:
#Initilization of variables
basis=100 #mol
x=0.850
conv1=0.501
conv2=0.471
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
n1=(1-conv1)*basis*x
n2=conv2*basis*x
E1=n2
E2=basis*x - E1-n1
n3=E1-E2
n4=2*E2
n5=basis*(1-x)
nt=n1+n2+n3+n4+n5
selectivity=n2/n4
print '%s  %.2f %s ' %('selectivity=',selectivity,' mol Ethene/mol methane')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
selectivity=  7.85  mol Ethene/mol methane
Press the Enter key to quit

Out[20]:
''

## Example 4.7-3, page no. 139¶

In [21]:
#Initilization of variables
import math
import numpy
from numpy import linalg
x0=0.996
basis=100 #mol combined feed to the reactor
inputxH2=0.7
single_pass=0.6
inputxCO2=0.28
molI=2
Ix=0.004
final=155 #kmol/h
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("Reactor analysis, ")
n2=(1-single_pass)*basis*inputxH2
print '%s  %.2f %s' %('n2=',n2,' mol H2')
print("H2 balance")
consH2=basis*inputxH2-n2
print '%s  %.2f %s' %('H2 moles consumed=',consH2,' mol H2')
print("CO2 balance")
n1=basis*inputxCO2-consH2/3
print '%s  %.2f %s' %('n1=',n1,'mol CO2')
print("Methanol balance")
n3=consH2/3
print '%s  %.2f %s' %('n3=',n3,'mol Methanol')
print("H2O balance")
n4=consH2/3
print '%s  %.2f %s' %('n4=',n4,' mol H2O')
print("condenser analysis")
print("Total mole balance")
n5=n1+n2+molI
print '%s  %.2f %s' %('n5=',n5 ,'mol')
print("CO2 balance")
x5C=n1/n5
print '%s  %.2f %s' %('x5C=',x5C,' mol CO2/mol')
print("H2 balance")
x5H=n2/n5
print '%s  %.2f %s' %('x5H=', x5H,'mol CO2/mol')
x1=1-x5C-x5H
print '%s  %.2f %s' %('x1=',x1,' mol I/mol')
print("Fresh Feed-Recycle mixing point analysis")
print("Total mole balance")
print '%s  %.2f' %('n0+nr=',basis)
print("I balance")
print '%s  %.2f %s  %.2f %s  %.2f' %('n0', Ix,' + nr ',x1,' = ',molI)
A=([[1, 1],[Ix, x1]])
b=([[basis],[molI]])
C=numpy.dot(linalg.inv(A),b) #Here We solve two linear equations simultaneously
n0=C[0,0]
nr=C[1,0]
print '%s  %.2f %s' %(' \n n0=',n0,' mol fresh feed')
print '%s  %.2f %s' %(' \n nr=', nr ,'mol recycle')
x0C=(basis*inputxCO2-nr*x5C)/n0
print '%s  %.2f %s' %(' \n x0C=',x0C,' mol CO2/mol')
x0H=1-x0C-Ix
print '%s  %.2f %s' %(' \n x0H=',x0H ,'mol H2/mol')
print("Recycle-Purge splitting Analysis")
print("Total mole balance")
np=n5-nr
print '%s  %.2f %s' %('np=',np,' mol purge')
print("Flow chart scaling")
Factor=final/n3
print '%s  %.2f %s' %('Factor for scaling=',Factor,' Kmol/h/mol')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Reactor analysis,
n2=  28.00  mol H2
H2 balance
H2 moles consumed=  42.00  mol H2
CO2 balance
n1=  14.00 mol CO2
Methanol balance
n3=  14.00 mol Methanol
H2O balance
n4=  14.00  mol H2O
condenser analysis
Total mole balance
n5=  44.00 mol
CO2 balance
x5C=  0.32  mol CO2/mol
H2 balance
x5H=  0.64 mol CO2/mol
x1=  0.05  mol I/mol
Fresh Feed-Recycle mixing point analysis
Total mole balance
n0+nr=  100.00
I balance
n0  0.00  + nr   0.05  =   2.00

n0=  61.40  mol fresh feed

nr=  38.60 mol recycle

x0C=  0.26  mol CO2/mol

x0H=  0.74 mol H2/mol
Recycle-Purge splitting Analysis
Total mole balance
np=  5.40  mol purge
Flow chart scaling
Factor for scaling=  11.07  Kmol/h/mol
Press the Enter key to quit

Out[21]:
''

## Example 4.8-1, page no. 143¶

In [22]:
#Initilization of variables
xN2wet=0.6
xCO2wet=0.15
xO2wet=0.1
xH2O=0.15
basis=100 #mol Wet gas
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("part 1")
wet=xN2wet+xCO2wet+xO2wet
xN2dry=xN2wet/wet
xCO2dry=xCO2wet/wet
xO2dry=xO2wet/wet
print '%s %f %s' %(' \n xN2 dry =', xN2dry,' mol N2/mol dry gas')
print '%s %f %s' %(' \n xO2 dry =',xO2dry,' mol O2/mol dry gas')
print '%s %f %s' %(' \n xCO2 dry =', xCO2dry ,'mol CO2/mol dry gas')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
part 1

xN2 dry = 0.705882  mol N2/mol dry gas

xO2 dry = 0.117647  mol O2/mol dry gas

xCO2 dry = 0.176471 mol CO2/mol dry gas
Press the Enter key to quit

Out[22]:
''

## Example 4.8-2, page no. 145¶

In [23]:
#Initilization of variables
basisButane=100. #mol/h butane
basisAir=5000. #mol/h
#calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
nO2Theoretical=basisButane*6.5
nAirTheoretical=nO2Theoretical*4.76
percent=(basisAir-nAirTheoretical)*100/nAirTheoretical
print '%s  %.2f' %(' \n percent excess air=',percent)
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook

percent excess air=  61.60
Press the Enter key to quit

Out[23]:
''

## Example 4.8-3, page no. 147¶

In [24]:
#Initilization of variables
basis=100. #mol ethane feed
E1=0.9
E2=0.25
excess=0.5
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print(" 50percent excess air")
nO2theoretical=basis*3.5
n0=nO2theoretical*(1+excess)/0.21
print '%s  %.4f %s' %(' n0=',n0,' mol air fed')
print("90% ethane conversion")
n1=(1-E1)*basis
print '%s  %.4f' %('No. of moles of ethane unreacted=',n1)
print("25% conversion to CO")
n4=E2*(basis-n1)*2
print '%s  %.4f %s' %('n4=', n4 ,'mol CO')
print("nitrogen balance")
n3=0.79*n0
print '%s  %.4f %s' %('n3=', n3,' mol N2')
print("Atomic carbon balance")
n5=2*basis-2*n1-n4
print '%s  %.4f %s' %('n5=', n5 ,'mol CO2')
print("Atomic hydrogen balance")
n6=(basis*6-n1*6)/2
print '%s  %.4f %s' %('n6=', n6,' mol H2O')
print("Atomic oxygen balance")
n2=(nO2theoretical*1.5*2-n4-n5*2-n6)/2
print '%s  %.4f %s' %('n2=', n2 ,'mol O2')
dry=n1+n2+n3+n4+n5
wet=dry+n6
y1=n1/dry
print '%s  %.4f %s' %('\n y1=', y1,' mol C2H6/mol')
y2=n2/dry
print '%s  %.4f %s' %('\n y2=', y2 ,'mol O2/mol')
y3=n3/dry
print '%s  %.4f %s' %('\n y3=', y3,' mol N2/mol')
y4=n4/dry
print '%s  %.4f %s' %('\n y4=', y4 ,'mol CO/mol')
y5=n5/dry
print '%s  %.4f %s' %('\n y5=',y5,' mol CO2/mol')
ratio=n6/dry
print '%s  %.4f %s' %(' \n ratio=',ratio,' mol H2O/mol dry stack gas')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
50percent excess air
n0=  2500.0000  mol air fed
90% ethane conversion
No. of moles of ethane unreacted=  10.0000
25% conversion to CO
n4=  45.0000 mol CO
nitrogen balance
n3=  1975.0000  mol N2
Atomic carbon balance
n5=  135.0000 mol CO2
Atomic hydrogen balance
n6=  270.0000  mol H2O
Atomic oxygen balance
n2=  232.5000 mol O2

y1=  0.0042  mol C2H6/mol

y2=  0.0970 mol O2/mol

y3=  0.8238  mol N2/mol

y4=  0.0188 mol CO/mol

y5=  0.0563  mol CO2/mol

ratio=  0.1126  mol H2O/mol dry stack gas
Press the Enter key to quit

Out[24]:
''

## Example 4.8-4, page no. 149¶

In [25]:
#Initilization of variables
basis=100 #mol pf product gas
xCO=0.015
xCO2=0.060
xO2=0.082
xN2=0.843
#Calculations and printing:
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("N2 balance")
na=basis*xN2/0.79
print '%s  %.2f %s' %('na=',na,' mol air')
print("Atomic C balance")
nc=basis*xCO + basis*xCO2
print '%s  %.2f %s' %('nc=',nc ,'mol C')
print("Atomic O balance")
nw=0.21*na*2-basis*(xCO + xCO2*2 + xO2*2)
print '%s  %.2f %s' %('nw=',nw,' mol oxygen')
print("Atomic H2 balance")
nh=nw*2
print '%s  %.2f %s' %('nh=',nh ,'mol H2')
ratio=nh/nc
print '%s  %.2f %s' %('\n C/H ratio in fuel=',ratio,' mol H/mol C')
print("percent excess air")
nO2theoretical=nc + nh/4
print '%s  %.2f %s' %('nO2 theoretical=',nO2theoretical ,'mol O2')
nO2fed=0.21*na
print '%s  %.2f %s' %(' \n nO2fed=',nO2fed,' mol O2')
percent=(nO2fed-nO2theoretical)*100/nO2theoretical
print '%s  %.2f %s' %('\n percentage excess air=',percent ,'excess air')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
N2 balance
na=  106.71  mol air
Atomic C balance
nc=  7.50 mol C
Atomic O balance
nw=  14.92  mol oxygen
Atomic H2 balance
nh=  29.84 mol H2

C/H ratio in fuel=  3.98  mol H/mol C
percent excess air
nO2 theoretical=  14.96 mol O2

nO2fed=  22.41  mol O2

percentage excess air=  49.80 excess air
Press the Enter key to quit

Out[25]:
''

## Example 4.9-1, page no. 151¶

In [ ]:
#Initilization of variables
feed=59.6 #mol/s
x=0.2
TopFlow1=48.7 #mol/s
outputx1=0.021
BottomFlow1=10.9
TopFlow2=48.3
outputx2=0.063
BottomFlow2=6.4
print(" All the values in the textbook are Approximated hence the values in this code differ from those of Textbook")
print("Design")
MEKin1=feed*x
MEKout1=TopFlow1*outputx1 + BottomFlow1
closure1=MEKout1*100/MEKin1
print '%s %d %s' %('closure1=',closure1,' percent')
print("Experiment")
MEKin2=feed*x
MEKout2=TopFlow2*outputx2 + BottomFlow2
closure2=MEKout2*100/MEKin2
print '%s %d %s' %('closure2=',closure2, 'percent')
raw_input("Press the Enter key to quit")

 All the values in the textbook are Approximated hence the values in this code differ from those of Textbook
Design
closure1= 100  percent
Experiment
closure2= 79 percent