%matplotlib inline
from matplotlib.pyplot import *
# Variables
# Given
x_Tl = [90,92,97,100] ; # Temperature of saturated liquid- [degree C]
x_Tg = [100,102,107,110] ; # Temperature of saturated vapour- [degree C]
y_Hl = [376.9,385.3,406.3,418.6] ; # Enthalpy change of saturated liquid -[kJ/kg]
y_Hg = [2256.44,2251.2,2237.9,2229.86] ; # Enthalpy change of saturated vapour -[kJ/kg]
# Results
plot(x_Tl,y_Hl,x_Tg,y_Hg);
show()
import math
# Variables
# Basis : 1 g mol
R = 8.314 * 10**-3 ; # Ideal gas constant -[kJ/(g mol * K)]
Hv = 30.20 ; # Experimental value of heat of vaporization of acetone -[kJ/g]
# additional needed data for acetone from Appendix D
T = 329.2 ; # Normal boiling point of acetone - [K]
Tc = 508.0 ; # Critical temperature of acetone - [K]
Pc = 47.0 ; # Critical presure of acetone -[atm]
# Calculations and Results
Tbc = T/Tc ; # variable required in etimation equations
lnPc = math.log(Pc) ; # variable required in etimation equations
B = 2940.46 ;
C = -35.93 ;
del_Hv1 = (R*B*T**2)/((C+T)**2) ; #Heat of vapourization -[kJ/g]
d1 = (abs(Hv - del_Hv1)*100)/Hv ; # differece of experimental and calculated value -[%]
print '(a) Heat of vapourization of acetone is %.2f kJ/g mol. And differece of experimental and calculated value is %.1f %% . '%(del_Hv1,d1);
del_Hv2 = R*T*((3.978*Tbc - 3.938 +1.555*lnPc)/(1.07 - Tbc)) ; #Heat of vapourization -[kJ/g]
d2 = (abs(Hv - del_Hv2)*100)/Hv ; # differece of experimental and calculated value -[%]
print ' (b) Heat of vapourization of acetone is %.2f kJ/g mol. And differece of experimental and calculated value is %.1f %% . '%(del_Hv2,d2);
del_Hv3 = 1.093*R*Tc*((Tbc*(lnPc-1))/(0.93-Tbc)) ; #Heat of vapourization -[kJ/g]
d3 = (abs(Hv - del_Hv3)*100)/Hv ; # differece of experimental and calculated value -[%]
print ' (c) Heat of vapourization of acetone is %.2f kJ/g mol. And differece of experimental and calculated value is %.1f %% . '%(del_Hv3,d3);
# Variables
c = 2.675*10**4 #*.4536)/(1055*1.8) ;
d = 42.27#*.4536)/(1055*1.8) ;
e = 1.425*10**-2#*.4536)/(1055*1.8) ;
# Calculations
#Now convert Tk (Temperature in K) to TF (temperature in F) to get answer of form x + yT - zT**2,where
x = c + d*460/1.8 - e*((460/1.8)**2) ;
y = d/1.8;
z = e/(1.8*1.8) ;
# Results
print 'The required answer is %.2e + (%.2e)T - (%.3e) T**2 Btu/(lb mol*F) , where T is in degree F . '%(x,y,z)
print "Note answer in textbook seems wrong by order of 10^-3"
# Variables
# Take all 18 experimenta data in an array Cp
Cpi = [39.87,39.85,39.90,45.16,45.23,45.17,50.72,51.03,50.90,56.85,56.80,57.02,63.01,63.09,63.14,69.52,69.68,69.63] ; # Array of Cpi(Heat capacity) values
# Take corresponding temperatures in array T
Ti = [300,300,300,400,400,400,500,500,500,600,600,600,700,700,700,800,800,800] ; # array of Ti
Ti_sqr = [300**2,300**2,300**2,400**2,400**2,400**2,500**2,500**2,500**2,600**2,600**2,600**2,700**2,700**2,700**2,800**2,800**2,800**2] ; # array of Ti**2
Ti_cub = [300**3,300**3,300**3,400**3,400**3,400**3,500**3,500**3,500**3,600**3,600**3,600**3,700**3,700**3,700**3,800**3,800**3,800**3]; # array of Ti**3
Ti_qd = [300**4,300**4,300**4,400**4,400**4,400**4,500**4,500**4,500**4,600**4,600**4,600**4,700**4,700**4,700**4,800**4,800**4,800**4]; # array of Ti**4
Cpi_Ti = [39.87*300,39.85*300,39.90*300,45.16*400,45.23*400,45.17*400,50.72*500,51.03*500,50.90*500,56.85*600,56.80*600,57.02*600,63.01*700,63.09*700,63.14*700,69.52*800,69.68*800,69.63*800] ; # Array of Cpi(Heat capacity)*Ti values
Cpi_Ti_sqr = [39.87*300**2,39.85*300**2,39.90*300**2,45.16*400**2,45.23*400**2,45.17*400**2,50.72*500**2,51.03*500**2,50.90*500**2,56.85*600**2,56.80*600**2,57.02*600**2,63.01*700**2,63.09*700**2,63.14*700**2,69.52*800**2,69.68*800**2,69.63*800**2] ; # Array of Cpi(Heat capacity)*Ti**2 values
n = 18. ; # Number of data
# Calculations
from numpy import matrix
# Solve equations (a),(b) & (c) simultaneously using matrix
a = matrix([[n,sum(Ti),sum(Ti_sqr)],[sum(Ti),sum(Ti_sqr),sum(Ti_cub)],[sum(Ti_sqr),sum(Ti_cub),sum(Ti_qd)]]) ; # Matrix of coefficients of unknown
b = matrix([[sum(Cpi)],[sum(Cpi_Ti)],[sum(Cpi_Ti_sqr)]]) ; # Matrix of constants
x = (a)**-1 * b ; # Matrix of solutions a = x(1), b = x(2) , c = x(3)
# Results
print 'The solution is Cp = %.2f + %.3e T + %.2e T**2 .Therefore coefficients are as follows :'%(x[0],x[1],x[2])
print ' a = %.2f. b = %.3e . c = %.2e .'%(x[0],x[1],x[2])
from scipy.integrate import quad
# Variables
# Basis : 1 g mol of gas
#Given
T1 = 550. ; # Initial temperature - [degree F]
T2 = 200. ; # Final temperature - [degree F]
CO2 = 9.2/100 ; # Mole fraction
CO = 1.5/100 ; # Mole fraction
O2 = 7.3/100 ; # Mole fraction
N2 = 82.0/100 ; #Mole fraction
# Calculations
# Additional data needed :
a_N2 = 6.895; # constant
b_N2 = 0.7624*10**-3; # coefficient of T
c_N2 = -0.7009*10**-7; # coefficient of square T
a_O2 = 7.104 ; # constant
b_O2 = (0.7851*10**-3); # coefficient of T
c_O2 = (-0.5528*10**-7); # coefficient of square T
a_CO2 = 8.448; # constant
b_CO2 = 5.757*10**-3; # coefficient of T
c_CO2 = -21.59*10**-7; # coefficient of square T
d_CO2 = 3.059*10**-10; # coefficient of cubic T
a_CO = 6.865 ; # constant
b_CO = 0.8024*10**-3; # coefficient of T
c_CO = -0.7367*10**-7; # coefficient of square T
# New coefficients after multiplying mole fraction of each component
a1_N2 = 6.895*N2 ; # constant
b1_N2 = N2*0.7624*10**-3; # coefficient of T
c1_N2 = (-0.7009*10**-7)*N2; # coefficient of square T
a1_O2 = 7.104*O2 ; # constant
b1_O2 = (0.7851*10**-3)*O2; # coefficient of T
c1_O2 = (-0.5528*10**-7)*O2; # coefficient of square T
a1_CO2 = 8.448*CO2; # constant
b1_CO2 = (5.757*10**-3)*CO2; # coefficient of T
c1_CO2 = (-21.59*10**-7)*CO2; # coefficient of square T
d1_CO2 = (3.059*10**-10)*CO2; # coefficient of cubic T
a1_CO = 6.865*CO; # constant
b1_CO = (0.8024*10**-3)*CO; # coefficient of T
c1_CO = (-0.7367*10**-7)*CO; # coefficient of square T
# Get net coefficients of T , square T and cubic T by adding them
a_net = a1_N2+a1_CO2+a1_CO+a1_O2; #Net constant
b_net = b1_N2+b1_CO2+b1_CO+b1_O2; #Net coefficient of T
c_net = c1_N2+c1_CO2+c1_CO+c1_O2 ; #Net coefficient of square T
d_net = d1_CO2; #Net coefficient of cubic T
def f(T):
return (a_net )+( b_net*T) + (c_net*(T**2)) + (d_net*(T**3))
del_H = quad(f,T1,T2)[0] # Change in enthalpy of gas over given range-[Btu/lb mol gas]
# Results
print ' Change in enthalpy of gas over given range is %.0f Btu/lb mol gas . '%del_H
# Solution
#Given
N2 = 1. ; # Moles of N2 - [kg mol]
P = 100. ; # Pressure of gas - [kPa]
T1 = 18. ; # Initial temperature - [degree C]
T2 = 1100. ; # Final temperature - [degree C]
# Calculations
# In the book it is mentioned to use tables in Appendix D6 to calculate enthalpy change, we get
H_T1 = 0.524; # Initial enthalpy -[kJ/kg mol]
H_T2 = 34.715 ; # Final enthalpy - [kJ/kg mol]
del_H = H_T2 - H_T1 ; # Change in enthalpy - [kJ/kg]
# Results
print ' Change in enthalpy of N2 over given range is %.3f kJ/kg mol N2 . '%del_H
# Variables
#Given
T1 = 640. ; # Initial temperature -[degree F]
T2 = 480. ; # Final temperature -[degree F]
P1 = 92. ; # Initial pressure -[psia]
P2 = 52. ; # Final pressure - [psia]
#From steam table
#At 90 psia
H1_600 = 1328.7 ; #H at 90 psia and 600 F-[Btu/lb]
H1_700 = 1378.1 ; #H at 90 psia and 700 F-[Btu/lb]
H2_600 = 1328.4 ; #H at 95 psia and 600 F-[Btu/lb]
H2_700 = 1377.8 ; #H at 95 psia and 700 F-[Btu/lb]
# Calculations
H3_600 = H1_600+ ((H2_600-H1_600)/(95.-90))*(92-90); #H at 92 psia and 600 F-[Btu/lb]
H3_700 = H1_700+ ((H2_700-H1_700)/(95.-90))*(92-90); #H at 92 psia and 700 F-[Btu/lb]
H3_640 = H3_600+((H3_700-H3_600)/(700.-600))*(640-600); #H at 92 psia and 640 F-[Btu/lb]
H1_450 = 1258.7 ; #H at 50 psia and 450 F-[Btu/lb]
H1_500 = 1282.6 ; #H at 50 psia and 500 F-[Btu/lb]
H2_450 = 1258.2 ; #H at 55 psia and 450 F-[Btu/lb]
H2_500 = 1282.2 ; #H at 55 psia and 500 F-[Btu/lb]
H3_450 = H1_450+ ((H2_450-H1_450)/(55.-50))*(52-50) ; #H at 52 psia and 450 F-[Btu/lb]
H3_500 = H1_500+ ((H2_500-H1_500)/(55.-50))*(52-50); #H at 52 psia and 500 F-[Btu/lb]
H3_480 = H3_450+((H3_500-H3_450)/(500.-450))*(480-450); # H at 52 psia and 480 F-[Btu/lb]
del_H = H3_480 - H3_640; # Change in enthalpy - [Btu/lb]
# Results
print 'Change in enthalpy is %.1f Btu/lb .'%del_H
# Solution
# Variables
W = 4. ; # Mass of water -[kg]
Ti= 27.+273 ; # Initial temperature -[K]
Pi = 200. ; # Initial pressure -[kPa]
Pf = Pi ; # Final pressure -[kPa]
V1 = 0.001004 ; # Specific volume at Ti -[cubic metre/kg]
V2 = 1000. * V1 ; #Specific volume at final temperature(Tf) from given condition in problem - [cubic metre/kg]
va = 0.9024 ; # Specific volume -[cubic metre/kg]
Ta = 400. ; # [K]
vb = 1.025 ; # Specific volume -[cubic metre/kg]
Tb = 450. ; #[K]
vf = V2 ; # Final specific volume -[cubic metre/kg]
# Calculations
m=(Tb - Ta)/(vb - va); # slope
Tf=Ta + m*(vf - va) ; # Final temperature - [K]
# Results
print ' Final temperature is %.0f K.'%Tf
# Solution
# Variables
mv = 1. ; # Mass of saturated vapour - [lb]
P1 = 2. ; # Initial pressure -[atm]
P2 = 20. ; # Final pressure -[atm]
H_2 = 179. ; # Specific enthalpy at 2 atm - [Btu/lb]
H_20 = 233. ; # Specific enthalpy at 20 atm - [Btu/lb]
V_2 = 3.00 ; # Specific volume at 2 atm - [cubic feet/lb]
V_20 = 0.30 ; # Specific volume at 20 atm - [cubic feet/lb]
T_2 = 72. ; # Temperature at 2 atm -[degree F]
T_20 = 239. ; # Temperature at 20 atm -[degree F]
# Calculations
del_H = H_20 - H_2 ; # Change in specific enthalpy -[Btu/lb]
del_V = V_20 - V_2 ; # Change in specific volume -[cubic feet/lb]
del_T = T_20 - T_2 ; # Change in temperature -[degree F]
# Results
print '(a) Change in specific enthalpy is %.0f Btu/lb.'%del_H
print ' (b) Change in specific volume is %.2f cubic feet/lb.'%del_V
print ' (c) Change in temperature is %.1f degree F.'%del_T