In [6]:

```
#Variable declaration:
i = 0.03375 #Rate of interest (%)
n = 9 #Years to the end of life (yr)
P = 60000 #Cost of exchanger ($)
L = 500 #Salvage value ($)
x = 5 #Time after 5 years (yr)
#Calculation:
SFDF = i/((1+i)**n-1) #Sinking fund depreciation factor
UAP = (P-L)*SFDF #Uniform annual payment ($)
B = P-((P-L)/n)*x #Appraisal value after 5 years ($)
#Result:
print "1. The uniform annual payment made into the fund at the of the year is : $",round(UAP)," ."
print "2. The appraisal value of the exchanger at the end of the fifth year is : $",round(B)," ."
```

In [7]:

```
from __future__ import division
#Variable declaration:
C = 150000 #Capital cost ($)
i = 7/100 #Interest rate
n = 5 #Time (yr)
OC = 15000 #Operating cost ($)
A = 75000 #Annual cost for the old process ($)
#Calculation:
CRF = (i*(1+i)**n)/((1+i)**n-1) #Capital recovery factor
IC = CRF*C #Initial cost ($)
AC = IC+OC #Total annualized cost ($)
#Result:
print "The annualized cost for the new heating system is : $",round(AC)," ."
if (AC<A):
print "Since this cost is lower than the annual cost of $75,000 for the old process, the proposed plan should be implemented."
else :
print "Since this cost is higher than the annual cost of $75,000 for the old process, the proposed plan should not be implemented."
```

In [8]:

```
from __future__ import division
#Variable declaration:
i = 12/100 #Intersest rate
n = 12 #Lifetime period (yr)
CC = 2625000 #Capital cost ($)
IC = 1575000 #Installation cost ($)
#From table 27.3:
Ic1 = 2000000 #Income credit for double pipe ($/yr)
Ic2 = 2500000 #Income credit for Shell-and-tube ($/yr)
AC1 = 1728000 #Total annual cost for double pipe ($/yr)
AC2 = 2080000 #Total annual cost for Shell-and-tube ($/yr)
#Calculation:
CRF = i/(1-(1+i)**-n) #Capital recovery factor
DPc = (CC+IC)*CRF #Annual capital and installation costs for the DP unit ($/yr)
STc = (CC+IC)*CRF #Annual capital and installation costs for the ST unit ($/yr)
DPp = Ic1-AC1 #Profit for the DP unit ($/yr)
STp = Ic2-AC2 #Profit for the ST unit ($/yr)
#Result:
print "The profit for the shell-and-tube unit is : $",round(DPp),"/yr ."
print "The profit for the double pipe unit is : $",round(STp),"/yr ."
if (STp>DPp):
print "A shell-and-tube heat exchanger should therefore be selected based on the above economic analysis."
else :
print "A double pipe heat exchanger should therefore be selected based on the above economic analysis."
```

In [9]:

```
from __future__ import division
from math import log
#Variable declaration:
m = 50000 #Mass flowrate of the organic fluid (lb/h)
cP = 0.6 #The heat capacity of the organic liquid (Btu/lb.°F)
T1 = 150 #Initial temperature of organic fluid (°F)
T2 = 330 #Final temperature of organic fluid (°F)
Ts1 = 358 #Saturation temperature for 150 psia (°F)
Ts2 = 417 #Saturation temperature for 300 psia (°F)
L1 = 863.6 #Latent heat for 150 psia (Btu/lb)
L2 = 809 #Latent heat for 300 psia (Btu/lb)
c1 = 5.20/1000 #Cost for 150 psia ($/lb)
c2 = 5.75/1000 #Cost for 300 psia ($/lb)
CI1 = 230 #Cost index in 1998
CI2 = 360 #Cost index in 2011
IF = 3.29 #Installation factor
PF1 = 1.15 #Pressure factors for 100 to 200 psig
PF2 = 1.20 #Pressure factors for 200 to 300 psig
OP = 90/100 #Plant on-stream operation factor
h = 365*24 #Hours in a year (h)
#Calculation:
Q = m*cP*(T2-T1) #Overall heta duty (Btu/h)
DT1 = Ts1-T1 #Temperature driving force 1 for 150 psia (°F)
DT2 = Ts1-T2 #Temperature driving force 2 for 150 psia (°F)
LMTD1 = (DT1-DT2)/log(DT1/DT2) #Log-mean temperature difference for 150 psia (°F)
DT3 = Ts2-T1 #Temperature driving force 1 for 300 psia (°F)
DT4 = Ts2-T2 #Temperature driving force 2 for 300 psia (°F)
LMTD2 = (DT3-DT4)/log(DT3/DT4) #Log-mean temperature difference for 1300 psia (°F)
A1 = Q/(138*LMTD1) #Required heat transfer area for 150 psia (ft^2)
A2 = Q/(138*LMTD2) #Required heat transfer area for 300 psia (ft^2)
BC1 = 117*A1**0.65 #Base cost for 150 psia ($)
BC2 = 117*A2**0.65 #Base cost for 13000 psia ($)
C1 = BC1*(CI2/CI1)*IF*PF1 #Capital cost for 150 psia ($)
C2 = BC2*(CI2/CI1)*IF*PF2 #Capital cost for 300 psia ($)
S1 = Q*(h*OP)/L1 #Steam requirement for 150 psia (lb/yr)
S2 = Q*(h*OP)/L2 #Steam requirement for 300 psia (lb/yr)
SC1 = S1*c1 #Annual steam cost for 150 psia ($/yr)
SC2 = S2*c2 #Annual steam cost for 300 psia ($/yr)
#Result:
print "1. The capital cost for 150 psia is : $",round(C1,-3)," ."
print " The capital cost for 300 psia is : $",round(C2,-3)," ."
print "2. The annual steam cost for 150 psia is : $",round(SC1,-3),"/yr ."
print " The annual steam cost for 300 psia is : $",round(SC2,-3),"/yr ."
if (C1<C2 and SC1>SC2):
print "The 300-psia exchanger costs less to purchase and install, but it costs more to operate. Choosing the more expensive, 150-psia exchanger is the obvious choice."
elif (C1>C2 and SC1<SC2):
print "The 150-psia exchanger costs less to purchase and install, but it costs more to operate. Choosing the more expensive, 300-psia exchanger is the obvious choice."
```

