{
"metadata": {
"name": "",
"signature": "sha256:20841f2d078ed8f6b672e93204c42bfe5b2cecc320cf09e962fc7cfcf63372c5"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 24: Accident and Emergency Management"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.4, Page number: 514"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from __future__ import division\n",
"\n",
"#Variable declaration:\n",
"fm = 30/100 #Mole fraction of methane\n",
"fe = 50/100 #Mole fraction of ethane\n",
"fp = 20/100 #Mole fraction of pentane\n",
"LFLm = 0.046 #Lower flammability limit for methane\n",
"LFLe = 0.035 #Lower flammability limit for ethane\n",
"LFLp = 0.014 #Lower flammability limit for propane\n",
"UFLm = 0.142 #Upper flammability limit for methane\n",
"UFLe = 0.151 #Upper flammability limit for ethane\n",
"UFLp = 0.078 #Upper flammability limit for propane\n",
"\n",
"#Calculation:\n",
"LFLmix = 1/((fm/LFLm)+(fe/LFLe)+(fp/LFLp)) #Lower flammability limit of gas mixture\n",
"UFLmix = 1/((fm/UFLm)+(fe/UFLe)+(fp/UFLp)) #Upper flammability limit of gas mixture\n",
"\n",
"#Result:\n",
"print \"The upper flammability limit (UFL) of the gas mixture is :\",round(UFLmix*100,2),\" % .\"\n",
"print \"The lower flammability limit (LFL) of the gas mixture is :\",round(LFLmix*100,2),\" % .\"\n",
"print \"There is a printing mistake in book.\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The upper flammability limit (UFL) of the gas mixture is : 12.52 % .\n",
"The lower flammability limit (LFL) of the gas mixture is : 2.85 % .\n",
"There is a printing mistake in book.\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.5, Page number: 514"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from __future__ import division\n",
"from sympy import nsimplify as changeToFraction\n",
"\n",
"#Variable declaration:\n",
"P_A = 10/100 #Probability that the first tube is defective if the first is replaced\n",
"P_B = 10/100 #Probability that the second tube is defective if the first is replaced\n",
"\n",
"#Calculation:\n",
"P_AB = P_A*P_B #Probability that the two tubes are defective if the first is replaced\n",
"P_B_A = 9/99 #Probability that the second tube is defective if the first tube is not replaced\n",
"Pd_AB = P_A*P_B_A #Probability that both tubes are defective if the first tube is not replaced\n",
"\n",
"#Result:\n",
"print \"The probability that both tubes are defective if :\"\n",
"print \"(a) the first is replaced before the second is drawn is :\",changeToFraction(P_AB),\" .\"\n",
"print \"(b) the first is not replaced before the second is drawn is :\",changeToFraction(Pd_AB),\" .\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The probability that both tubes are defective if :\n",
"(a) the first is replaced before the second is drawn is : 1/100 .\n",
"(b) the first is not replaced before the second is drawn is : 1/110 .\n"
]
}
],
"prompt_number": 9
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.6, Page number: 515"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from sympy import symbols, integrate, exp\n",
"\n",
"#Variable declaration:\n",
"X = symbols('X') #Range of X\n",
"Px = 1.7*(exp(-1.7*X)) #Probability distribution function\n",
"\n",
"#Calculation:\n",
"P = integrate(Px, (X,2,6)) #Probability that X will have a value between 2 and 6\n",
"\n",
"#Result:\n",
"print \"The probability that X will have a value between 2 and 6 is :\",round(P,4),\" .\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The probability that X will have a value between 2 and 6 is : 0.0333 .\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.7, Page number: 517"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from __future__ import division\n",
"from math import factorial\n",
"\n",
"#Variable Declaration:\n",
"n = 20 #Total number of components\n",
"p = 0.1 #Probability of success\n",
"\n",
"#Calculations:\n",
"def binomial(n,p,x):\n",
" P=0\n",
" for x in range(0,x,1):\n",
" P = P + p**x*(1-p)**(n-x)*factorial(n)/(factorial(x)*factorial(n-x))\n",
" return P\n",
"\n",
"#Results:\n",
"print \"Probability that the sprinkler system fails :\",round((1-binomial(n,p,4))*100,2),\"%\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Probability that the sprinkler system fails : 13.3 %\n"
]
}
],
"prompt_number": 7
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.8, Page number: 518"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from sympy import symbols, integrate, exp\n",
"\n",
"#Variable declaration:\n",
"a = 1.3*10**-3 #Constant a\n",
"B = 0.77 #Constant B\n",
"t = symbols('t') #Time (h)\n",
"Ft = a*B*t**(B-1)*(exp(-a*t**B)) #Pdf for heat exchanger tube\n",
"Pt = integrate(Ft, (t,0,1000)) #Probability that a heat exchanger will fail within 100 hours\n",
"\n",
"#Result:\n",
"print \"The probability that a tube in a heat exchanger will fail in 1000 hours is :\",round(Pt,2),\" .\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"The probability that a tube in a heat exchanger will fail in 1000 hours is : 0.23 .\n"
]
}
],
"prompt_number": 21
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.9, Page number: 519"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from __future__ import division\n",
"from scipy.stats import norm as f\n",
"\n",
"#Variable declaration:\n",
"m = 0.4008 #Mean(inch)\n",
"s = 0.0004 #Standard Deviation(inch)\n",
"UL = 0.4000+0.001 #Upper Limit\n",
"LL = 0.4000-0.001 #Upper Limit\n",
"\n",
"#Calculation:\n",
"Ps = f.cdf(UL,m,s)-f.cdf(LL,m,s)#Probability of meeting specs\n",
"Pd = 1-Ps #Probability of defect\n",
"\n",
"#Results:\n",
"print 'Probability of meeting specifications:',round(Ps*100,2),'%'\n",
"print 'Probability of Defect:',round(Pd*100,2),'%'"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Probability of meeting specifications: 69.15 %\n",
"Probability of Defect: 30.85 %\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.10, Page number: 522"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from __future__ import division\n",
"from numpy import array,minimum\n",
"from math import sqrt\n",
"\n",
"#variable Declaration:\n",
"mTa = array([100]*10) #Mean weeks for thermometer failure(A)\n",
"mTb = array([90]*10) #Mean weeks for thermometer failure(B)\n",
"mTc = array([80]*10) #Mean weeks for thermometer failure(C)\n",
"sTa = 30 #Standard deviation (weeks) for thermometer failure(A)\n",
"sTb = 20 #Standard deviation (weeks) for thermometer failure(B)\n",
"sTc = 10 #Standard deviation (weeks) for thermometer failure(C)\n",
"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\n",
"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\n",
"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\n",
"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\n",
"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\n",
"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\n",
"\n",
"#Calculations:\n",
"Ta = mTa+sTa*Za\n",
"Tb = mTb+sTb*Zb\n",
"Tc = mTc+sTc*Zc\n",
"Ts = minimum(Ta,Tb)\n",
"Ts = minimum(Ts,Tc)\n",
"m = array([sum(Ts)/len(Ts)]*10)\n",
"s = sqrt(sum((Ts-m)**2)/(len(Ts)-1))\n",
"\n",
"#Results:\n",
"print 'Standard deviation :',round(s,1),\" Weeks\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Standard deviation : 25.9 Weeks\n"
]
}
],
"prompt_number": 22
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"ILLUSTRATIVE EXAMPLE 24.15, Page number: 531"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"\n",
"from __future__ import division\n",
"\n",
"#Variable declaration:\n",
"t = 273 #Standard temperature (K)\n",
"v = 0.0224 #Volume of air occupied by 1 gmol of ideal gas (m^3)\n",
"V = 1100 #Volume of heat exchanger (m^3)\n",
"T = 22+273 #Temperature of heat exchanger (K)\n",
"x1 = 0.75 #gmols of hydrocarbon leaking from the exchanger (gmol)\n",
"\n",
"#Calculation:\n",
"n = V*(1/v)*(t/T) #Total number of gmols of air in the room (gmol)\n",
"xHC = (x1/(n+x1))*10**6 #The mole fraction of hydrocarbon in the room (ppm)\n",
"\n",
"#Result:\n",
"print \"1. The mole fraction of hydrocarbon in the room is :\",round(xHC*1000,-1),\" ppb .\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1. The mole fraction of hydrocarbon in the room is : 16500.0 ppb .\n"
]
}
],
"prompt_number": 3
}
],
"metadata": {}
}
]
}