Chapter 24: Accident and Emergency Management

ILLUSTRATIVE EXAMPLE 24.4, Page number: 514

In [4]:
from __future__ import division

#Variable declaration:
fm = 30/100                         #Mole fraction of methane
fe = 50/100                         #Mole fraction of ethane
fp = 20/100                         #Mole fraction of pentane
LFLm = 0.046                        #Lower flammability limit for methane
LFLe = 0.035                         #Lower flammability limit for ethane
LFLp = 0.014                        #Lower flammability limit for propane
UFLm = 0.142                        #Upper flammability limit for methane
UFLe = 0.151                        #Upper flammability limit for ethane
UFLp = 0.078                        #Upper flammability limit for propane

#Calculation:
LFLmix = 1/((fm/LFLm)+(fe/LFLe)+(fp/LFLp))  #Lower flammability limit of gas mixture
UFLmix = 1/((fm/UFLm)+(fe/UFLe)+(fp/UFLp))  #Upper flammability limit of gas mixture

#Result:
print "The upper flammability limit (UFL) of the gas mixture is :",round(UFLmix*100,2)," % ."
print "The lower flammability limit (LFL) of the gas mixture is :",round(LFLmix*100,2)," % ."
print "There is a printing mistake in book."
The upper flammability limit (UFL) of the gas mixture is : 12.52  % .
The lower flammability limit (LFL) of the gas mixture is : 2.85  % .
There is a printing mistake in book.

ILLUSTRATIVE EXAMPLE 24.5, Page number: 514

In [9]:
from __future__ import division
from sympy import nsimplify as changeToFraction

#Variable declaration:
P_A = 10/100                               #Probability that the first tube is defective if the first is replaced
P_B = 10/100                               #Probability that the second tube is defective if the first is replaced

#Calculation:
P_AB = P_A*P_B                             #Probability that the two tubes are defective if the first is replaced
P_B_A = 9/99                               #Probability that the second tube is defective if the first tube is not replaced
Pd_AB = P_A*P_B_A                          #Probability that both tubes are defective if the first tube is not replaced

#Result:
print "The probability that both tubes are defective if :"
print "(a) the first is replaced before the second is drawn is :",changeToFraction(P_AB)," ."
print "(b) the first is not replaced before the second is drawn is :",changeToFraction(Pd_AB)," ."
The probability that both tubes are defective if :
(a) the first is replaced before the second is drawn is : 1/100  .
(b) the first is not replaced before the second is drawn is : 1/110  .

ILLUSTRATIVE EXAMPLE 24.6, Page number: 515

In [6]:
from sympy import symbols, integrate, exp

#Variable declaration:
X = symbols('X')                        #Range of X
Px = 1.7*(exp(-1.7*X))                  #Probability distribution function

#Calculation:
P = integrate(Px, (X,2,6))              #Probability that X will have a value between 2 and 6

#Result:
print "The probability that X will have a value between 2 and 6 is :",round(P,4)," ."
The probability that X will have a value between 2 and 6 is : 0.0333  .

ILLUSTRATIVE EXAMPLE 24.7, Page number: 517

In [7]:
from __future__ import division
from math import factorial

#Variable Declaration:
n = 20                  #Total number of components
p = 0.1                 #Probability of success

#Calculations:
def binomial(n,p,x):
    P=0
    for x in range(0,x,1):
        P = P + p**x*(1-p)**(n-x)*factorial(n)/(factorial(x)*factorial(n-x))
    return P

#Results:
print "Probability that the sprinkler system fails :",round((1-binomial(n,p,4))*100,2),"%"
Probability that the sprinkler system fails : 13.3 %

ILLUSTRATIVE EXAMPLE 24.8, Page number: 518

In [21]:
from sympy import symbols, integrate, exp

#Variable declaration:
a = 1.3*10**-3                      #Constant a
B = 0.77                            #Constant B
t = symbols('t')                    #Time (h)
Ft = a*B*t**(B-1)*(exp(-a*t**B))     #Pdf for heat exchanger tube
Pt = integrate(Ft, (t,0,1000))      #Probability that a heat exchanger will fail within 100 hours