In [1]:

```
from __future__ import division
from sympy import symbols,solve
from scipy.optimize import fsolve
#Variable declaration:
TCC_TB = 2500000 #Total capital cost ($)
R_TB = 3600000 #R_TBevenue generated from the facility ($)
AOC_TB = 1200000 #Annual operating costs ($)
TCC_FB = 3500000 #Total capital cost ($)
R_FB = 5300000 #R_TBevenue generated from the facility ($)
AOC_FB = 1400000 #Annual operating costs ($)
n = 10 #Time of facility (yr)
#Calculation:
D = 0.1*TCC_TB #Depriciation ($)
WC = 0.1*TCC_TB #Working capital ($)
TI = R_TB-AOC_TB-D #Taxable income ($)
IT = 0.5*TI #Income tax to be paid ($)
A = R_TB-AOC_TB-IT #After-tax cash flow ($)
def eqTB(i):
x = (((1+i)**n-1)/(i*(1+i)**n))*A + (1/(1+i)**n)*WC #Equation for computing rate of return for TB unit
y = WC + 0.5*TCC_TB + 0.5*TCC_TB*(1+i)**1 #Equation for computing rate of return for TB unit
return x-y
iTB = round(fsolve(eqTB,0.8)*100,1) #Rate of return for TB unit (%)
D = 0.1*TCC_FB #Depriciation ($)
WC = 0.1*TCC_FB #Working capital ($)
TI = R_FB-AOC_FB-D #Taxable income ($)
IT = 0.5*TI #Income tax to be paid ($)
A = R_FB-AOC_FB-IT #After-tax cash flow ($)
def eqFB(i):
x = (((1+i)**n-1)/(i*(1+i)**n))*A + (1/(1+i)**n)*WC #Equation for computing rate of return for FB unit
y = WC + 0.5*TCC_FB + 0.5*TCC_FB*(1+i)**1 #Equation for computing rate of return for FB unit
return x-y
iFB = round(fsolve(eqFB,0.8)*100,1) #Rate of return for FB unit (%)
#Results:
print "The rate of return for TB unit is:",round(iTB)," %."
print "The rate of return for FB unit is:",round(iFB,1)," %."
```

In [11]:

```
#Variable declaration:
f = 100000 #Flow rate of flue gas (acfm)
i = 0.1 #Interest rate
#From table 27.4:
#For finned preheater:
ac1 = 3.1 #Equipment cost ($/acfm)
ac2 = 0.8 #Installation cost ($/acfm)
ac3 = 0.06 #Operating cost ($/acfm-yr)
ac4 = 14000 #Maintenance cost ($/yr)
an = 20 #Lifetime (yr)
#For 4-pass preheater:
bc1 = 1.9 #Equipment cost ($/acfm)
bc2 = 1.4 #Installation cost ($/acfm)
bc3 = 0.06 #Operating cost for ($/acfm-yr)
bc4 = 28000 #Maintenance cost ($/yr)
bn = 15 #Lifetime of (yr)
#For 2-pass preheater:
cc1 = 2.5 #Equipment cost ($/acfm)
cc2 = 1.0 #Installation cost ($/acfm)
cc3 = 0.095 #Operating cost for ($/acfm-yr)
cc4 = 9500 #Maintenance cost for ($/yr)
cn = 20 #Lifetime of (yr)
#Calculation:
#For Finned preheater:
aEC = f*ac1 #Total equipment cost ($)
aIC = f*ac2 #Total installation cost ($)
aOC = f*ac3 #Total operating cost ($)
aMC = f*ac4 #Total maintenance cost ($)
aCRF = (i*(1+i)**an)/((1+i)**an-1) #Capital recovery factor
aAEC = aEC*aCRF #Equipment annual cost ($/yr)
aAIC = aIC*aCRF #Installation annual cost($/yr)
aAOC = ac3*f #Annual operating cost ($)
aAMC = ac4 #Annual maintenance cost ($)
aTAC = aAEC+aAIC+aAOC+aAMC #Total annual cost ($)
#For 4-pass preheater:
bEC = f*bc1 #Total equipment cost ($)
bIC = f*bc2 #Total installation cost ($)
bOC = f*bc3 #Total operating cost ($)
bMC = f*bc4 #Total maintenance cost ($)
bCRF = (i*(1+i)**bn)/((1+i)**bn-1) #Capital recovery factor
bAEC = bEC*bCRF #Equipment annual cost ($/yr)
bAIC = bIC*bCRF #Installation annual cost($/yr)
bAOC = bc3*f #Annual operating cost ($)
bAMC = bc4 #Annual maintenance cost ($)
bTAC = bAEC+bAIC+bAOC+bAMC #Total annual cost ($)
#For 2-pass preheater:
cEC = f*cc1 #Total equipment cost ($)
cIC = f*cc2 #Total installation cost ($)
cOC = f*cc3 #Total operating cost ($)
cMC = f*cc4 #Total maintenance cost ($)
cCRF = (i*(1+i)**cn)/((1+i)**cn-1) #Capital recovery factor
cAEC = cEC*cCRF #Equipment annual cost ($/yr)
cAIC = cIC*cCRF #Installation annual cost($/yr)
cAOC = cc3*f #Annual operating cost ($)
cAMC = cc4 #Annual maintenance cost ($)
cTAC = cAEC+cAIC+cAOC+cAMC #Total annual cost ($)
#Result:
print "Total annual cost for finned preheater is : $",round(aTAC)," ."
print "Total annual cost for 4-pass preheater is : $",round(bTAC)," ."
print "Total annual cost for 2-pass preheater is : $",round(cTAC)," ."
if (cTAC<aTAC and cTAC<bTAC):
print "According to the analysis, the 2-pass exchanger is the most economically attractive device since the annual cost is the lowest."
elif (bTAC<aTAC and bTAC<cTAC):
print "According to the analysis, the 4-pass exchanger is the most economically attractive device since the annual cost is the lowest."
elif (aTAC<cTAC and aTAC<bTAC):
print "According to the analysis, the finned exchanger is the most economically attractive device since the annual cost is the lowest."
```

In [14]:

```
from __future__ import division
from numpy import roots
from math import sqrt
#Variable declaration:
TH = 500 #Hot stream temperature at exchanger 1 (°F)
tc = 100 #Cold stream temperature at exchanger 2 (°F)
A = 10 #Constant A
B1 = 100000 #Constant B1
B2 = 4000 #Constant B2
B3 = 400000 #Constant B3
#Calculations:
#It forms equation fo form t^2 - t(Th-tc) +tcTH +B/A
t1 = roots([1, -(TH+tc),(tc*TH + B1/A) ]); #Roots
tmax1 = TH - sqrt(B1/A) #Upon maximising profit
t2 = roots([1, -(TH+tc),(tc*TH + B2/A) ]); #Roots
tmax2 = TH - sqrt(B2/A) #Upon maximising profit
t3 = roots([1, -(TH+tc),(tc*TH + B3/A) ]); #Roots
tmax3 = TH - sqrt(B3/A) #Upon maximising profit
#Results:
print 'tBE for case 1: ',round(t1[0]),'°F',round(t1[1]),'°F'
print 'tmax1:', round(tmax1),'°F'
print 'tBE for case 2: ',round(t2[0]),'°F',round(t2[1]),'°F'
print 'tmax1:', round(tmax2),'°F'
print 'tBE for case 1: ',round(t3[0]),'°F',round(t3[1]),'°F'
print 'tmax1:', round(tmax3),'°F'
```

In [4]:

```
from __future__ import division
from scipy.optimize import fmin_cobyla as optimize
#Key:
#f(x) : Objective Function
#ci(x)'s : Constraints
#Variable Declaration:
def f(x):
return -1.70*x[0] - 2*x[1]
def c1(x):
return 8000 - x[0]
def c2(x):
return 6000 - x[1]
def c3(x):
return 12000 - 0.75*x[0] - 0.40*x[1]
def c4(x):
return 6000 - 0.60*x[0] - 0.25*x[1]
def c5(x):
return x[0]
def c6(x):
return x[1]
#Calculation
X = optimize(f,[7000,6000],[c1,c2,c3,c4,c5,c6], disp = 0)
#Result:
print "Maximum Profit is $",-f(X), "/day or $", -365*f(X), "/year"
```