#Result:
print "The probability that a tube in a heat exchanger will fail in 1000 hours is :",round(Pt,2)," ."
The probability that a tube in a heat exchanger will fail in 1000 hours is : 0.23  .

ILLUSTRATIVE EXAMPLE 24.9, Page number: 519

In [10]:
from __future__ import division
from scipy.stats import norm as f

#Variable declaration:
m = 0.4008                     #Mean(inch)
s = 0.0004                   #Standard Deviation(inch)
UL = 0.4000+0.001            #Upper Limit
LL = 0.4000-0.001            #Upper Limit

#Calculation:
Ps = f.cdf(UL,m,s)-f.cdf(LL,m,s)#Probability of meeting specs
Pd = 1-Ps                    #Probability of defect

#Results:
print 'Probability of meeting specifications:',round(Ps*100,2),'%'
print 'Probability of Defect:',round(Pd*100,2),'%'
Probability of meeting specifications: 69.15 %
Probability of Defect: 30.85 %

ILLUSTRATIVE EXAMPLE 24.10, Page number: 522

In [22]:
from __future__ import division
from numpy import array,minimum
from math import sqrt

#variable Declaration:
mTa = array([100]*10)                   #Mean weeks for thermometer failure(A)
mTb = array([90]*10)                    #Mean weeks for thermometer failure(B)
mTc = array([80]*10)                    #Mean weeks for thermometer failure(C)
sTa = 30                                #Standard deviation (weeks) for thermometer failure(A)
sTb = 20                                #Standard deviation (weeks) for thermometer failure(B)
sTc = 10                                #Standard deviation (weeks) for thermometer failure(C)
Ra = array([0.52,0.80,0.45,0.68,0.59,0.01,0.50,0.29,0.34,0.46])         #Random No corrosponding to A
Rb = array([0.77,0.54,0.96,0.02,0.73,0.67,0.31,0.34,0.00,0.48])         #Random No corrosponding to B
Rc = array([0.14,0.39,0.06,0.86,0.87,0.90,0.28,0.51,0.56,0.82])         #Random No corrosponding to B
Za = array([0.05,0.84,-0.13,0.47,0.23,-2.33,0.00,-0.55,-0.41,-0.10])    #Normal variable corrosponding to random No for A
Zb = array([0.74,0.10,1.75,-2.05,0.61,0.44,-0.50,-0.41,-3.90,-0.05])    #Normal variable corrosponding to random No for B
Zc = array([-1.08,-0.28,-1.56,1.08,1.13,1.28,-0.58,0.03,0.15,0.92])     #Normal variable corrosponding to random No for C

#Calculations:
Ta = mTa+sTa*Za
Tb = mTb+sTb*Zb
Tc = mTc+sTc*Zc
Ts = minimum(Ta,Tb)
Ts = minimum(Ts,Tc)
m = array([sum(Ts)/len(Ts)]*10)
s = sqrt(sum((Ts-m)**2)/(len(Ts)-1))

#Results:
print 'Standard deviation :',round(s,1)," Weeks"
Standard deviation : 25.9  Weeks

ILLUSTRATIVE EXAMPLE 24.15, Page number: 531

In [3]:
from __future__ import division

#Variable declaration:
t = 273                     #Standard temperature (K)
v = 0.0224                  #Volume of air occupied by 1 gmol of ideal gas (m^3)
V = 1100                    #Volume of heat exchanger (m^3)
T = 22+273                  #Temperature of heat exchanger (K)
x1 = 0.75                   #gmols of hydrocarbon leaking from the exchanger (gmol)

#Calculation:
n = V*(1/v)*(t/T)           #Total number of gmols of air in the room (gmol)
xHC = (x1/(n+x1))*10**6     #The mole fraction of hydrocarbon in the room (ppm)

#Result:
print "1. The mole fraction of hydrocarbon in the room is :",round(xHC*1000,-1)," ppb ."
1. The mole fraction of hydrocarbon in the room is : 16500.0  ppb .