diff options
50 files changed, 19345 insertions, 0 deletions
diff --git a/Concepts_Of_Physics_(Volume_-_1)_by_H._C._Verma/README.txt b/Concepts_Of_Physics_(Volume_-_1)_by_H._C._Verma/README.txt new file mode 100644 index 00000000..17a34250 --- /dev/null +++ b/Concepts_Of_Physics_(Volume_-_1)_by_H._C._Verma/README.txt @@ -0,0 +1,10 @@ +Contributed By: Jaya Sravya +Course: btech +College/Institute/Organization: Kakatiya institute of technology and sciences +Department/Designation: IT +Book Title: Concepts Of Physics (Volume - 1) +Author: H. C. Verma +Publisher: Bharati Bhavan,india +Year of publication: 2011 +Isbn: 9788177091878 +Edition: 2
\ No newline at end of file diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-10_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-10_1.ipynb new file mode 100644 index 00000000..b3e76c7e --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-10_1.ipynb @@ -0,0 +1,360 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 10 : Law of Hydrostatics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.1 Page no 98 " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 10.1 pagr no. 98\n", + "\n", + "\n", + "\n", + " height of mercury h=2.493 ft\n", + " density of mercury rho=848.700 lb/ft**3\n", + " atmospheric pressure P_at=2116.000 psf \n", + "gauge pressure P=2115.809 psf\n", + " absolute pressure P_ab=4232.000 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 10.1 pagr no. 98\\n\\n\"\n", + "# in a column of liquid\n", + "h=2.493#height of the liquid (mercury) column\n", + "rho=848.7#density of mercury\n", + "P_at=2116#atmospheric pressure \n", + "print \"\\n height of mercury h=%0.3f ft\\n density of mercury rho=%0.3f lb/ft**3\\n atmospheric pressure P_at=%0.3f psf \"%(h,rho,P_at)#\n", + "#refer to equation 10.5\n", + "g=9.8\n", + "g_c=9.8\n", + "P=rho*(g/g_c)*h#gauge pressure \n", + "P_ab=round(P+P_at)#absolute pressure\n", + "print \"gauge pressure P=%0.3f psf\\n absolute pressure P_ab=%0.3f psf\"%(P,P_ab)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.2 Page no 99" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 10.2 page no 99\n", + "\n", + "\n", + "\n", + " density rho=1000.000 kg/m**3\n", + " pressure P1=10.000 atm\n", + " pressure P2=1.000 atm\n", + " height at ocean surface z1=0.000 m\n", + " \n", + " depth z2=-92.987 m\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 10.2 page no 99\\n\\n\"\n", + "#determining the depth of atlantic ocean \n", + "rho=1000#density of water\n", + "P1=10#pressure at which depth is to be determine\n", + "P2=1#pressure at the ocean surface z1\n", + "z1=0#ocean surface\n", + "g=9.807#gravitational constant\n", + "print \"\\n density rho=%0.3f kg/m**3\\n pressure P1=%0.3f atm\\n pressure P2=%0.3f atm\\n height at ocean surface z1=%0.3f m\"%(rho,P1,P2,z1)#\n", + "z2=z1-(P1-P2)*101325/(rho*g)#depth at pressure P2\n", + "print \" \\n depth z2=%0.3f m\"%(z2)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.3 Page no 99 " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 10.3 page no 99 fig 10.1\n", + "\n", + "\n", + "\n", + "\n", + " density of water rho=1000.000 kg/m**3\n", + " density of oil rho_oil=890.000 kg/m**3\n", + "\n", + " depth at point 1, z1=0.000 m\n", + " pressure P1=1.000 atm\n", + " depth at point 2,z2=-10.980 m\n", + "\n", + " gauge pressure P2_gu=95835.965 Pag\n", + "\n", + " depth z3=-13.720 m\n", + " pressure at bottom P3=122707.145 Pag\n", + "\n", + " diameter of tank d=6.100 m\n", + " surface area of tank s=29.225 m**2\n", + "\n", + " absolute pressure P3_ab=224032.145 Pag\n", + " pressure force at bottom F=6.55e+06 N\n", + "\n", + " force on the side of the tank F_s=5.73e+06 N\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "from sympy.mpmath import quad\n", + "print \"Example 10.3 page no 99 fig 10.1\\n\\n\\n\"\n", + "#a cylindrical tank contain water and immiscible oil ,tank isvopen to the atmosphere\n", + "rho=1000#density of water \n", + "SG=0.89#special gravity of oil\n", + "rho_oil=rho*SG#density of oil\n", + "print \"\\n density of water rho=%0.3f kg/m**3\\n density of oil rho_oil=%0.3f kg/m**3\"%(rho,rho_oil)#\n", + "#applying bernoulli equationbetween point 1 and 2 to calculate the gauge pressure at water oil interface\n", + "z1=0#depth at surface\n", + "P1=1#pressure at point 1\n", + "z2=-10.98#depth at point 2\n", + "print \"\\n depth at point 1, z1=%0.3f m\\n pressure P1=%0.3f atm\\n depth at point 2,z2=%0.3f m\"%(z1,P1,z2)#\n", + "g=9.807#gravitational constant\n", + "P2_gu=rho_oil*g*(z1-z2)#gauge pressure at point 2\n", + "print \"\\n gauge pressure P2_gu=%0.3f Pag\"%(P2_gu)#\n", + "#gauge preesure at bottom z3\n", + "z3=-13.72\n", + "P3=P2_gu+rho*g*(z2-z3)\n", + "print \"\\n depth z3=%0.3f m\\n pressure at bottom P3=%0.3f Pag\"%(z3,P3)#\n", + "d=6.1#diameter of tank\n", + "s=pi*d**2/4#surface area of tank \n", + "print \"\\n diameter of tank d=%0.3f m\\n surface area of tank s=%0.3f m**2\"%(d,s)#\n", + "P3_ab=P3+101325#absolute pressure\n", + "F=P3_ab*s#pressure force at the bottom of tank\n", + "print \"\\n absolute pressure P3_ab=%0.3f Pag\\n pressure force at bottom F=%0.2e N\"%(P3_ab,F)# \n", + "#the force on the side of the tank ,within water layer\n", + "F_s=(pi*d)*quad(lambda z:-11910-9807*z,[-13.72,-10.98])#\n", + "print \"\\n force on the side of the tank F_s=%0.2e N\"%(F_s)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.4 Page no 102 " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 10.4 page n0 102 \n", + "\n", + "\n", + "\n", + " weight of air W_a=200.000 lbf\n", + " weight of water W_w=120.000 lbf\n", + " sp.weight of water gamma_w=62.400 lbf/ft**3\n", + "\n", + "buoyant force F_b=80.000 lbf\n", + "\n", + " volume displaced V_dis=1.282 ft**3\n", + "\n", + " density of block rho_b=156.000 lb/ft**3\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 10.4 page n0 102 \\n\\n\"\n", + "W_a=200#weight of material in air\n", + "W_w=120#weight of material in water\n", + "gamma_w=62.4#specific weight of water\n", + "print \"\\n weight of air W_a=%0.3f lbf\\n weight of water W_w=%0.3f lbf\\n sp.weight of water gamma_w=%0.3f lbf/ft**3\"%(W_a,W_w,gamma_w)#\n", + "F_b=W_a-W_w#buoyant force\\\n", + "print \"\\nbuoyant force F_b=%0.3f lbf\"%(F_b)#\n", + "V_dis=F_b/gamma_w#volume displaced\n", + "print \"\\n volume displaced V_dis=%0.3f ft**3\"%(V_dis)#\n", + "rho_b=W_a/V_dis#density of block\n", + "print \"\\n density of block rho_b=%0.3f lb/ft**3\"%(rho_b)##printing mistake in book\n", + "#assumption of rho_b>rho_w is justified" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.5 Page no 103" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 10.5 page no 103\n", + "\n", + "\n", + "\n", + " force F=0.130 N\n", + " sp.gravity SG=1.300 \n", + " stem diameter D=0.008 m\n", + " density rho_w=1000.000 kg/m**3\n", + " g=ravitational acc. g=9.807 m/s**2\n", + "\n", + " height h=0.061 m\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"\\n Example 10.5 page no 103\\n\\n\"\n", + "#a hydrometer is a liquid specific gravity indicator with the value being indicated by the level at which the surface of the liquid intersects the sten when floating in avliquid\n", + "F=0.13#the total hydrometer weight, N\n", + "SG=1.3#sp. gravity of liquid\n", + "D=.008#stem diameter of hydrometer,m\n", + "rho_w=1000#density of water ,kg/m**3\n", + "g=9.807\n", + "pi=22/7\n", + "print \"\\n force F=%0.3f N\\n sp.gravity SG=%0.3f \\n stem diameter D=%0.3f m\\n density rho_w=%0.3f kg/m**3\\n g=ravitational acc. g=%0.3f m/s**2\"%(F,SG,D,rho_w,g)#\n", + "h=(4*F/(pi*D**2*rho_w*g))*(1-1/SG)#height where it will float\n", + "print \"\\n height h=%0.3f m\"%(h)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 10.6 Page no 105" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 10.6 page no 105 fig. 10.3\n", + "\n", + "\n", + "\n", + " \n", + " pressure P=1.817 psi\n", + "\n", + " pressure at right leg P_r=14.700 psia\n", + " pressure due to water height P_w=1.298 psi\n", + "\n", + " absolute pressure P_a=14.181 psia\n", + " gauge pressure P_g=-0.519 psig\n", + "\n", + "pressure in psfa P_af=2042 psfa\n", + " pressure in psfg P_gf=-75 psfg\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 10.6 page no 105 fig. 10.3\\n\\n\\n\"\n", + "# since the density of air is effectively zero,the contribution of air to the 3 ft. manometer can be neglected\n", + "#the contribution due to the carbon tetrachloride can be found by using the hydrostatic equation\n", + "rho=62.3#density of water\n", + "SG=1.4#/specific gravity of ccl4\n", + "h=3#height in manometer\n", + "P=rho*SG*h/144#factor 144 for psf to psi\n", + "print \" \\n pressure P=%0.3f psi\"%(P)#\n", + "P_r=14.7#the right leg of manometer is open to atmosphere,atmospheric pressure at this point\n", + "#contribution to the prssure due to the height of water above pressure gauge\n", + "P_w=rho*h/144\n", + "print \"\\n pressure at right leg P_r=%0.3f psia\\n pressure due to water height P_w=%0.3f psi\"%(P_r,P_w)#\n", + "P_a=P_r-P+P_w#absolute pressure\n", + "P_g=P_a-14.7#gauge pressure \n", + "print \"\\n absolute pressure P_a=%0.3f psia\\n gauge pressure P_g=%0.3f psig\"%(P_a,P_g)# \n", + "P_af=P_a*144\n", + "P_gf=round(P_g*144)\n", + "print \"\\npressure in psfa P_af=%0.f psfa\\n pressure in psfg P_gf=%0.f psfg\"%(P_af,P_gf)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-11_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-11_1.ipynb new file mode 100644 index 00000000..8e90299e --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-11_1.ipynb @@ -0,0 +1,276 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 11 : Ideal Gas Law" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.2 Page no. 113" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 11.2-Page no.113\n", + "\n", + "\n", + "density of gas rho =0.076lb/ft**3\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 11.2-Page no.113\\n\\n\"\n", + "#given\n", + "#Pressure(P),Temp.(T),Molecular wt. of gas(M)\n", + "P=1#atm\n", + "T_d=60#degree F\n", + "M=29#gram\n", + "#Gas constant R\n", + "R=.73\n", + "T=T_d+460# rankin\n", + "#density of gaS\n", + "rho=(P*M)/(R*T)\n", + "print \"density of gas rho =%0.3flb/ft**3\"%(rho)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.3 Page no. 114" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 11.3-Page no. 114\n", + "\n", + "\n", + "actual volumetric flowrate Qa=4461.54 acfm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 11.3-Page no. 114\\n\\n\"\n", + "#given\n", + "#standard volumetric flowrate of a gas stream(Qs),standard conditions,actual conditions\n", + "Qs=2000#scfm\n", + "Ps=1#atm\n", + "Ts=60#degree F\n", + "Pa=1#atm\n", + "Ta=700#degree F\n", + "Ta=Ta+460#rankin\n", + "Ts=Ts+460#rankin\n", + "Qa=Qs*(Ta/Ts)*(Ps/Pa)\n", + "print \"actual volumetric flowrate Qa=%.2f acfm\"%(Qa)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.4 Page no. 115" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 11.4-Page no. 115\n", + "\n", + "\n", + "standard volumetric flowrate Qs=654.48 scfm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 11.4-Page no. 115\\n\\n\"\n", + "#given\n", + "#mass flowrate of flue gas ,average moleculer weight flue gas,standard conditions\n", + "m=50#lb/min\n", + "M=29#lb/lbmol\n", + "Ts=60#degree F\n", + "Ps=1#atm\n", + "R=0.73#atm.ft**3/(lbmol.degree R)\n", + "Ts=Ts+460#rankin\n", + "Qs=(m/M)*(R*Ts/Ps)\n", + "print \"standard volumetric flowrate Qs=%0.2f scfm\"%(Qs)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.5 Page no. 116" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 11.5-Page no.1 116\n", + "\n", + "\n", + "molecular weight of gas Mw=32.02\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 11.5-Page no.1 116\\n\\n\"\n", + "#given\n", + "#specific volume(V),temperature(T),pressure(P)\n", + "V=12.084#ft**3/lb\n", + "T=70#degree F\n", + "P=1#atm\n", + "R=0.73\n", + "T=T+460#rankin\n", + "Mw=(R*T)/(P*V)\n", + "print \"molecular weight of gas Mw=%0.2f\"%(Mw)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.6 Page no 118" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 11.6 page no 118\n", + "\n", + "\n", + "\n", + "Volume of gas V=0.63 L/gmol\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 11.6 page no 118\\n\\n\"\n", + "#first and second viral coeff.\n", + "B=-0.159#m**3/kgmol\n", + "C=0.009#(m**3/kgmol)**2\n", + "V_new=0\n", + "V=0.820#\n", + "for i in range(1,4):\n", + " V_new=(1+(B)/V+(C)/(V**2))/1.22\n", + " V=V_new\n", + "print \"\\nVolume of gas V=%0.2f L/gmol\"%(V)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.7 Page no 118" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 11.7 page no 118\n", + "\n", + "\n", + "\n", + " Volume V=48.80 ft**3/lbmol \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 11.7 page no 118\\n\\n\"\n", + "#given\n", + "T_c=343# critical temperature,deg R\n", + "P_c=45.4#critical pressure,atm\n", + "#emplying redlich kwong (R-K)equation\n", + "R=0.73#gas constant \n", + "a=round(0.42748*R**2*T_c**2.5/P_c)#R-k constant\n", + "b=0.08664*R*T_c/P_c#R-k constant\n", + "# V_new=[[490/(V-b)]-[a/(25.9*V*V+b)]]/10\n", + "# V=V_new\n", + "#by trial and error method\n", + "V=48.8\n", + "print \"\\n Volume V=%0.2f ft**3/lbmol \"%(V)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-12_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-12_1.ipynb new file mode 100644 index 00000000..31dfa593 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-12_1.ipynb @@ -0,0 +1,340 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 12 : Flow Mechanisms" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.1 Page no 124" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 12.1 page no 124\n", + "\n", + "\n", + "\n", + " temperature at inlet T_i=660.00 k\n", + " diameter at inlet D_1=6.00 ft\n", + " velocity at inlet v_1=25.00 ft/s\n", + "\n", + " area at ilet A_1=28.27 st**2\n", + " volumatric flow rate at inlet q_1=706.86 ft**3/s\n", + "\n", + " temperature T_2=2360.00 k\n", + " velocity of flow at outlet v_2=40.00 ft/s\n", + "\n", + " volumatric flow rate at outlet q_2=2527.55 ft**3/s\n", + " cross sectional area at outlet A_2=63.19 ft**2 \n", + "\n", + " diameter at outlet D_2=8.97 ft \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 12.1 page no 124\\n\\n\"\n", + "T_i=660#temperature of flue at inlet in furnsce\n", + "D_1=6#inside diameter of pipe,ft\n", + "v_1=25#velocity at inlet\n", + "print \"\\n temperature at inlet T_i=%0.2f k\\n diameter at inlet D_1=%0.2f ft\\n velocity at inlet v_1=%0.2f ft/s\"%(T_i,D_1,v_1)#\n", + "A_1=pi/4*D_1**2#\n", + "q_1=A_1*v_1#volumatric flow rate at inlet\n", + "print\"\\n area at ilet A_1=%0.2f st**2\\n volumatric flow rate at inlet q_1=%0.2f ft**3/s\"%(A_1,q_1)#\n", + "#applying charle's law for volumatic flow out of the scrubber\n", + "#given\n", + "T_2=2360#the temperature up to which furnace heats the gas\n", + "v_2=40#velocity of flow at outlet\n", + "print \"\\n temperature T_2=%0.2f k\\n velocity of flow at outlet v_2=%0.2f ft/s\"%(T_2,v_2)#\n", + "q_2=q_1*(T_2/T_i)#volumatric flow rate at outlet\n", + "A_2=q_2/v_2# cross sectional area at outlet duct\n", + "print \"\\n volumatric flow rate at outlet q_2=%0.2f ft**3/s\\n cross sectional area at outlet A_2=%0.2f ft**2 \"%(q_2,A_2)#\n", + "D_2=sqrt(4*A_2/pi)#diameter at outlet\n", + "print \"\\n diameter at outlet D_2=%0.2f ft \"%(D_2)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.2 Page no 125" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 12.2 page no 125\n", + "\n", + "\n", + "\n", + " diameter of tube L=2.54 cm\n", + " density rho=1.50 gm/cm**3\n", + " velocity v=20.00 cm/s\n", + " viscosity meu=0.01 g/cm*s\n", + "\n", + " Reynolds no. R_e=9769.23 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 12.2 page no 125\\n\\n\"\n", + "#to calculate reynolds number\n", + "L=2.54#diameter of tube in cm\n", + "rho=1.50#density of liquid in gm/cm**3\n", + "v=20#velocity of flow in cm/s\n", + "meu=0.78e-2#viscosity of liquid in g/cm*s\n", + "print \"\\n diameter of tube L=%0.2f cm\\n density rho=%0.2f gm/cm**3\\n velocity v=%0.2f cm/s\\n viscosity meu=%0.2f g/cm*s\"%(L,rho,v,meu)#\n", + "R_e=L*rho*v/meu#reynolds number\n", + "print \"\\n Reynolds no. R_e=%0.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.3 Page no 126" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 12.3 page no 126\n", + "\n", + "\n", + "\n", + " velocity v = 3.80 m/s\n", + " diameter D=0.45 m\n", + " density rho=1.20 kg/m**3\n", + " viscosity meu=1.73e-05 kg/m*s\n", + "\n", + " reynoldsno R_e = 118612.72 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 12.3 page no 126\\n\\n\"\n", + "#to determine the teynolds no of a gas stream \n", + "v=3.8#velocity through the duct \n", + "D=0.45#duct diameter\n", + "rho=1.2#density of gas\n", + "meu=1.73e-5#viscosity of gas\n", + "print \"\\n velocity v = %0.2f m/s\\n diameter D=%0.2f m\\n density rho=%0.2f kg/m**3\\n viscosity meu=%0.2e kg/m*s\"%(v,D,rho,meu)#\n", + "R_e=D*v*rho/meu#reynolds no\n", + "print \"\\n reynoldsno R_e = %0.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.5 Page no 128" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 12.5 page no 128\n", + "\n", + "\n", + "\n", + " volumatric flow rate q = 0.006 m**3/s\n", + "\n", + " mass flow rate m_dot=5.43 kg/s\n", + "\n", + " average velocity v_av=2.00 m/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \" Example 12.5 page no 128\\n\\n\"\n", + "SG=0.96#sp.gravity of a liquid\n", + "R=0.03#radius of long circular tube through which liquid flow\n", + "#flow rate is related with the diameter of circular tube \n", + "q=2*pi*(3*R**2-(200/3)*R**3)#\n", + "print \"\\n volumatric flow rate q = %0.3f m**3/s\"%(q)#\n", + "rho_w=1000#density of water \n", + "rho_l=SG*rho_w#density of liquid\n", + "m_dot=rho_l*q#mass flow rate \n", + "print \"\\n mass flow rate m_dot=%0.2f kg/s\"%(m_dot)#\n", + "s=pi*R**2#surface area\n", + "v_av=q/s#average velocity\n", + "print \"\\n average velocity v_av=%0.2f m/s\"%(v_av)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.6 Page no 129" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 12.6 page no 129\n", + "\n", + "\n", + "\n", + " time t=3539.82 s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 12.6 page no 129\\n\\n\"\n", + "#refer to example 12.6\n", + "V=20#volume of liquid passes through the section,m**3\n", + "q=0.00565#volumatric flow rate \n", + "t=V/q#time to pass liquid pass through volume V\n", + "print \"\\n time t=%0.2f s\"%(t)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 12.7 Page no 130" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 12.7 page no. 130\n", + "\n", + "\n", + "\n", + " actual volumatric flow rate q=1461.54 acfm \n", + "\n", + " average velocity v=21.54 ft/s\n", + "\n", + " density rho=0.06 lb/ft**3\n", + "\n", + " mass flow rate m_dot=0.13 lb/s\n", + "\n", + "v_m=6.55\n", + "\n", + " reynolds no R_e=103737.71 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi \n", + "\n", + "print \"Example 12.7 page no. 130\\n\\n\"\n", + "#a gas is flowing through a circular duct\n", + "D=1.2#diameter of duct,ft\n", + "T=760#temperature,k\n", + "P=1#pressure\n", + "T_s=520#standard temperature\n", + "P_s=1#standard pressure\n", + "q_s=1000# standard volumatric flow rate,in scfm(given)\n", + "q=q_s*(T/T_s)*(P/P_s)#actual volumatric flow rate\n", + "print \"\\n actual volumatric flow rate q=%0.2f acfm \"%(q)#\n", + "s=pi*D**2/4#cross sectional area\n", + "s_m=s*0.0929#area in m**2 \n", + "v=(q/s)/60#velocity\n", + "print \"\\n average velocity v=%0.2f ft/s\"%(v)#\n", + "MW=33#mlecular weight of gas\n", + "R=0.7302#gas constant\n", + "rho=(P*MW)/(R*T)#density from ideal gas law\n", + "print \"\\n density rho=%0.2f lb/ft**3\"%(rho)#\n", + "m_dot=rho*v*s_m#mass flow rate \n", + "print \"\\n mass flow rate m_dot=%0.2f lb/s\"%(m_dot)##printing mistake in book\n", + "D_m=0.366#diamter in m\n", + "v_m=6.55#velocity in m/s\n", + "rho_m=rho*(0.4536/.3048**3)#density in kg/m**3\n", + "rho_m=0.952#round off value\n", + "print \"\\nv_m=%0.2f\"%(v_m)#\n", + "meu=2.2e-5#viscosity of gas in \n", + "R_e=D_m*v_m*rho_m/meu#reynolds no\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)##calculation error in book" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-13_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-13_1.ipynb new file mode 100644 index 00000000..76d1c287 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-13_1.ipynb @@ -0,0 +1,325 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 13 : Laminar Flow in Pipe" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.1 Page no 136" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 13.1 page no 136\n", + "\n", + "\n", + "\n", + " velocity v_w=0.13 ft/s\n", + "\n", + " velocity of air v_a=1.44 ft/s\n", + "\n", + " velocity of oil v_o=22.00 ft/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 13.1 page no 136\\n\\n\"\n", + "#calculate average velocities for which th flow will be viscous,laminar\n", + "#(a) water at 60 deg F in a 2-inch standard pipe \n", + "R_e=2100#reynolds number <2100, for laminar flow\n", + "meu_w=6.72e-4#viscosity of water,lb/ft.s\n", + "rho_w=62.4#density of water,lb/ft**3\n", + "D_w=2.067#diameter of pipe,ft\n", + "v_w=(R_e*meu_w)/((D_w/12)*rho_w)#velocity of water\n", + "print \"\\n velocity v_w=%0.2f ft/s\"%(v_w)#\n", + "#(b) air at 60 deg F and 5 psig in a 2 inch standard pipe\n", + "meu_a=12.1e-6#viscosity of air ,lb/ft.s\n", + "rho_a=.1024# density of air,lb/ft**3\n", + "D_a=0.17225#diameter of pipe ,ft\n", + "v_a=(R_e*meu_a)/(D_a*rho_a)#velocity of air\n", + "print \"\\n velocity of air v_a=%0.2f ft/s\"%(v_a)#\n", + "#(c) oil of a viscosity of 300 cP and SG of .92 in a 4 inch standard pipe\n", + "meu_o=300*6.72e-4#viscosity of oil ,lb/ft.s\n", + "rho_o=0.92*62.4#density of oil, lb/ft**3\n", + "D_o=.3355#diameter of pipe,ft\n", + "v_o=round((R_e*meu_o)/(D_o*rho_o))#velocity of oil\n", + "print \"\\n velocity of oil v_o=%0.2f ft/s\"%(v_o)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.2 Page no 137" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 13.2 page no 137\n", + "\n", + "\n", + "\n", + " pressure drop per unit length P_l=0.09 psf/ft\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \" Example 13.2 page no 137\\n\\n\"\n", + "#refer to part a of example 1\n", + "#appplying Hagen-Poiseuille equation\n", + "meu=6.72e-4#viscosity of water\n", + "v=0.13#velocity of water\n", + "D=2.067/12#diameter of pipe\n", + "P_l=32*meu*v/(D**2)\n", + "print \"\\n pressure drop per unit length P_l=%0.2f psf/ft\"%(P_l)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.4 Page no 138" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 13.4 page no 138\n", + "\n", + " \n", + "\n", + " hydraulic diameter D=0.40 m\n", + "\n", + " velocity of air v=0.06 m/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \" Example 13.4 page no 138\\n\\n \"\n", + "#an air conducting duct has a rectangular cross section\n", + "w=1#width of rectangular section \n", + "h=0.25#height of rectangular section\n", + "D=2*w*h/(w+h)#equivalent or hydraulic diameter\n", + "print \"\\n hydraulic diameter D=%0.2f m\"%(D)\n", + "R_e=2300#critical reynolds no\n", + "neu=1e-5#kinematic viscosity of air\n", + "v=R_e*neu/D#velocity\n", + "print \"\\n velocity of air v=%0.2f m/s\"%(v)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.5 Page no 139" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 13.5 page no 139\n", + "\n", + "\n", + "flow velocity v=22.27 ft/s\n", + "\n", + " dynamic viscosity meu=0.18 lb/ft.s\n", + "\n", + " reynolds no R_e=1438.12 \n", + "\n", + " friction factor f=0.01 \n", + "\n", + " entance length L_e=11.99 ft\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "from math import pi\n", + "print \" Example 13.5 page no 139\\n\\n\"\n", + "#a circulsr horizontal tube cntains asphalt\n", + "D=0.1667#diameter of tube,ft\n", + "s=pi*D**2/4#surface area of tube,ft**2\n", + "q=0.486#volumatric flow rate,ft**3/s\n", + "v=q/s#flow velocity\n", + "print \"flow velocity v=%0.2f ft/s\"%(v)#\n", + "g=32.174\n", + "P_grad=144#pressure gradient ,psf/ft\n", + "meu=(pi*P_grad*g*D**4)/(128*q)#dynamic viscosity,laminar flow\n", + "print \"\\n dynamic viscosity meu=%0.2f lb/ft.s\"%(meu)#\n", + "#check on the laminar flow\n", + "rho=70#density,lb/ft**3\n", + "R_e=D*v*rho/meu#reynlods number\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#\n", + "f=16/R_e#fanning friction factor\n", + "print \"\\n friction factor f=%0.2f \"%(f)#\n", + "#the pipe must be longer than the entrance length to have fully developed flow\n", + "L_e=0.05*D*R_e#entrance length\n", + "print \"\\n entance length L_e=%0.2f ft\"%(L_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.6 Page no 140" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 13.6 page no 140\n", + "\n", + "\n", + "vol. flow rate q=0.01 m**3/s\n", + "\n", + " av. velocity v_av=8.00 m/s\n", + " mass flow rate m_dot=12.60 kg/s\n", + " mass flux G=10080.00 kg/m**2.s\n", + " linear mometum flux M_dot=100.80 N \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "from sympy.mpmath import quad\n", + "print \" Example 13.6 page no 140\\n\\n\"\n", + "#liquid glycerin flows in a tube \n", + "#to obtain the properties of glycerine use table A.2 in the appendix\n", + "rho=1260#density,kg/m**3\n", + "meu=1.49#viscosity,kg/ms\n", + "neu=meu/rho#kinematic viscosity,m**2/s\n", + "R=0.02#by no slip condition radius of tube,m\n", + "q=32*pi*quad(lambda r:r-2500*r**3,[0,R]) #volumatric flow rate from the given parabolic velocity distribution\n", + "print \"vol. flow rate q=%0.2f m**3/s\"%(q)#\n", + "r=0#for average velocity for laminar flow\n", + "v_av=16*(1-2500*r**2)/2#average velocity\n", + "q=0.010#approximation\n", + "m_dot=q*rho#mass flow rate\n", + "G=rho*v_av#mass flux \n", + "M_dot=m_dot*v_av#inear momentum flux\n", + "print \"\\n av. velocity v_av=%0.2f m/s\\n mass flow rate m_dot=%0.2f kg/s\\n mass flux G=%0.2f kg/m**2.s\\n linear mometum flux M_dot=%0.2f N \"%(v_av,m_dot,G,M_dot)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 13.7 Page no 142" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 13.7 page no 142\n", + "\n", + "\n", + "\n", + " reynolds no R_e=135.30 \n", + "\n", + " time t=87.72 min\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 13.7 page no 142\\n\\n\"\n", + "#refer to example 13.6\n", + "rho=1260#density,kg/m**3\n", + "v=8#flow velocity,m**2/s\n", + "D=0.02#diameter,m\n", + "meu=1.49#viscosity\n", + "R_e=rho*v*D/meu#reynolds no\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#\n", + "V=14000#volume in gallons of glycerine pass through a cross section of tube \n", + "q=159.6#flow rate\n", + "t=V/q#time\n", + "print \"\\n time t=%0.2f min\"%(t)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-14_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-14_1.ipynb new file mode 100644 index 00000000..f803b1a9 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-14_1.ipynb @@ -0,0 +1,587 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 14 : Turbulent Flow in Pipes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.1 page no 148" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.1 page no 148\n", + "\n", + "\n", + "\n", + " Reynolds no R_e = 9769.23 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 14.1 page no 148\\n\\n\" # a liquid flow through a tube\n", + "meu=0.78e-2#viscosity of liquid,g/cm*s\n", + "rho=1.50#density,g/cm**3\n", + "D=2.54#diameter,cm\n", + "v=20#flow velocity\n", + "R_e=D*v*rho/meu#reynolds no\n", + "print \"\\n Reynolds no R_e = %.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.2 page no 148" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.2 page no 148\n", + "\n", + "\n", + "\n", + " velocity v = 0.28 ft/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 14.2 page no 148\\n\\n\" # a fluid is moving through a cylinder in laminar flow\n", + "meu=6.9216e-4#viscosity of fluid,lb/ft*s\n", + "rho=62.4#density,lb/ft**3\n", + "D=1/12#diameter,ft\n", + "R_e=2100#reynolds no\n", + "v=R_e*meu/(D*rho)#minimum velocity at which turbulance will appear\n", + "print \"\\n velocity v = %.2f ft/s\"%(v)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.3 page no 152" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.3 page no 152\n", + "\n", + "\n", + "\n", + " fanning friction factor f_a=0.01 \n", + "\n", + " friction factor f_b1=0.01 \n", + "\n", + " friction factor f_b2=0.01 \n", + "\n", + " friction factor f_c=0.01 \n", + "\n", + " friction factor f_d=0.01 \n", + "\n", + " friction factor f_e=0.01\n", + "\n", + " average friction f_av=0.01 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "from math import log10\n", + "print \"Example 14.3 page no 152\\n\\n\" # calculate the friction factor by using different equation's\n", + "R_e=14080#reynolds no\n", + "K_r=0.004#relative roughness (a) by PAT proposed equation\n", + "f_a=0.0015+(8*(R_e)**0.30)**-1\n", + "print \"\\n fanning friction factor f_a=%0.2f \"%(f_a)# equation for 5000<R_e>50000\n", + "f_b1=0.0786/(R_e)**0.25 \n", + "print \"\\n friction factor f_b1=%0.2f \"%(f_b1)# equation for 30000<R_e>1000000\n", + "f_b2=0.046/(R_e)**0.20\n", + "print \"\\n friction factor f_b2=%0.2f \"%(f_b2)# equation for the completely turbulent region \n", + "f_c=1/(4*(1.14-2*log10(K_r))**2)\n", + "print \"\\n friction factor f_c=%0.2f \"%(f_c)# equation given by jain \n", + "f_d=1/(2.28-4*log10(K_r+21.25/(R_e**.9)))**2\n", + "print \"\\n friction factor f_d=%0.2f \"%(f_d)#\n", + "f_e=0.0085 #from figur 14.2\n", + "print \"\\n friction factor f_e=%0.2f\"%(f_e)#\n", + "f_av=(f_a+f_b1+f_b2+f_c+f_d+f_e)/6\n", + "print \"\\n average friction f_av=%0.2f \"%(f_av)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.4 page no 154" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.4 page no 154\n", + "\n", + "\n", + "\n", + " equivalent diameter D_eq_a=3.33 in\n", + "\n", + " equivalent diameter D_eq_b=18.00 cm\n", + "\n", + " equivalent diameter D_eq_c=10.00 cm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "from math import pi\n", + "print \"Example 14.4 page no 154\\n\\n\" # for turbulent fluid flow in across section (a) for a rectangle \n", + "w=2#width of a rectangle,in\n", + "h=10#height of rectangle,in\n", + "S_a=h*w#cross sectional area\n", + "P_a=2*h+2*w#perimeter of rectangle\n", + "D_eq_a=4*S_a/P_a#equivalent diameter\n", + "print \"\\n equivalent diameter D_eq_a=%0.2f in\"%(D_eq_a)# (b) for an annulus \n", + "d_o=10#outer diameter of annulus\n", + "d_i=8#inner diameter \n", + "S_b=pi*(d_o**2-d_i**2)/4#cross sectional area\n", + "P_b=pi*(d_o-d_i)#perimeter\n", + "D_eq_b=(4*S_b)/(P_b)#eq. diameter\n", + "print \"\\n equivalent diameter D_eq_b=%0.2f cm\"%(D_eq_b)# (c) for an half- full circle\n", + "d_c=10#diameter of circle \n", + "S_c=pi*d_c**2/8# cross sectional area\n", + "P_c=pi*d_c/2#perimeter\n", + "D_eq_c=4*S_c/P_c#eq. diameter\n", + "print \"\\n equivalent diameter D_eq_c=%0.2f cm\"%(D_eq_c)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exampkle 14.5 page no 157" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.5 page no 157\n", + "\n", + "\n", + "\n", + " pipe diameter D=0.29 ft\n", + "\n", + "D=0.69 \n", + "\n", + " flow velocity v=22.28 ft/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 14.5 page no 157\\n\\n\" # air is transported through a circular conduit \n", + "MW=28.9#molecular weight of air \n", + "R=10.73#gas constant\n", + "T=500#temperature\n", + "P=14.75#pressure,psia applying ideal gas law for density\n", + "rho=P*MW/(R*T)#density \n", + "rho=0.08#after round off\n", + "meu=3.54e-7#viscosity of air at 40 degF assume flow is laminar\n", + "q=8.33#flow rate ,ft**3/s\n", + "L=800#length of pipe,ft\n", + "P_1=.1#pressure at starting point\n", + "P_2=.01#pressure at delivery point \n", + "D=((128*meu*L*q)/(pi*(P_1-P_2)*144))**(1/4)#diameter\n", + "print \"\\n pipe diameter D=%0.2f ft\"%(D)# check the flow type\n", + "meu=1.14e-5\n", + "R_e1=4*q*rho/(pi*D*meu)#reynolds no print \"\\n reynolds no R_e=%0.2f \"%(R_e)# from R_e we can conclude that laminar flow is not valid\n", + "P_drop=12.96#pressure drop P_1-P2 in psf\n", + "f=0.005#fanning friction factor\n", + "g_c=32.174\n", + "D=(32*rho*f*L*q**2/(g_c*pi**2*P_drop))**(0.2)#diamter from new assumption strat the second iteration with the newly calculated D\n", + "k=0.00006/12#roughness factor\n", + "K_r=k/D#relative roughness \n", + "C_f=1.321224\n", + "R_e_n=4*q*rho/(pi*D*meu)#new reynolds no print \"\\n new reynolds no R_e=%0.2f \"%(R_e)#\n", + "f_n=0.0045#new fanning friction factor\n", + "D=(((8*rho*f_n*L*q**2)/(g_c*pi**2*P_drop))**(0.2))*C_f#final calculated diameter because last diameter is same with this\n", + "print \"\\nD=%0.2f \"%(D)# iteration may now be terminated\n", + "S=pi*(D**2)/4#cross sectional area of pipe\n", + "v=q/S#flow velocity\n", + "print \"\\n flow velocity v=%0.2f ft/s\"%(v)##printing mistake in book in the value of meu in the formula of D is first time that's why this deviation in answer" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.6 page no 159" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.6 page no. 159\n", + "\n", + "\n", + "\n", + " R_e=106208.60 \n", + "\n", + " since R_e is more than 4000 flow is turbulent\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 14.6 page no. 159\\n\\n\" # ethyl alcohol is pumped through a horizontal tube\n", + "rho=789#density .kg/m**3\n", + "meu=1.1e-3#viscosity ,kg/m-s\n", + "k=1.5e-6#roughness,m\n", + "L=60#length of tube,m\n", + "q=2.778e-3#flow rate \n", + "g=9.807\n", + "h_f=30#friction loss\n", + "A=(L*q**2)/(g*h_f)\n", + "A=1.574e-7\n", + "D=0.66*(((k**1.25)*(A**4.75)+meu*(A**5.2)/(q*rho))**.04)\n", + "D=0.0377 # calculate velocity of alcohol in the tube\n", + "S=3.14*(D)**2/4#surface area\n", + "v=q/S#velocity\n", + "v=3.93#velocity\n", + "neu=1.395e-6#dynamic viscosity\n", + "R_e=D*v/neu#reynolds no \n", + "print \"\\n R_e=%0.2f \"%(R_e)##printing mistake in book\n", + "print \"\\n since R_e is more than 4000 flow is turbulent\" #" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exanmple 14.7 page no 160" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.7 page no 160\n", + "\n", + "\n", + "\n", + " average velocity v=2.37 m/s\n", + "\n", + " S=0.00 \n", + "\n", + " flow rate q=1244.02 m**3/s\n", + "\n", + " mass flow rate m_dot=1020094.94 kg/s\n", + "\n", + " v_max=2.91 m/s\n", + "\n", + " length L_c=1.36 m\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 14.7 page no 160\\n\\n\" # kerosene flow ina lng ,smooth ,horizontal pipe\n", + "rho=820#density,kg/m**3\n", + "D=0.0493#iside diameter of pipe by appendix A.5,m\n", + "R_e=60000\n", + "meu=0.0016#viscosity,kg/m.s\n", + "v=(R_e*meu)/(D*rho)# flow average velocity\n", + "print \"\\n average velocity v=%0.2f m/s\"%(v)#\n", + "S=(pi/4)*D**2#cross sectional area\n", + "print \"\\n S=%0.2f \"%(S)#\n", + "q=v/S#flow rate \n", + "print \"\\n flow rate q=%0.2f m**3/s\"%(q)##printing mistake in book\n", + "m_dot=rho*q#mass flow rate\n", + "print \"\\n mass flow rate m_dot=%0.2f kg/s\"%(m_dot)##printing mistake in book in the value of v\n", + "n=7#seventh power apply\n", + "v_max=v/(2*n**2/((n+1)*(2*n+1)))#maximum velocity\n", + "print \"\\n v_max=%0.2f m/s\"%(v_max)# check the assumptioon of fully developed flow\n", + "R_e=60000#reynolds no\n", + "L_c=4.4*R_e**(1/6)*D#critical length\n", + "print \"\\n length L_c=%0.2f m\"%(L_c)# since L_c <L th eassumption is valid" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.8 page no 161" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 14.8 page no 161\n", + "\n", + "\n", + "\n", + " fanning friction factor f=0.01 \n", + "\n", + " h_f friction loss=1.07 m \n", + "\n", + " P_drop_a =0.09 atm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 14.8 page no 161\\n\\n\" # refer to example no 14.7\n", + "rho=860#density\n", + "R_e=60000#reynolds no\n", + "f=.046/R_e**.2#fanning friction factor\n", + "print \"\\n fanning friction factor f=%0.2f \"%(f)#\n", + "L=9#length of tube\n", + "v=2.38#velocity\n", + "D=.0493#diameter of tube\n", + "g=9.807\n", + "h_f=4*f*(L*v**2)/(D*2*g)#friction loss \n", + "print \"\\n h_f friction loss=%0.2f m \"%(h_f)# applying bernoulli equation\n", + "P_drop=rho*g*h_f#pressure drop in pa\n", + "P_drop_a=P_drop/10**5#pressure drop in atm\n", + "print \"\\n P_drop_a =%0.2f atm\"%(P_drop_a)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.9 page no 161" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 14.9 page no 161\n", + "\n", + "\n", + "\n", + " Force required to hold pipe F=16.58 N\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \" Example 14.9 page no 161\\n\\n\" # refer to example 14.7\n", + "D=0.0493#diameter of tuube\n", + "S=pi*D**2/4#cross sectional area\\\n", + "P=8685#pressure\n", + "F=P*S#force required to hold the pipe,direction is opposite the flow\n", + "print \"\\n Force required to hold pipe F=%0.2f N\"%(F)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.10 page no 163" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.10 page no 163\n", + "\n", + "\n", + "\n", + " vz_bar=40.00\n", + "\n", + " vz_sqr=4.60\n", + "\n", + " intensity of turbulance I=0.05 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"Example 14.10 page no 163\\n\\n\" # a fluid is moving in the turbulent flw through a pipe a hot wire anemometer is inserted to measure the local velocity at a given point P in the system following readings were recorded at equal time interval instantaneous velocities at subsequent time interval\n", + "vz=[43.4,42.1,42,40.8,38.5,37,37.5,38,39,41.7]\n", + "vz_bar=0#\n", + "n=10#\n", + "i = 0#\n", + "sums=0#\n", + "for i in range(0,10):\n", + " sums=sums+vz[i]#\n", + "\n", + "vz_bar=sums/n#\n", + "print \"\\n vz_bar=%0.2f\"%(vz_bar)#\n", + "sigma=0#\n", + "for i in range(0,10):\n", + " sigma=sigma+(vz[i]-vz_bar)**2#\n", + " vz_sqr=sigma/10#\n", + "\n", + "print \"\\n vz_sqr=%0.2f\"%(vz_sqr)\n", + "I = sqrt(vz_sqr)/vz_bar#intensity of turbulance\n", + "print \"\\n intensity of turbulance I=%0.2f \"%(I)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 14.11 page no 164" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 14.11 page no 164\n", + "\n", + "\n", + "\n", + " flow rate q_a=0.33 ft**3/min\n", + " \n", + " flow rate q_b=0.65 ft**3/min\n", + "\n", + " flow rate q_c=0.53 ft**3/min\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 14.11 page no 164\\n\\n\" # a fluid is flowing through a pipe\n", + "D=2#inside diameter of pipe,in\n", + "v_max=30#maximum velocity,ft/min\n", + "A=(pi/4)*(D/12)**2#cross sectional area (a) for laminar flow \n", + "v_a=(1/2)*v_max#average velocity\n", + "q_a=v_a*A#volumatric flow rate\n", + "print \"\\n flow rate q_a=%0.2f ft**3/min\"%(q_a)# (b) for plug flow \n", + "v_b=v_max#average velocity \n", + "q_b=v_b*A#volumatric flow rate\n", + "print \" \\n flow rate q_b=%0.2f ft**3/min\"%(q_b)# (c)for turbulent flow\n", + "v_c=(49/60)*v_max#average velocity\n", + "q_c=v_c*A#volumatric flow rate\n", + "print \"\\n flow rate q_c=%0.2f ft**3/min\"%(q_c)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-15_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-15_1.ipynb new file mode 100644 index 00000000..4c3339e9 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-15_1.ipynb @@ -0,0 +1,314 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 15 : Compressible and Sonic Flow" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.2 Page no 169" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 15.2 page no 169\n", + "\n", + "\n", + "\n", + " speed of sound on nitrogen c=349.01 m/s\n", + "\n", + " mach no. M_a=0.235 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \" Example 15.2 page no 169\\n\\n\"\n", + "#nitrogen gas is flowing in a duct,neglect compressibility effects\n", + "T=293#temperature,k\n", + "R=8314.4#gas constant\n", + "k=1.4#for nitrogen\n", + "M=28#molecular weight of nitrogen\n", + "c=sqrt(k*R*T/M)#speed of sound in nitrogen \n", + "print \"\\n speed of sound on nitrogen c=%0.2f m/s\"%(c)#\n", + "v=82#flow velocity \n", + "M_a=v/c#mach no.\n", + "print \"\\n mach no. M_a=%0.3f \"%(M_a)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.3 Page no 170" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 15.3 page no 170\n", + "\n", + "\n", + "\n", + " speed of sound in propane c=266.91 m/s\n", + "\n", + " M_a mach no=0.16 \n", + "\n", + " reynolds no R_e=872394.75 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"Example 15.3 page no 170\\n\\n\"\n", + "#propane is flowing in a tube\n", + "k=1.3#degree of freedom for propane\n", + "T=290#temperature,k\n", + "M=44#mol. weight \n", + "R=8314.4#gas constant\n", + "c=sqrt((k*R*T)/M)#speed of sound in propane\n", + "print \"\\n speed of sound in propane c=%0.2f m/s\"%(c)#\n", + "v=43#average velocity\n", + "M_a=v/c#mach no.\n", + "print \"\\n M_a mach no=%0.2f \"%(M_a)#\n", + "#mach no is< 0.3,that's why flow is incompressible\n", + "rho=6.39#density,kg/m**3\n", + "meu=8e-6#viscosity ,m**2/s\n", + "D=0.0254#inside diameter of tube\n", + "R_e=D*rho*v/meu#reynolds no.\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#\n", + "#because R_e is >4000,flow is turbulent" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.6 Page no 173" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 15.6 page no 173\n", + "\n", + "\n", + "\n", + " pressure drop P_drop=35.00 psia\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 15.6 page no 173\\n\\n\"\n", + "#methane is flowing through a horizontal steel pipe\n", + "m_dot=10#mass flow rate, lb/s\n", + "D=1#diameter of pipe,ft\n", + "G=m_dot/((pi/4)*D**2)#mass velocity flux\n", + "P=89.7#inlet pressure\n", + "T=530#temprature,k\n", + "MW=16#mol. weight\n", + "R=10.73#gas constant\n", + "#applying eq 15.7\n", + "rho=P*MW/(R*T)#density\n", + "f=0.008#friction factor\n", + "L=15840#length of pipe,ft\n", + "g_c=32.2#gravitational constant\n", + "P_drop=(2*f*L*(G**2))/(g_c*rho*D)#pressure drop\n", + "P1=89.7#inlet pressure,psia\n", + "P2=P1-(P_drop/144)\n", + "P2=54.7#corrected value\n", + "P_drop=P1-P2#updated value of P_drop\n", + "print \"\\n pressure drop P_drop=%0.2f psia\"%(P_drop)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.7 Page no 174" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 15.7 page no 174\n", + "\n", + "\n", + "\n", + " reynolds no R_e=1718538.57 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 15.7 page no 174\\n\\n\"\n", + "#refr to example 15.6\n", + "D=1#diameter of pipe\n", + "G=12.7#mass velocity flux\n", + "meu=7.39e-6#viscosity,lb/ft.s\n", + "R_e=(D*G)/(meu)#reynolds no\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.8 Page no 174" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example no page no 174\n", + "\n", + "\n", + "\n", + " density rho =3.31 kg/m**3\n", + "\n", + " G mass velocity flux =99.40 kg/m**2.s\n", + "\n", + " pressure drop P__2=2.52 atm\n", + "\n", + " P_drop pressure=0.18 atm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example no page no 174\\n\\n\"\n", + "#air flowing through a steel pipe \n", + "P_1=2.7#pressure,atm\n", + "T=288#temperature,k\n", + "v=30#velocity at the entrance of the pipe ,m/s\n", + "Mw=29#mol. weight of air\n", + "V=22.4#standard volume\n", + "T_s=273#st. temp\n", + "P_s=1#st. pressure\n", + "rho=(Mw*P_1*T_s)/(V*T*P_s)#density \n", + "print \"\\n density rho =%0.2f kg/m**3\"%(rho)#\n", + "G=v*rho#mass veocity flux\n", + "print \"\\n G mass velocity flux =%0.2f kg/m**2.s\"%(G)#\n", + "f=0.004#friction factor\n", + "D=0.085#diameter ,m\n", + "L=65#length of pipe,m\n", + "#gravitational constant\n", + "P_2=P_1-2*f*L*G**2/(rho*D*101325)#pressure drop across the line\n", + "#factor 101325 for atm\n", + "print \"\\n pressure drop P__2=%0.2f atm\"%(P_2)#\n", + "P_drop=P_1-P_2#pressure drop\n", + "print \"\\n P_drop pressure=%0.2f atm\"%(P_drop)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 15.9 Page no 175" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 15.9 page no 175\n", + "\n", + "\n", + "\n", + " reynolds no R_e=485086.21 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \" Example 15.9 page no 175\\n\\n\"\n", + "#refer to Example 15.9\n", + "meu=1.74e-5#viscosity,kg/m.s\n", + "D=0.085#diameter of pipe\n", + "G=99.3#mass velocity flux\n", + "R_e=D*G/meu#reynolds no.\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-16_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-16_1.ipynb new file mode 100644 index 00000000..10681e75 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-16_1.ipynb @@ -0,0 +1,248 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 16 : Two Phase Flow" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.2 Page no 183" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 16.2 page no 183\n", + "\n", + "\n", + "\n", + " Y_g=32.71 \n", + "\n", + " P_drop_t=88.63 psf/100 ft\n", + "\n", + " Y_l =12.03 \n", + "\n", + " P_drop=90.21 psf/100ft\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 16.2 page no 183\\n\\n\"\n", + "#cal. pressure drop if the flow for both phases is turbulent\n", + "#a. since the flow is tt and 1<X<10 ,apply equatuion 16.16b to obtain Y_g\n", + "X=1.66\n", + "Y_g=5.80+6.7143*X+6.9643*X**2-0.75*X**3\n", + "print \"\\n Y_g=%0.2f \"%(Y_g)#\n", + "#the value of Y_g is an excellent agreement with the values provided by lockhart and Martinelli\n", + "#then pressure drop is\n", + "P_drop_g=2.71\n", + "P_drop_t=Y_g*P_drop_g\n", + "print \"\\n P_drop_t=%0.2f psf/100 ft\"%(P_drop_t)#\n", + "#b. applying eq. 16.17b to generate Y_l\n", + "Y_l=18.219*X**-.8192\n", + "print \"\\n Y_l =%0.2f \"%(Y_l)#\n", + "#pressure drop from eq. 16.2\n", + "P_drop_l=7.50\n", + "P_drop=Y_l*P_drop_l\n", + "print \"\\n P_drop=%0.2f psf/100ft\"%(P_drop)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.3 Page no 185" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 16.3 page no 185\n", + "\n", + "\n", + "\n", + " Y_G_tv=20.48 \n", + "\n", + " pressure drop P_drop_a=55.51 psf/100 ft\n", + "\n", + " Y_l_tv=8.07 \n", + "\n", + " P_drop_b=60.52 psf/100 f\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 16.3 page no 185\\n\\n\"\n", + "#if the flow for the gas phase is turbulent and the liquid phase is viscous\n", + "#cal. pressure drop total\n", + "X=1.66#from ex. 16.1\n", + "Y_G_tv=20-21.81*X+16.357*X**2-1.8333*X**3\n", + "print \"\\n Y_G_tv=%0.2f \"%(Y_G_tv)#\n", + "#pressure drop from eq 16.1\n", + "P_drop_g=2.71\n", + "P_drop_a=Y_G_tv*P_drop_g\n", + "print \"\\n pressure drop P_drop_a=%0.2f psf/100 ft\"%(P_drop_a)#\n", + "#b. applying eq 16.20b to generate Y_l\n", + "Y_l_tv=11.702*X**-0.7334\n", + "print \"\\n Y_l_tv=%0.2f \"%(Y_l_tv)#\n", + "#pressure drop from equation 16.2\n", + "P_drop_l=7.50\n", + "P_drop_b=Y_l_tv*P_drop_l\n", + "print \"\\n P_drop_b=%0.2f psf/100 f\"%(P_drop_b)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.4 Page no 187" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 16.4 page no 187\n", + "\n", + "\n", + "\n", + " Y_G=12.45 \n", + "\n", + " pressure drop P_drop=33.74 psf/100 ft\n", + "\n", + " Y_l =4.88 \n", + "\n", + " pressure drop P_drop_b=36.61 psf/100 ft\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 16.4 page no 187\\n\\n\"\n", + "#if flow for both phases is laminar then cal pressure drop total\n", + "#a. apply eq. 16.22b to obtain Y_G\n", + "X=1.66\n", + "Y_G=10-10.405*X+8.6786*X**2-0.9167*X**3\n", + "print \"\\n Y_G=%0.2f \"%(Y_G)#\n", + "#pressure drop from eq 16.1\n", + "P_drop_g=2.71\n", + "P_drop=Y_G*P_drop_g\n", + "print \"\\n pressure drop P_drop=%0.2f psf/100 ft\"%(P_drop)#\n", + "#b. apply eq 16.23b to generate Y_l\n", + "Y_l=6.4699*X**-0.556\n", + "print \"\\n Y_l =%0.2f \"%(Y_l)#\n", + "#pressure drop from eq. 16.2\n", + "P_drop_l=7.50\n", + "P_drop_b=Y_l*P_drop_l\n", + "print \"\\n pressure drop P_drop_b=%0.2f psf/100 ft\"%(P_drop_b)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 16.6 Page no 191" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 16.6 page no 191\n", + "\n", + "\n", + "\n", + " S=0.03 \n", + "\n", + " velocity v_a =3.07 ft/s\n", + " velocity v_k=1.03 ft/s\n", + "\n", + " R_e_a=3557.49\n", + "R_e_k=6145.91 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"\\n Example 16.6 page no 191\\n\\n\"\n", + "#a mixture of air(a) and kerosene(k) are flowing in a horizontal pipe \n", + "rho_a=0.075#density of airlb/ft**3\n", + "meu_a=1.24e-5#viscosity of air ,lb/ft.s\n", + "q_a=5.3125#flow rate ft**3/s\n", + "rho_k=52.1#density of kerosene,lb/ft**3\n", + "meu_k=0.00168#viscosity lof kerosene,lb/ft.s\n", + "q_k=1.790#flow rate ft**3/s\n", + "D=.19167#diameter of pipe ,ft\n", + "S=(pi/4)*D**2#cross sectional area,ft**2\n", + "print \"\\n S=%0.2f \"%(S)#\n", + "#superficial velocity of each phase can be obtained by applying either eq, 16.7 and 16.8\n", + "v_a=q_a/(S*60)#for air\n", + "v_k=q_k/(S*60)#for kerosene\n", + "print \"\\n velocity v_a =%0.2f ft/s\\n velocity v_k=%0.2f ft/s\"%(v_a,v_k)#\n", + "R_e_a=D*rho_a*v_a/meu_a#reynolds no. of Air\n", + "R_e_k=D*rho_k*v_k/meu_k#reynolds no. of kerosene\n", + "print \"\\n R_e_a=%0.2f\\nR_e_k=%0.2f \"%(R_e_a,R_e_k)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-17_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-17_1.ipynb new file mode 100644 index 00000000..d8ea433c --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-17_1.ipynb @@ -0,0 +1,305 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 17 : Prime Movers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 17.1 Page no 201" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 17.1 page no 201\n", + "\n", + "\n", + "\n", + " power requirement h_p_b=33.10 bhp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 17.1 page no 201\\n\\n\"\n", + "#fan are operating for transporting gas\n", + "#two fans fan(a)and fan(b)\n", + "D_a=46#diameter of blade of fan (a)\n", + "rpm_a=1575#operating speed of fan(a)\n", + "D_b=42#diameter of blade of fan(b)\n", + "rpm_b=1625#operating speed of fan(b)\n", + "h_p_a=47.5#power requirement of fan (a)\n", + "h_p_b=(rpm_b**3/rpm_a**3)*(D_b/D_a)**5*h_p_a#power requirement of fan(b)\n", + "print \"\\n power requirement h_p_b=%.2f bhp\"%(h_p_b)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 17.2 Page no 201" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 17.2 page no 201\n", + "\n", + "\n", + "\n", + "new flow rate q_n=15123.97 acfm\n", + "\n", + "new pressureP_n=7.68 in H20\n", + "\n", + " new powerhp_n=17.62 bhp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 17.2 page no 201\\n\\n\"\n", + "rpm=1694#speed of fan \n", + "q=12200#flow rate of q_a\n", + "rpm_n=2100#new speed of fan \n", + "q_n=q*(rpm_n/rpm)#new flow rate\n", + "print \"\\nnew flow rate q_n=%.2f acfm\"%(q_n)#\n", + "#applyingeq 17.5\n", + "P=5#pressure ,in\n", + "P_n=P*(rpm_n**2/rpm**2)#new pressure\n", + "print \"\\nnew pressureP_n=%.2f in H20\"%(P_n)#\n", + "#required power is calculated using eq. 17.6\n", + "hp=9.25#power at 1694 speed\n", + "hp_n=hp*(rpm_n**3/rpm**3)#new power required\n", + "print \"\\n new powerhp_n=%.2f bhp\"%(hp_n)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 17.3 Page no. 201" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\\Example 17.3 page no 201\n", + "\n", + "\n", + "\n", + " total pressure P_drop=10.80 in H20\n", + "\n", + " brake horse power bhp=17.55 bhp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\Example 17.3 page no 201\\n\\n\"\n", + "# a gas stream in a process\n", + "P_l_m=4.4# minor pressure loss for duct work,valves etc,in\n", + "P_l_mz=6.4#major pressure loss due to pieces of equipment,in\n", + "P_drop=P_l_m+P_l_mz#total pressure drop\n", + "print \"\\n total pressure P_drop=%.2f in H20\"%(P_drop)#\n", + "#applying eq 17.7\n", + "q=6500#flow rate ,acfm\n", + "neta=0.63#overall fan-motor effficiency \n", + "bhp=1.575e-4*q*P_drop/neta#brake horse power required\n", + "#1.575e-5 is aconversion factor for horse power\n", + "print \"\\n brake horse power bhp=%.2f bhp\"%(bhp)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 17.4 Page no 208" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 17.4 page no 208\n", + "\n", + "\n", + "\n", + " pressure P=20.00 kpa\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 17.4 page no 208\\n\\n\"\n", + "#a pump is in process\n", + "#given: parabolic pump pressure flow \n", + "#P=a-b*q**2 equation\n", + "#a and b calculate from conditions\n", + "a=25\n", + "b=5\n", + "#then equation becomes P=25-5*q**2\n", + "#pressure at 1m**3/s flow rate\n", + "q=1#flow rate,m**3/s\n", + "P=a-b*q**2#pressure\n", + "print \"\\n pressure P=%.2f kpa\"%(P)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 17.6 Page no 214" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 17.6 page no. 214\n", + "\n", + "\n", + "\n", + " total head hc=36.24 ft of water\n", + "\n", + " m_dot mass flow rate =4.87 lb/s\n", + "\n", + " fluid power requirement W_dot=176.40 lbf.ft/s\n", + "\n", + " brake horse power bhp=0.53 bhp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 17.6 page no. 214\\n\\n\"\n", + "#the total head developed by a centrifugal pump is given by a equation \n", + "#hc=42-0.0047*q**2\n", + "#the pump is to be used in a water flow system in which the pump head in feet of water is given by eq.\n", + "#hp=12+0.0198*q**2\n", + "#for cal. flow rate hc=hp\n", + "q=35#from condition hc=hp,gpm\n", + "hc=42-0.0047*q**2#total head\n", + "print \"\\n total head hc=%.2f ft of water\"%(hc)#\n", + "rho=62.40#density\n", + "q_c=0.078#flow rate in cfs unit\n", + "m_dot=rho*q_c#mass flow rate\n", + "print \"\\n m_dot mass flow rate =%.2f lb/s\"%(m_dot)#\n", + "W_dot=m_dot*hc#fluid power requirement can be calculated\n", + "print \"\\n fluid power requirement W_dot=%.2f lbf.ft/s\"%(W_dot)#\n", + "neta=.6#efficiency\n", + "W_dot_hp=.32#fluid power requirement in hp\n", + "bhp=W_dot_hp/neta#brake horse power\n", + "print \"\\n brake horse power bhp=%.2f bhp\"%(bhp)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 17.8 Page no 216" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 17.8 page no 216\n", + "\n", + "\n", + "\n", + " energy requirement W_s=-1163.53 btu/lbmol of air\n", + "\n", + " power hp=-2.34e+05 ft .lbf/min\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 17.8 page no 216\\n\\n\"\n", + "#compressed air is to be employed in the nozzle\n", + "T1=520#temperature\n", + "P2=40#pressure\n", + "P1=14.7#atmosphric pressure\n", + "gamma=1.3#degree of freedom\n", + "R=1.987#gas constant\n", + "W_s=-(gamma*R*T1/(gamma-1))*((P2/P1)**((gamma-1)/gamma)-1)#compreesd energy requirement \n", + "print \"\\n energy requirement W_s=%.2f btu/lbmol of air\"%(W_s)#\n", + "hp=W_s*(7.5/29)*778#power\n", + "print \"\\n power hp=%.2e ft .lbf/min\"%(hp)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-18_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-18_1.ipynb new file mode 100644 index 00000000..3e95a23a --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-18_1.ipynb @@ -0,0 +1,400 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 18 : Valves and Fittings" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.1 Page no 225" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 18.1 page no 225\n", + "\n", + "\n", + "\n", + " K_se coeff. of sudden expansion=0.56 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 18.1 page no 225\\n\\n\"\n", + "#there is a sudden expansion in which the diameter D1 doubls to D2,D2=2D1\n", + "#if D1=1 then D2=2\n", + "D1=1.0#diameter D1\n", + "D2=2#diameter D2\n", + "K_se=(1-(D1/D2)**2)**2# coefficent of sudden expansion \n", + "print \"\\n K_se coeff. of sudden expansion=%0.2f \"%(K_se)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.2 Page no 227" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 18.2 page no 227\n", + "\n", + "\n", + "\n", + " L_eq_gate=21.00 in\n", + "\n", + " L_eq_globe=900.00 in \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 18.2 page no 227\\n\\n\"\n", + "#cal. equivalent length of pipe that would cause the same head los for gate and globe valve located in piping\n", + "D=3#diameter of pipe,in\n", + "L_gate=7#L/D ratio for fully open gate valve\n", + "L_globe=300#L/D ratio for globe valve \n", + "L_eq_gate=L_gate*D#equivalent length for gate valve\n", + "print \"\\n L_eq_gate=%0.2f in\"%(L_eq_gate)#\n", + "L_eq_globe=L_globe*D#equivalent length for globe valve\n", + "print \"\\n L_eq_globe=%0.2f in \"%(L_eq_globe)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.3 Page no 227" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 18.3 page no 227\n", + "\n", + "\n", + "\n", + " reynolds no R_e=29017.86 \n", + "\n", + " friction factor f=0.01 \n", + "\n", + " pressure drop P_drop=2689.88 lbf/ft**2 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 18.3 page no 227\\n\\n\"\n", + "# water is flowing at room temperature\n", + "rho=62.4#density of water,lb/ft**3\n", + "meu=6.72e-4#viscosity of water,lb/ft.s\n", + "D=0.03125#diameter of pipe\n", + "v=10#velocity \n", + "R_e=D*v*rho/meu#reynolds no.\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#\n", + "f=0.0015+0.125/R_e**.30#equation for friction factor\n", + "print \"\\n friction factor f=%0.2f \"%(f)#\n", + "L=30#length of pipe\n", + "gc=32.2#gravitational constant\n", + "P_drop=2*f*rho*v**2*L/(D*gc)#pressure drop \n", + "print \"\\n pressure drop P_drop=%0.2f lbf/ft**2 \"%(P_drop)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.4 Page no 229" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 18.4 pageno 229\n", + "\n", + "\n", + "\n", + " friction loss due to globe valve h_f=34.16 ft.lbf/lb\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 18.4 pageno 229\\n\\n\"\n", + "#refer to example 18.3\n", + "#applying eq 18.4 for friction loss by globe valve\n", + "K_f=22#coeff of expansion loss\n", + "v=10#velocity\n", + "gc=32.2#ravitational constant\n", + "h_f=K_f*v**2/(2*gc)#friction loss due to globe valve\n", + "print \"\\n friction loss due to globe valve h_f=%0.2f ft.lbf/lb\"%(h_f)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.5 Page no 230" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 18.5 page no. 230\n", + "\n", + "\n", + "\n", + " total pressure drop P_d_t=4814.78 lbf/ft**2\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 18.5 page no. 230\\n\\n\"\n", + "#refer to example no. 18.3 and 18.4\n", + "P_drop=34.16#pressure drop ,ft\n", + "h_f=43#friction loss due to fitting\n", + "rho=62.4#density,lb/ft**3\n", + "P_d_t=(P_drop+h_f)*rho#total pressure drop\n", + "print \"\\n total pressure drop P_d_t=%0.2f lbf/ft**2\"%(P_d_t)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.6 Page no 230" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 18.6 page no 230\n", + "\n", + "\n", + "\n", + " h_f=120.05 \n", + "\n", + " reynolds number R_e=904180.14 \n", + "\n", + " vol. flow rate q=6.40 ft**3/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt, pi\n", + "print \"Example 18.6 page no 230\\n\\n\"\n", + "k=0.00085#relative roughness of pipe ,ft\n", + "D=0.833#diameter of pipe,ft\n", + "f=0.005#we assume fanning friction factor ,0.004-0.005,select upper limit\n", + "K=0.45#entrance loss coefficient is estimated from eq. 18.10 and 18.11\n", + "L=5000#length of pipe,ft\n", + "h_f=4*f*(L/D)#the friction head loss in terms of the line velocity\n", + "print \"\\n h_f=%0.2f \"%(h_f)##printing mistake in book 12 instead of 120\n", + "#applying bernoulli equation between points 1 and 2 to calculate v2\n", + "h_s=0#no shaft head\n", + "v1=0#large tank\n", + "#because both locations open to the atmosphere,P1=P2=0 psig\n", + "h=260#height from point 1 to 2\n", + "V2_h=sqrt(h/(1+h_f+K))#total velocity head at point 2\n", + "g=32.174\n", + "V2=V2_h*2*g\n", + "V2=11.75\n", + "neu=1.0825e-5#viscosity\n", + "R_e=D*(V2)/neu#reynolds number\n", + "print \"\\n reynolds number R_e=%0.2f \"%(R_e)##printing mistake in book due to value of h_f\n", + "q=V2*(pi*(D**2)/4)#volumatric flow rate\n", + "print \"\\n vol. flow rate q=%0.2f ft**3/s\"%(q)##printing mistake in book due to value of h_f" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.7 Page no 232" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 18.7 page no 232\n", + "\n", + "\n", + "\n", + " relative roughness K_r=0.00 \n", + "\n", + " flow velocity v=2.64 m/s\n", + "\n", + " reynolds no R_e=205941.18 \n", + "\n", + " head loss h_f=377.37 J/kg\n", + "\n", + " major friction losses h_s=377.37 J/kg\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt, pi\n", + "\n", + "print \"Example 18.7 page no 232\\n\\n\"\n", + "#two large water reservoirs are connected by a pipe\n", + "D=0.0779#diameter of pipe (m), by appendix A.5 for 3 inch schdule 40 pipe\n", + "k=0.046*1e-3#roughness of pipe\n", + "K_r=k/D#relative roughness\n", + "print \"\\n relative roughness K_r=%0.2f \"%(K_r)#\n", + "q=0.0126#flow rate of water m**3/s,\n", + "S=(pi/4)*D**2#cross sectional area of pipe\n", + "v=q/S#flow velocity of water\n", + "print \"\\n flow velocity v=%0.2f m/s\"%(v)#\n", + "neu=1e-6#viscosity of water\n", + "R_e=v*D/neu#reynolds no\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#\n", + "#from R_e and relative roughness K_r ,obtain friction factor \n", + "f=0.00345\n", + "L=2000*.3048#length of pipe,m\n", + "h_f=4*f*(L/D)*(v**2/2)\n", + "print \"\\n head loss h_f=%0.2f J/kg\"%(h_f)#\n", + "#apply bernoulli equation between station 1 and 2. Note that P1=P2=1 atm,v1=v2,z1=z2\n", + "#P_drop/rho + V**2/2g + z = h_s - h_f\n", + "#whera h_s is the major friction loss\n", + "#above equation reduces to h_s=h_f\n", + "h_s=h_f#h_s is major friction loss\n", + "print \"\\n major friction losses h_s=%0.2f J/kg\"%(h_s)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 18.8 Page no 233" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 18.8 page no 233\n", + "\n", + "\n", + "\n", + " W_dot fluid power=5985.00 kw\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 18.8 page no 233\\n\\n\"\n", + "#refer to example no 18.7\n", + "rho=1000#density\n", + "g=9.807#gravitational acc.\n", + "h_f=38.39#head loss\n", + "P_rise=rho*g*h_f#pressure rise across the pump\n", + "P_rise=475000#in book by mistake this value instead original value \n", + "q=0.0126#flow rate from example 18.7\n", + "W_dot=q*P_rise#ideal pumping requirement(the fluid power)\n", + "print \"\\n W_dot fluid power=%0.2f kw\"%(W_dot)##printing mistake in book in putting value of P_rise" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-19_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-19_1.ipynb new file mode 100644 index 00000000..cb58ffc8 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-19_1.ipynb @@ -0,0 +1,427 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 19 : Flow Measurement" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.1 Page no. 246" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 19.1 page no 246\n", + "\n", + "\n", + "\n", + " pressure P1=1.10e+05 Pag\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 19.1 page no 246\\n\\n\"\n", + "#we have to find pressure at different point in a oil tank\n", + "#apply manometer equation between point 1 and 2\n", + "#since rho1=rho2,z1=z2\n", + "#it gives P1=P2\n", + "#applying manometer equation between points 2 and 3\n", + "rho_oil=0.8*1000#density of oil\n", + "#since rho3=rho_oil=rho2\n", + "rho3=rho_oil\n", + "z_32=.4#height difference between point 2 and 3\n", + "g=9.807#grav. acc.\n", + "P7=0#pressure at point 7,on gauge basis\n", + "z_76=0.8#height difference between point 6 and 7\n", + "rho_hg=13600#density of mercury\n", + "P6=P7 + rho_hg*g*z_76#pressure at point 6\n", + "P5=P6#pressure at point 5\n", + "rho_air=1.2#density of air\n", + "z_54=1#height difference between point 5 and 4\n", + "P4=P5 + rho_air*g*z_54#pressure at point 4 \n", + "P3=P4#pressure at point 3\n", + "P2=P3 + rho_oil*g*z_32#pressure at point 2\n", + "P1=P2#air pressure in the oil tank\n", + "print \"\\n pressure P1=%0.2e Pag\"%(P1)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.2 Page no 250" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 19.2 page no 250\n", + "\n", + "\n", + "\n", + " velocity v=29.87 ft/s\n", + "\n", + " maximum veocity v_max=29.87 ft/s\n", + "\n", + " average velocity v_av=24.34 ft/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"Example 19.2 page no 250\\n\\n\"\n", + "#pitot tube is located at the center line of a horizontal pipe transporting air\n", + "rho=0.075#density of gas ,lb/ft**2\n", + "h=0.0166667#height difference,ft\n", + "g=32.2#gravitational acc. lb/ft**2\n", + "rho_m=62.4#density of medium which is air\n", + "v=sqrt(2*g*h*(rho_m-rho)/rho)#velocity\n", + "print \"\\n velocity v=%0.2f ft/s\"%(v)#\n", + "v_max=v#because at that point where the reading was taken is the centerline\n", + "print \"\\n maximum veocity v_max=%0.2f ft/s\"%(v_max)#\n", + "#since the flowing fluid is air at a high velocity the flow has a high probability of being turbilent .from chapter 14,assume\n", + "#v_av/v_max=0.815\n", + "v_av=v_max*0.815\n", + "print \"\\n average velocity v_av=%0.2f ft/s\"%(v_av)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.3 Page no 251" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 19.3 page no 251\n", + "\n", + "\n", + "\n", + " flow rate q=1149.24 ft**3 min\n", + "\n", + " m_dot mass flow rate=5171.58 lb/hr\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 19.3 page no 251\\n\\n\"\n", + "#refer to example 19.3 \n", + "S=0.785#cross sectional area,ft**2\n", + "v_av=24.4#average velocity,ft/s\n", + "q=v_av*S*60#flow rate,factor 60 for minute\n", + "print \"\\n flow rate q=%0.2f ft**3 min\"%(q)#\n", + "rho=0.075#density \n", + "m_dot=q*rho*60#mass flow rate \n", + "print \"\\n m_dot mass flow rate=%0.2f lb/hr\"%(m_dot)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.4 Page no 251" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 19.4 page no\n", + "\n", + "\n", + "\n", + " water velocity v=4.16 m/s \n", + "\n", + " cross sectional area S=0.00 m**2\n", + "\n", + " flow rate q=0.02 m**3/s\n", + "\n", + " reynolds no R_e=324007.33 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 19.4 page no\\n\\n\"\n", + "#water flow ina circular pipe,a pitot tube is used to measure the water velocity \n", + "h=0.07#manometer height,m\n", + "rho=1000#density of water,kg/m**3\n", + "rho_m=13600#density of mercury,kg/m**3\n", + "g=9.807\n", + "v=sqrt(2*g*h*(rho_m-rho)/rho)\n", + "print \"\\n water velocity v=%0.2f m/s \"%(v)#\n", + "D=0.0779#pipe inside diameter,by using table A.5 in the appendix for a 3 inch schedule 40 pipe\n", + "S=(pi/4)*D**2\n", + "print \"\\n cross sectional area S=%0.2f m**2\"%(S)#\n", + "q=v*S#flow rate\n", + "print \"\\n flow rate q=%0.2f m**3/s\"%(q)#\n", + "meu=0.001#viscosity of water,kg/m.s\n", + "R_e=rho*v*D/meu#reynolds number\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.5 Page no 254" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 19.5 page no 254\n", + "\n", + "\n", + "\n", + " velocity at throat v2=3.61 m/s\n", + "\n", + " flow rate q =0.00 m**3/s\n", + "\n", + " pressure P2=96890.27 Pa\n", + "\n", + " pressure loss P_l=443.47 Pa\n", + "\n", + " power loss W_l=0.50 W\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 19.5 page no 254\\n\\n\"\n", + "#a venturi meter has gasoline flowing through it.\n", + "h=0.035#height of venturi meter\n", + "D1=0.06#upsteeam diameter,m\n", + "D2=0.02#throat diameter,m\n", + "rho_m=13600#density of mercury\n", + "rho=680#density of gasoline\n", + "g=9.807\n", + "v2=sqrt((2*g*h*(rho_m-rho)/rho)/1-D2**4/D1**4)#velocity of gasoline at the the throat\n", + "print \"\\n velocity at throat v2=%0.2f m/s\"%(v2)#\n", + "q=(pi/4)*D2**2*v2#flow rate\n", + "print \"\\n flow rate q =%0.2f m**3/s\"%(q)#\n", + "P1=101325#upstream pressure,Pa\n", + "P2=P1-g*h*(rho_m-rho)#pressure at throat P2\n", + "print \"\\n pressure P2=%0.2f Pa\"%(P2)#\n", + "P_d=P1-P2#pressure difference\n", + "P_l=.1*P_d#pressure loss is 10 %\n", + "print \"\\n pressure loss P_l=%0.2f Pa\"%(P_l)#\n", + "W_l=q*P_l#power loss\n", + "print \"\\n power loss W_l=%0.2f W\"%(W_l)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.6 Page no. 255" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 19.6 page no. 255\n", + "\n", + "\n", + "\n", + " velocity v2=12.21 m/s\n", + "\n", + " flow rate q=3.84e-03 m**3/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"\\n Example 19.6 page no. 255\\n\\n\"\n", + "#refer to example 19.5\n", + "#if gasoline has vapor pressure of 50000Pa ,we have to calculate flow rate at whhich cavitation to occur\n", + "P1=101325#upstream pressure,Pa\n", + "P2=50000#given vapor pressure,Pa\n", + "D1=0.06#upstream diameter,m\n", + "D2=0.02#throat diameter,m\n", + "rho=680#density of gasoline\n", + "v2=sqrt((2*(P1-P2))/rho*(1-D2**4/D1**4))#velocity\n", + "print \"\\n velocity v2=%0.2f m/s\"%(v2)# \n", + "q=(pi/4)*D2**2*v2#flow rate\n", + "print \"\\n flow rate q=%0.2e m**3/s\"%(q)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.7 Page no 258" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 19.7 page no 258\n", + "\n", + "\n", + "\n", + " velocity through orifice v2=35.27 m/s\n", + "\n", + " pressure P=509.80 Pa\n", + "\n", + " Reynolds no. R_e=457919.49 \n", + "\n", + " actual pressure drop P_l=572.00 Pa\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 19.7 page no 258\\n\\n\"\n", + "#an orifice meter is equipped with flange top is installed to measure the flow rate of air in a circular duct\n", + "D1=0.25#diameter of circular duct,m\n", + "D2=0.19#orifice diamter,m\n", + "v2=4/(pi*D2**2)#velocity through orifice\n", + "print \"\\n velocity through orifice v2=%0.2f m/s\"%(v2)#\n", + "C_o=1# assuming orifice discharge coefficient\n", + "rho=1.23#density of air,kg/m**3\n", + "P=rho*v2**2*(1-(D2**4/D1**4))/2#pressure \n", + "print \"\\n pressure P=%0.2f Pa\"%(P)#\n", + "meu=1.8e-5# absolute viscosity\n", + "R_e=rho*v2*D2/(meu)#reynolds no.\n", + "print \"\\n Reynolds no. R_e=%0.2f \"%(R_e)#\n", + "C_ac=0.62#actual discharge cefficient,from fig.19.8\n", + "P_ac=P/(C_ac)**2#actual pressure drop \n", + "P_rec=14*(D2/D1) + 80*((D2/D1)**2)#equation for percentage pressure recovery\n", + "P_loss=100-P_rec#precentage pressure loss\n", + "P_l=round((P_loss/100)*P_ac)#actual pressure drop after recovery\n", + "print \"\\n actual pressure drop P_l=%0.2f Pa\"%(P_l)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 19.9 Page no 259" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 19.9 page no 259\n", + "\n", + "\n", + "\n", + " volumatric flow rate q=6.67 ft**3/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 19.9 page no 259\\n\\n\"\n", + "#air at ambient condition is flowing in a pipe\n", + "rho=0.075#density of air ,lb/ft**3\n", + "m_dot=0.5#mass flow rate ,lb/s\n", + "q=m_dot/rho#volumatric flow rate\n", + "print \"\\n volumatric flow rate q=%0.2f ft**3/s\"%(q)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-20_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-20_1.ipynb new file mode 100644 index 00000000..c37ab601 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-20_1.ipynb @@ -0,0 +1,339 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 20 : Ventilation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 20.2 Page no 269" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 20.2 page no 269\n", + "\n", + "\n", + "\n", + " C_a concentration of toluene=0.00 \n", + " q volumatric flow rate q=0.38 gal/h \n", + " S_g specific gravity=0.87 \n", + "\n", + " mass flow rate m_dot-tol=1.09 lb/h\n", + "\n", + " mass flow rate in g/min m_dot_g=8.24 g/min\n", + "\n", + " no. of moles n_dot_tol=0.09 gmol/min\n", + "\n", + " R gas constant=0.08 atm.L/(gmol.K)\n", + " T temperature=293.00 K\n", + " P pressure =1.00 atm\n", + "\n", + " toluene vapor vol. flow rate q_tol=2.15 L/min\n", + "\n", + " diluent vol. flow rate q_dil=134375.00 L/min\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 20.2 page no 269\\n\\n\"\n", + "#ventilation required in an indoor work area where a toluene containing adhesive in a nanotechnology process is used.\n", + "#equation for estimate the dilution air requirement \n", + "C_a=80e-6#concentration of toluene\n", + "q=3/8#volumatric flow rate, gal/h\n", + "v=0.4#adhesive contains 4 volume % toluene\n", + "S_g=0.87#specific gravity\n", + "print \"\\n C_a concentration of toluene=%.2f \\n q volumatric flow rate q=%.2f gal/h \\n S_g specific gravity=%.2f \"%(C_a,q,S_g)#\n", + "#mass flow rate of toluene \n", + "m_dot_tol=q*v*S_g*(8.34)#factor 8.34 for lb\n", + "print \"\\n mass flow rate m_dot-tol=%.2f lb/h\"%(m_dot_tol)#\n", + "m_dot_g=m_dot_tol*(454/60)#unit conversion of mass flow rate in g/min\n", + "print \"\\n mass flow rate in g/min m_dot_g=%.2f g/min\"%(m_dot_g)#\n", + "M_w=92#molecular weight of toluene\n", + "n_dot_tol=m_dot_g/M_w#no. of gm moles of toluene/min\n", + "print \"\\n no. of moles n_dot_tol=%.2f gmol/min\"%(n_dot_tol)#\n", + "#resultant toluene vapor volumatric flow rate q_tol is directly calculated from th eidal gas law\n", + "#applying ideal gas law\n", + "R=0.08206#gas constant \n", + "P=1#standard pressure\n", + "T=293#standard temperature\n", + "print \"\\n R gas constant=%.2f atm.L/(gmol.K)\\n T temperature=%.2f K\\n P pressure =%.2f atm\"%(R,T,P)#\n", + "q_tol=n_dot_tol*R*T/P#toluene vapor volumatric flow rate \n", + "print \"\\n toluene vapor vol. flow rate q_tol=%.2f L/min\"%(q_tol)#\n", + "q_tol=2.15#round off value\n", + "#the required diluent volumatric flow rtae\n", + "K=5#dimensionless mixing factor \n", + "q_dil=K*q_tol/(C_a)#diluent vol. flow rate\n", + "print \"\\n diluent vol. flow rate q_dil=%.2f L/min\"%(q_dil)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 20.3 Page no 270" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 20.3 page no 270 \n", + "\n", + "\n", + "\n", + " lbmol of H2S n_H2S=0.01 lbmol\n", + "\n", + " mass of H2S m_H2S=0.34 lb\n", + "\n", + " stand. temperature T_st=32.00 F\n", + " temperature of air in room T_r=51.00 F\n", + " stand. volume v_st=359.00 ft**3\n", + "\n", + " volume of air at 51deg F V_a=372.86 ft**3\n", + "\n", + " conc. of H2S in ppm C_H2S=2732.19 ppm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 20.3 page no 270 \\n\\n\"\n", + "# a certain poorly ventilated room chemical stroage room has a ceiling fan\n", + "#inside this room bottle of iron(3) sulfide sits next to a bottle sulfuric acid containg 1 lb H2SO4 in water\n", + "# an earthquake sends the botlles on the shelf crashing to the floor where bottles break and their contant mix and react to form iron(3) sulfate and hydrogen sulfide\n", + "#we have to calculate maximum H2S concentration that could be reached in the room\n", + "Mw_Fe2S3=208#mol. weight of Fe2S3\n", + "Mw_H2SO4=98#mol. weight of H2SO4\n", + "Mw_H2S=34#mol. weight of H2S\n", + "Mw_air=29#mol. weight of air\n", + "#balancing chemical reaction \n", + "# from the stiochiometric of the reaction ,sulfuric acid is the limiting reagent\n", + "# 0.030 lbmol of Fe2S3 is required to react with 0.010 lbmol of H2SO4\\\n", + "v_r=1600#volume of room,ft**3\n", + "n_H2SO4=0.010# lbmol of H2SO4\n", + "Stoi_c_H2SO4=3#stoichiometric coeff. of H2SO4\n", + "Stoi_c_H2S=3#stoichiometric coeff. of H2S\n", + "n_H2S=n_H2SO4*(Stoi_c_H2S/Stoi_c_H2SO4)#lbmol of H2S\n", + "print \"\\n lbmol of H2S n_H2S=%.2f lbmol\"%(n_H2S)#\n", + "m_H2S=n_H2S*Mw_H2S#conversion of moles into mass of H2S\n", + "print \"\\n mass of H2S m_H2S=%.2f lb\"%(m_H2S)#\n", + "#at 32 degF and i atm pressure an ideal gas occupies 359 ft**3 volume then,at 51 deg F occupies\n", + "T_r=51#temperature of air in the room\n", + "T_st=32#standard temperature\n", + "v_st=359#standard volume\n", + "print \"\\n stand. temperature T_st=%.2f F\\n temperature of air in room T_r=%.2f F\\n stand. volume v_st=%.2f ft**3\"%(T_st,T_r,v_st)# \n", + "V_a=v_st*(460+T_r)/(460+T_st)#volume of air\n", + "print \"\\n volume of air at 51deg F V_a=%.2f ft**3\"%(V_a)#\n", + "#the final concentration of H2S in the room in ppm C_H2S\n", + "C_H2S=m_H2S*(V_a/Mw_air)*1e+6/(v_r)\n", + "print \"\\n conc. of H2S in ppm C_H2S=%.2f ppm\"%(C_H2S)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 20.4 Page no 271" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 20.4 page no 271\n", + "\n", + "\n", + "\n", + " rho density of vinyl chloride=0.00 g/cm**3\n", + "\n", + " vol. flow rate q=3135.11 cm**3/min\n", + "\n", + " vol.flow rate q_air=110700.00 acfm\n", + "\n", + " air flow rate for dilution q_dil=1107000.00 acfm\n", + "\n", + " air flow rate q_exh=521.00 acfm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 20.4 page no 271\\n\\n\"\n", + "#vinyl chloride application\n", + "#calculation of density by using ideal gas law\n", + "Mw=78#molecular weight of vinyl chloride\n", + "R=82.06#gas constant,cm**3.atm/mol.K \n", + "T=298#temperature,K \n", + "P=1#pressure ,atm\n", + "rho=P*Mw/(R*T)#density of vinyl chloride\n", + "print \"\\n rho density of vinyl chloride=%.2f g/cm**3\"%(rho)#\n", + "#given\n", + "m_dot=10#mass flow rate,g/min\n", + "q=m_dot/rho#volumatric flow rate\n", + "print \"\\n vol. flow rate q=%.2f cm**3/min\"%(q)#\n", + "q_acfm=0.1107#vol flow rate in acfm\n", + "#cal. the air flow rate in acfm q_air required to meet the 1.0 ppm constraint with the equation \n", + "q_air=q_acfm/1e-6\n", + "print \"\\n vol.flow rate q_air=%.2f acfm\"%(q_air)#\n", + "S_factor=10#correct for mixing by employing a saftey factor\n", + "#apply saftey factor to calculate the actual air flow rate for dilution ventilation \n", + "q_dil=S_factor*q_air\n", + "print \"\\n air flow rate for dilution q_dil=%.2f acfm\"%(q_dil)#\n", + "#now consider the local exhaust ventilation by first calculating the face area\n", + "H=30#height of hood,in\n", + "W=25#width of hood,in\n", + "S=H*W/144#surface area of hood ,ft**2\n", + "#the air flow rate in acfm q_air,exh required for a face velocity of 100 ft/min is then\n", + "v=100#face velocity,ft/min\n", + "q_exh=round(S*v)\n", + "print \"\\n air flow rate q_exh=%.2f acfm\"%(q_exh)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 20.7 Page no 276" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 20.7 page no 276\n", + "\n", + "\n", + "\n", + " q_o min. air ventilation flow rate=10.00 m**3/min\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 20.7 page no 276\\n\\n\"\n", + "#refer to illustrative Example 20.5\n", + "#(1)\n", + "#we have to calculate minimum air ventilation flow rate into the room containing 10 ng/m**3 of a toxic chemical\n", + "#ng means nanograms\n", + "rV=250#chemical generated in the laboratory,ng/min\n", + "c_o=10#room containg toxic chemical of 10ng/m**3 \n", + "c=35#limit of chemical concentration,ng/m**3\n", + "#applicable modal in this case\n", + "#q_o(c_o-c) + rV =V*dc/dt\n", + "#substituting gives\n", + "q_o=(-rV)/(c_o-c)#minimum air ventilation flow rate\n", + "print \"\\n q_o min. air ventilation flow rate=%.2f m**3/min\"%(q_o)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 20.8 Page no 277" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 20.8 page no 277\n", + "\n", + "\n", + "\n", + " t=29.00 min \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import exp\n", + "from scipy.optimize import fsolve\n", + "print \" Example 20.8 page no 277\\n\\n\"\n", + "#refer to example no 20.5 and 20.7\n", + "V=142#volume of room,m**3\n", + "q=12.1# flow rate of air,m**3/min\n", + "tou=V/q#time ,min\n", + "r=30#rate of generation of chemical,ng/min\n", + "k=r/V#ng/(m**3.min)\n", + "c_i=85#intial concentration in laboratory,ng/m**3\n", + "c_o=10#given concentration in room\n", + "c=20.7#final concentration in room\n", + "#by using trial and error mthod we get \n", + "def f(t):\n", + " y=c_i*(exp(-t/tou))+ (c_o+k*tou)*(1-exp(-t/tou)) - c\n", + " return y\n", + "t=fsolve(f,30)#\n", + "#by using trail and error method we get\n", + "t=29\n", + "print \"\\n t=%.2f min \"%(t)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-21_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-21_1.ipynb new file mode 100644 index 00000000..3865ae4c --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-21_1.ipynb @@ -0,0 +1,417 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 21 : Academic Application" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.7 Page no 284" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.7 page no 284\n", + "\n", + "\n", + "\n", + " veloctiy of fluid v=3.43 ft/s\n", + "\n", + " reynolds no R_e=13326.84 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 21.7 page no 284\\n\\n\"\n", + "# water is flowing through a 3/8 in schedule 40 brass pipe\n", + "D=0.0411#diameter of pipe,ft\n", + "S=0.00133#cross section area of pipe,ft**2\n", + "meu=6.598e-4#viscosity of water from table A.4 in the appendix,lb/ft.s\n", + "rho=62.4#density,lb/ft**3\n", + "q_gpm=2#vol.flow rate \n", + "q=q_gpm*0.00228#volumatric flow rate in ft**3s\n", + "v=q/S#velocity of fluid\n", + "print \"\\n veloctiy of fluid v=%.2f ft/s\"%(v)#\n", + "R_e=D*v*rho/meu#reynolds no.\n", + "print \"\\n reynolds no R_e=%.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.8 Page no 285" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.8 page no 285\n", + "\n", + "\n", + "\n", + " reynolds no R_e11=115553.46\n", + " reynolds no R_e12=462213.85 \n", + "\n", + " reynolds no R_e21=91588.19\n", + " reynolds no R_e22=366352.78\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 21.8 page no 285\\n\\n\"\n", + "#water flowing through a pipe\n", + "rho=62.4#density of water,lb/ft**3\n", + "meu=6.72e-4#viscosity of water,lb/ft.s\n", + "q_1gpm=1.5#vol. flow rate in gpm\n", + "q_2gpm=6#vol. flow rate in gpm \n", + "D_1=0.493#internal diameter of 3/8 in schdule pipe\n", + "v11=(0.409*q_1gpm)/(D_1**2)#flow velocity for an 3/8 in pipe with 1.5 gpm flow rate \n", + "v12=(0.409*q_2gpm)/(D_1**2)#flow velocity for an 3/8 pipe with 6 gpm flow\n", + "R_e11=D_1*v11*rho/meu#reynolds no for case 11\n", + "R_e12=D_1*v12*rho/meu#reynolds no for case 12\n", + "print \"\\n reynolds no R_e11=%.2f\\n reynolds no R_e12=%.2f \"%(R_e11,R_e12)##printing mistake in book\n", + "D_2=0.622#internal diameter of 1/2 in schdule pipe \n", + "v21=(0.409*q_1gpm)/D_2**2#flow velocity for 1/2 pipe with 1.5 gpm\n", + "v22=(0.409*q_2gpm)/D_2**2#flow velocity for 1/2 pipe with 6 gpm\n", + "R_e21=D_2*v21*rho/meu#reynolds no for case 21\n", + "R_e22=D_2*v22*rho/meu#reynolds no foe case 22\n", + "print \"\\n reynolds no R_e21=%.2f\\n reynolds no R_e22=%.2f\"%(R_e21,R_e22)#\n", + "#printing mistake in value of R_e" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.9 page no 286 " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example no 21.9 page no 286\n", + "\n", + "\n", + "\n", + " frictional loss h_f=14.93 ft.lbf/lb \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example no 21.9 page no 286\\n\\n\"\n", + "#water is flowing in a vertical pipe \n", + "#assume constant velocity \n", + "P_drop=-4.5#pressure drop from bottom to top\n", + "rho=62.4 #density of water \n", + "z2=15#height of pipe\n", + "z1=0#bottom level\n", + "#applying bernoulli equation \n", + "h_f=(P_drop/rho)+(z2-z1)#frictional loss \n", + "print \"\\n frictional loss h_f=%.2f ft.lbf/lb \"%(h_f)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.10 Page no 286" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.10 page no 286\n", + "\n", + "\n", + "\n", + " work h_sf=499500.00 ft.lbf/s\n", + "\n", + " actual work W_p=1397.00 hp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 21.10 page no 286\\n\\n\"\n", + "#a centrifugal pump is needed to transport water from sea level to 10000 feet above sea level\n", + "#using bernoulli equation\n", + "#neglectiing kinetic energy effects and frictional losses\n", + "P1=14.7#atmospheric pressure at sea level,psi\n", + "P2=10.2#atmospheric pressure at 10000 feet,psi\n", + "z1=0#at sea level,ft\n", + "z2=10000#height above sea level,ft\n", + "rho=62.4#density of water\n", + "g=32.2#gravitational acc.\n", + "g_c=32.2#gravitational constant\n", + "h_s=((P2-P1)*144/(rho) + (z2-z1)*(g/g_c))#work deliverd by the pump to the water,in ft.lbf/lb\n", + "h_s=9990#ft.lbf/lb\n", + "h_sf=h_s*50#in ft.lbf\n", + "print \"\\n work h_sf=%.2f ft.lbf/s\"%(h_sf)#\n", + "#actual pump work is calculated by dividing the above terms by the frictional afficiency\n", + "neta=0.65#frictional efficiency\n", + "W_p=round((h_sf/550)/neta)#actual work\n", + "print \"\\n actual work W_p=%.2f hp\"%(W_p)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.12 Page no 288" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.12 page no 288\n", + "\n", + "\n", + "\n", + " frictional loss h_f=12.77 ft.lbf/lb\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 21.12 page no 288\\n\\n\"\n", + "#refer to illustrative Example 21.4\n", + "# if the pipe contains two globe valves and one straight through tee,what is the friction loss\n", + "K_f_globe=6\n", + "K_f_tee=0.4\n", + "v=2.53# flow velocity \n", + "g_c=32.2\n", + "f=5/4#friction factor\n", + "L=144#lenth of pipe\n", + "D=62.4#diameter\n", + "h_f=4*f*(L/D) + (2*K_f_globe + K_f_tee)*(v**2/(2*g_c))\n", + "print \"\\n frictional loss h_f=%.2f ft.lbf/lb\"%(h_f)#\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.13 Page no 289 " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.13 page no 289 fig 21.1 \n", + "\n", + "\n", + "\n", + "\n", + " flow velocity v=3.29 m/s\n", + "\n", + " reynolds no R_e=4157.04 \n", + "\n", + " mass flow rate m_dot=7.18 kg/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt, pi\n", + "print \"Example 21.13 page no 289 fig 21.1 \\n\\n\\n\"\n", + "#a pitot tube is inserted in acircular pipe to measure the flow velocity\n", + "# the tube is inserted so that it points upstream into the flow and the pressure sensed by thre probeis the stagnation pressure \n", + "#the change in elevation between the tip of the pitot and the wall pressure tap is negligible \n", + "#the flowing fluid is soyabean oil at 20 deg C and the fluid in manometer tube is mercury\n", + "#point 2 is a stagnation point ,P2>P1 and the manometer fluid should be higher on th eleft side(h<0) \n", + "rho_m=13600#density of mercury,kg/m**3\n", + "h=0.04#height of mercury,\n", + "rho=919#density of oil kg/m**3\n", + "g=9.804\n", + "D=0.055#diameter of pipe,m\n", + "meu=0.04#viscosity of oil,kg.m.s\n", + "v=sqrt(2*g*h*((rho_m/rho)-1))#flow velocity\n", + "print \"\\n flow velocity v=%.2f m/s\"%(v)#\n", + "#assuming uniform velocity\n", + "S=(pi/4)*D**2\n", + "m_dot=rho*v*S#mass flow rate\n", + "R_e=(D*v*rho)/meu#reynolds no\n", + "print \"\\n reynolds no R_e=%.2f \"%(R_e)#\n", + "print \"\\n mass flow rate m_dot=%.2f kg/s\"%(m_dot)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.14 Page no 290" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.14 page no 290\n", + "\n", + "\n", + "\n", + " frictional loss h_f=8661.02 ft.lbf/lb \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 21.14 page no 290\\n\\n\"\n", + "#given: a 50 ft pipe with flowing water ,we have to determine the flow rate if there is an expansion from 3/8 inch to 1/8 inch and immediatly back to 3/8n inch with an overall pressure loss no greater than 2lbf/ft**2\n", + "#from table A.5 in the appendix \n", + "S1=0.00133#cross sectional area of 3/8 inch pipe,ft**2\n", + "S2=0.00211#cross sectional area of 1/2 inch pipe,ft**2\n", + "K_e=(1-S1/S2)**2#expansion constant\n", + "K_c=0.4*(1-S2/S1)**2#contraction constant\n", + "L=50#length of pipe\n", + "D=0.03125#diameter of pipe\n", + "v=1.93#velocity ,ft/s\n", + "f=0.01124#friction factor from table 21.3,for velocity estimated to be 1.93 ft/s\n", + "g_c=32.2 \n", + "h_f=(4*f*L/D + K_e + K_c)*(v**2*g_c)#frictional loss\n", + "print \"\\n frictional loss h_f=%.2f ft.lbf/lb \"%(h_f)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 21.16 Page no 291" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 21.16 page no 291\n", + "\n", + "\n", + "\n", + " flow velocity v_m=45.00 m/s\n", + "\n", + " pressure drop in prototype P_drop_p=0.021 Pa\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 21.16 page no 291\\n\\n\"\n", + "#water flows in a concrete pipe\n", + "v_p=0.02# flow velocity,m/s \n", + "D_p=1.5#diameter of pipe\n", + "L_p=20#length of pipe,m\n", + "rho_p=1000#density of water,kg/m**3\n", + "meu_p=0.001#viscosity of water,kg/m.s\n", + "K_p=0.003#roughnes factor,m\n", + "#this prototype is to be modeled in a lab using a 1/3o th scale pipe\n", + "D_m=D_p/30#D_m is diameter of modeled pipe\n", + "L_m=L_p*(D_m/D_p)#length of modeled pipe\n", + "K_m=K_p*(D_m/D_p)#roughness factor for modeled pipe\n", + "#the fluid in the model is caster oil \n", + "rho_m=961.3#densiy of oil, kg/m**3\n", + "meu_m=0.0721#viscosity of oil,kg/m.s\n", + "#since R_e = (rho_m*v_m*D_m)/meu_m = (rho_p*v_p*D_p)/meu_p\n", + "v_m = (rho_p*v_p*D_p*meu_m)/(rho_m*D_m*meu_p)# flow velcity in molded pipe\n", + "print \"\\n flow velocity v_m=%.2f m/s\"%(v_m)#\n", + "#pressure drop in prototype\n", + "P_drop_m=1e+5#pressure drop in model\n", + "P_drop_p=(P_drop_m*rho_p*(v_p)**2)/(rho_m*(v_m)**2)#pressure drop in prototype\n", + "print \"\\n pressure drop in prototype P_drop_p=%.3f Pa\"%(P_drop_p)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-22_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-22_1.ipynb new file mode 100644 index 00000000..b9b12c6a --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-22_1.ipynb @@ -0,0 +1,832 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 22 : Industrial Application" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.4 Page no 298" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.4 page no 298\n", + "\n", + "\n", + "\n", + " velocity v=113.49 ft/s\n", + "\n", + " circumference c=3.78 ft/rotation\n", + "\n", + " diameter D=1.20 ft\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.4 page no 298\\n\\n\"\n", + "#a centrifugal pump operating at 1800 rpm ,we have to find the impeller diameter needed to develop a head of 200 ft\n", + "h=200#height,ft\n", + "g=32.2#gravitational acc. ft/s**2\n", + "v=sqrt(2*g*h)#velocity needed to develop a head of 200 ft\n", + "print \"\\n velocity v=%.2f ft/s\"%(v)#\n", + "N=1800#pump operating at this rotational speed,in rpm\n", + "c=v*60/N#the number of feet that the impeller travels in one rotations\n", + "#this c represents the circumference of the impeller since it is equal to one rotation \n", + "print \"\\n circumference c=%.2f ft/rotation\"%(c)#\n", + "D=c/pi#diameter of the impeller\n", + "print \"\\n diameter D=%.2f ft\"%(D)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.5 Page no 299" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.5 page no 299\n", + "\n", + "\n", + "\n", + " reynolds no R_e=169425.74 \n", + "\n", + " h_f frictional loss=10.86 J \n", + "\n", + " e_l total elbow loss=2.56 J/kg\n", + "\n", + " potential energy PE=215.82 J/kg\n", + "\n", + " total energy TE=229.24 J/kg\n", + "\n", + " theoritical power W_dot_s=4575.71 J/s\n", + "\n", + " equivalent head h=23.37 m \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.5 page no 299\\n\\n\"\n", + "#water for a processing plant is required to be stored in a reservoir\n", + "#assume the properties of water at 20 deg C are\n", + "rho=998#density,kg/m**3\n", + "meu=0.001#viscosity,N.s/m**2\n", + "L=120#length of pipe,m\n", + "D=0.15#diameter of pipe,m\n", + "S=(pi/4)*D**2#cross sectional area of pipe\n", + "#given:\n", + "q=1.2/60#volumetric flow rate,m**3/s\n", + "v=q/S#flow velocity,m/s\n", + "R_e=D*v*rho/meu#reynolds no\n", + "print \"\\n reynolds no R_e=%.2f \"%(R_e)#\n", + "#from value of R_e ,flow is clearly turbulent\n", + "k=0.0005#roughness factor for galvanized iron\n", + "K_r=k/D#relative roughness\n", + "f=0.0053#fricion factor from fig. 14.2\n", + "h_f=4*f*(L/D)*(v**2/2)#friction loss of energy\n", + "print \"\\n h_f frictional loss=%.2f J \"%(h_f)#\n", + "#for right elbows (from table 18.1),the estimated value of resistance coff. K for one regular 90 deg elbows is 0.5\n", + "K=4#resstance coeff.\n", + "V_h=v**2/2#velociy head\n", + "e_l=K*V_h#the total loss from the elbows\n", + "print \"\\n e_l total elbow loss=%.2f J/kg\"%(e_l)#\n", + "#the energy to move 1 kg of water against a head of 22m of water is\n", + "z=22#height,m\n", + "g=9.81#grav. acc,m/s**2\n", + "PE=z*g\n", + "print \"\\n potential energy PE=%.2f J/kg\"%(PE)#\n", + "TE = h_f + e_l + PE#total requirement per kg\n", + "print \"\\n total energy TE=%.2f J/kg\"%(TE)#\n", + "W_dot_s= TE*q*rho#theoretical power requirement \n", + "print \"\\n theoritical power W_dot_s=%.2f J/s\"%(W_dot_s)# \n", + "h=TE/g#head equivalent to the energy requirement \n", + "print \"\\n equivalent head h=%.2f m \"%(h)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.6 Page no 301" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.6 page no 301\n", + "\n", + "\n", + "\n", + " reynolds no =8.91e+02 \n", + "\n", + " gauge reading h=0.17 ft \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 22.6 page no 301\\n\\n\"\n", + "#oil is flowing through a standard 3/2 inch steel pipe containing a 1 inch square edged orifice\n", + "v_gal=400#orifice velocity of oil in gal/hr\n", + "v_o=400*144/(0.785*3600*7.48)#orifice velocity in ft/hr\n", + "D_o=1/12#diameter of orifice\n", + "rho=0.87*62.4#density of oil\n", + "meu=20.6*0.000672#viscosity of oil\n", + "R_e=D_o*v_o*rho/meu\n", + "print \"\\n reynolds no =%.2e \"%(R_e)#\n", + "D_r=0.62#ratio of orifice plate to pipe diametersD_o/D1 = 1/1.61\n", + "C_d=0.76#discharge coeff. fro fig 19.8\n", + "g=32.2#grav. acc. ft/s**2\n", + "h=(v_o**2/(2*g*(C_d)**2))*(1-D_r**4)#height of oil in gauge reading\n", + "print \"\\n gauge reading h=%.2f ft \"%(h)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.7 Page no 302" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.7 page no 302\n", + "\n", + " \n", + "\n", + " orifice veloctiy v_o=60.76 ft/s\n", + "\n", + " R_e_o reynolds no =92475.80 \n", + "\n", + " mass flow rate m_dot=403.00 lb/hr\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.7 page no 302\\n\\n \"\n", + "#natural gas consisting of essentially pure methane flows through a long straight standard 10 inch steel pipe into which is inserted a square edged orifice 2.50 inches in diameter ,with pressure taps ,each 5 inch from the orifice plate\n", + "#manometer is attached across the orifice reads 1.60 in H20\n", + "D_o=2.50#diameter of orifice\n", + "D_1=10.15#diameter of plate\n", + "D_r=D_o/D_1#ratio of diameters\n", + "#assuming the reynolds no R_e in the orifice to be over 30,000\n", + "C_o=0.61#coeff. of discharge from R_e value\n", + "g=32.2#garv. acc ft/s**2\n", + "rho_m=62.4#density of medium (water)\n", + "rho=0.054#density of methane gas,lb/ft**3\n", + "h=1.60#manometer reading height,in\n", + "meu=12*0.011*0.000672#viscosity \n", + "v_o= C_o*sqrt((2*g*h*rho_m)/(12*rho))# orifice velocity\n", + "print \"\\n orifice veloctiy v_o=%.2f ft/s\"%(v_o)#\n", + "R_e_o=D_o*v_o*rho/meu#reynolds no in the orifice\n", + "print \"\\n R_e_o reynolds no =%.2f \"%(R_e_o)#\n", + "#from R_e_o value C_o=0.61 is permissible\n", + "m_dot=round(v_o*(pi/4)*(D_o**2)*rho*(3600/144))#mass flow rate \n", + "print \"\\n mass flow rate m_dot=%.2f lb/hr\"%(m_dot)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.8 Page no 303" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.8 page no 303\n", + "\n", + "\n", + "\n", + " vol.flow rate q=0.09 m**3/s\n", + "\n", + " mach no. M_a =0.10 \n", + "\n", + " pressure at point 2=129436.49 Pa\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.8 page no 303\\n\\n\"\n", + "#refer to fig 22.1\n", + "D1=.1#upstream diameter(at station 1),m\n", + "D2=.06#downstream diameter(station 2),m\n", + "S2=(pi/4)*D2**2#cross sectional area at point 2\n", + "rho=1.22#density of air from ideal gas law\n", + "rho_m=827#density of medium,kg.m**3\n", + "g=9.8#gravitational acc.\n", + "h=0.08#manometer head,m\n", + "#from bernoulli equation\n", + "v2=sqrt(2*g*h*((rho_m/rho)-1))#velocity at point 2\n", + "v1=v2*(D2/D1)**2#velocity at point 1\n", + "q=v2*S2#volumatric flow rate\n", + "print \"\\n vol.flow rate q=%.2f m**3/s\"%(q)#\n", + "#calculation of mach number from equation 15.1\n", + "T=293#temperature in k\n", + "c=20*sqrt(T)#speed of light at this temperature,m/s\n", + "M_a=v2/c#mach no.\n", + "print \"\\n mach no. M_a =%.2f \"%(M_a)#\n", + "#noting that M_a=0.095 < 0.3 , we can conclude that flow is incompressible#given \n", + "P1=130000 #absolute pressure at point 1,pa\n", + "#by using bernoulli eq for P2\n", + "P2=P1-rho*v2**2*(1-(D2/D1)**4)/2#pressure at point 2\n", + "print \"\\n pressure at point 2=%.2f Pa\"%(P2)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.9 Page no 305 " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 22.9 page no 305\n", + "\n", + "\n", + "\n", + " h_s =305.56 ft.lbf/lb\n", + "\n", + " frictional loss h_f=-643.25 ft.lbf/lb\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 22.9 page no 305\\n\\n\"\n", + "#water is flowing from an elevated reservoir through a conduit to a turbine at a lower level and out of the turbine through a similar conduit \n", + "#refer to fig 22.2\n", + "#since the diameter of the conduit is the same at location 1 and 2 ,kinetic energy effects can be neglected and bernoulli eq. takes the form\n", + "#P/rho + z(g/g_c) -h_s + h_f = 0\n", + "P1=30#/pressure at point 1,psia\n", + "z1=300#height of point 1,ft\n", + "P2=18#pressure at point 2,psia\n", + "z2=-10#height of point 2,ft\n", + "rho=62.4#density\n", + "m_dot=3600#mass flow rate,tons/hr\n", + "W_dot =1000#output at the shaft of turbine,hp\n", + "neta=0.9#efficiency of turbine\n", + "h_s=W_dot*550*3600/(neta*m_dot*2000)#\n", + "print \"\\n h_s =%.2f ft.lbf/lb\"%(h_s)#\n", + "#put this value in bernoulli eq.\n", + "h_f=(P2-P1)*144/rho + (z2-z1) -h_s#frictional loss\n", + "print \"\\n frictional loss h_f=%.2f ft.lbf/lb\"%(h_f)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.10 Page no 306" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 22.10 page no 306\n", + "\n", + "\n", + "\n", + " dynamic head D_h=0.92 m\n", + "\n", + " pressure at point 3 P3=78265.03 Pa\n", + "\n", + " NPSH=7.06 m\n", + "\n", + " new pressure at point 3 P3_n_ab=86273.97 Pa absolute\n", + "\n", + " height z3=0.85 m\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"\\n Example 22.10 page no 306\\n\\n\"\n", + "#benzene is pumped from a large tank to a delivery station \n", + "#refer fig 22.3\n", + "q=0.003#vol. flow rate,m**3/s\n", + "#tank is at atmosphric pressure\n", + "D=0.03#diameter of suction and discharge line,m\n", + "v_2=q/((pi/4)*D**2)#discharge velocity,m/s\n", + "#since all diameters are same likewise velocities are same\n", + "v_3=v_2\n", + "g=9.807#grav. acc.\n", + "D_h=(v_3**2)/(2*g)#dynamic head\n", + "print \"\\n dynamic head D_h=%.2f m\"%(D_h)#\n", + "z1=0#height at point 1,tank level\n", + "z2=1.8#height at point 3\n", + "#applying bernoulli's eq. between the top of the tank(open to theatomsphere)and the inlet to the pump(station3)\n", + "rho=865#density of benzene,kg/m**3\n", + "P3=101325-(z2+D_h)*(rho*g)#ptressure at point 3\n", + "print \"\\n pressure at point 3 P3=%.2f Pa\"%(P3)#\n", + "P_v=26200#vapor pressure of benzene,Pa\n", + "NPSH = (P3 - P_v)/(rho*g) + D_h\n", + "print \"\\n NPSH=%.2f m\"%(NPSH)\n", + "#the manufacturer NPSH is 8 m, which is greater than the calculated NPSH of 7.06m,therfore, the suction point of pump must be lowered \n", + "#calculation of new pressure\n", + "NPSH_m=8#NPSH by manufacturer\n", + "P3_n_ab=8*(rho*g)-D_h*(rho*g) + P_v\n", + "print \"\\n new pressure at point 3 P3_n_ab=%.2f Pa absolute\"%(P3_n_ab)#\n", + "P3_n_bz=-1.77#pressure in terms of benzene height,m\n", + "z3=-P3_n_bz -D_h#desired height of point 3\n", + "print \"\\n height z3=%.2f m\"%(z3)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.11 Page no 308" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.11 page no 308\n", + "\n", + "\n", + "\n", + " reynolds no. R_e=427481.50\n", + "\n", + " frictional loss h_fp=109.93 ft.lbf/lb\n", + "\n", + " total frictional loss h_f_total=128.27 ft.lbf/lb\n", + "\n", + " W_dot_s=85.35 hp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.11 page no 308\\n\\n\"\n", + "#a storage tank on top of a building pumps 60 deg F water through an open pipe to it from a reservoir \n", + "q=1.36#vol. flow rate ,ft**3/s\n", + "D=0.333#diameter of pipe,ft\n", + "S=pi/4*D**2#cross sectional area,ft**2\n", + "v2=q/S#flow velocity,ft/s\n", + "rho=62.37#density of water,lb/ft**3\n", + "meu=1.129*6.72e-4#viscosity of water\n", + "R_e=D*v2*rho/meu#reynolds no.\n", + "print \"\\n reynolds no. R_e=%.2f\"%(R_e )#\n", + "#from R_e we can conclude that flow is turbulent\n", + "k=0.0018#roughness factor\n", + "K_r=k/D#relative roughness\n", + "f=0.0046#friction factor\n", + "L=525#length of pipe,ft\n", + "g_c=32.174#grav. acc\n", + "h_fp=(4*f*L*v2**2)/(D*2*g_c)#frictional loss due to the length of pipe\n", + "print \"\\n frictional loss h_fp=%.2f ft.lbf/lb\"%(h_fp)#\n", + "#friction due to the fitings from table 18.1\n", + "K_ff_gate=2*0.11#loss coeff. due to gates\n", + "K_ff_elbows=5*0.64#loss coeff. due to elbows\n", + "#friction due to the sudden contraction is obtained from eq. 18.10 .\n", + "#note that D1/D2=0,since the upstream diameter is singnificantly larger than the downward diameter \n", + "K_c=0.42#coeff. of sudden contraction\n", + "K_e=1#coeff. of sudden expansion\n", + "K_s=K_ff_gate +K_ff_elbows +K_e +K_c#sum of loss coeff.\n", + "h_f=K_s*v2**2/(2*g_c)#friction losses due to fitting,expansion,contraction\n", + "h_f_total=h_fp + h_f#total frictional losses\n", + "print \"\\n total frictional loss h_f_total=%.2f ft.lbf/lb\"%(h_f_total)#\n", + "v1=0\n", + "P_drop=0#pressure drop\n", + "z1=0#reservoir water level\n", + "z2=200#height of reservoir\n", + "W_s=(v2**2-v1**2)/(2*g_c) + (z2-z1) + h_f_total#power requirement\n", + "m_dot=q*rho#mass flow rate,lb/s\n", + "neta=0.6#efficiency of pump\n", + "W_dot_s=m_dot*W_s/(550*neta)#actual horsepower requirement\n", + "print \"\\n W_dot_s=%.2f hp\"%(W_dot_s)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.12 Page no 311" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.12 page no 311\n", + "\n", + "\n", + "\n", + " frictional loss h_f =224.91 ft.lbf/lb\n", + "\n", + " q=0.34 ft**3/s \n", + "\n", + " brake horse power bhp=18.11 hp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.12 page no 311\\n\\n\"\n", + "#turpentine is being moved from a large storage tank to a blender through a 700 ft pipeline\n", + "rho=62.4#density\n", + "SG=0.872#specific gravity of terpentine\n", + "rho_t=SG*rho#density of turpentine\n", + "v=12.67#av. velocity of the turpentine in the line,ft/s\n", + "z1=20#height of top surface in the storage tank above floor level,ft\n", + "z2=90#height of discharge end of pipe,ft\n", + "neta=0.74#efficiency of pump\n", + "W_s=401.9#average energy delivered by pump,ft/lbf/lb\n", + "g_c=32.174#grav.acc\n", + "L=700#length of pipeline\n", + "#from bernoulli eq.\n", + "h_f= neta*W_s - v**2/(2*g_c) - (z2-z1)#frictional loss if there is no pressure drop\n", + "print \"\\n frictional loss h_f =%.2f ft.lbf/lb\"%(h_f)# \n", + "k_c=0.4#coeff. of contraction\n", + "k_e=0.9#coeff. of expansion\n", + "k_f=0.2#coeff. of bends and valve\n", + "#making equation(1) from the friction coeff. due to fittings between f and D,f=0.0293*D \n", + "#making another equation(2) from Reynolds number in terms D ,R_e=582250*D\n", + "#from trial and error method we get D\n", + "D=0.184#diameter\n", + "S=pi*D**2/4#cross sectional area\n", + "S=0.0266\n", + "q=v*S#volumetric flow rate \n", + "print \"\\n q=%.2f ft**3/s \"%(q)#\n", + "m_dot=rho_t*q#mass flow rate\n", + "bhp =m_dot*W_s/(550*neta)#brake horse power\n", + "print \"\\n brake horse power bhp=%.2f hp\"%(bhp)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.13 Page no 313" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.13 page no 313\n", + "\n", + "\n", + "\n", + " R_e reynolds no=589.08 \n", + "\n", + " Pressure gradient P_grad=0.00 Pa/m\n", + "\n", + " fanning friction factor f=0.03 \n", + "\n", + " darcy friction factor f_d=0.11 \n", + "\n", + " friction loss h_f=0.04 m\n", + "\n", + " friction power loss W_f=0.00 W\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.13 page no 313\\n\\n\"\n", + "#hydrogen flows through a horizontal pipe\n", + "#properties of hydrogen at 20 deg C from table A.3 in the appendix\n", + "rho=0.0838#density of hydrogen,kg/m**3\n", + "meu=9.05e-6#viscosity,kg/m.s\n", + "D=0.08#diameter of pipe,m\n", + "L=1#unit length of pipe,m\n", + "q=0.0004#vol. flow rate ,m**3/s\n", + "S=.000503#cross sectional area\n", + "v=q/S#flow velocity,m/s\n", + "m_dot=rho*q#mass flow rate,kg/s\n", + "R_e=(D*v*rho/meu)#reynolds no.\n", + "print \"\\n R_e reynolds no=%.2f \"%(R_e)#\n", + "#since R_e is 593<2100, flow is laminar\n", + "#since the tube is horizontal z1=z2,calculation of pressure gradient(P/L)\n", + "P_grad= 128*meu*q/(pi*D**4)#pressure gradient\n", + "print \"\\n Pressure gradient P_grad=%.2f Pa/m\"%(P_grad)\n", + "v_max=2*v#m/s\n", + "#calculation of fanning friction factor\n", + "#since the flow is laminar \n", + "f=16/R_e#fanning friction factor\n", + "print \"\\n fanning friction factor f=%.2f \"%(f)#\n", + "f_d=4*f#darcy friction factor\n", + "print \"\\n darcy friction factor f_d=%.2f \"%(f_d)#\n", + "g=9.807#grav. acc.\n", + "h_f=f_d*(L/D)*(v**2/(2*g))#friction loss\n", + "print \"\\n friction loss h_f=%.2f m\"%(h_f)#\n", + "W_f = m_dot*g*h_f#friction power loss\n", + "print \"\\n friction power loss W_f=%.2f W\"%(W_f)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.14 Page no 315" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 22.14 page no 315\n", + "\n", + "\n", + "\n", + " reynolds no R_e=4447617.59 \n", + "\n", + " ideal shaft work W_s_id=29304.00 W \n", + "\n", + " actual shaft work W_s_ac=36630.00 W\n", + "\n", + " f_inc=133.33 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 22.14 page no 315\\n\\n\"\n", + "#gasoline is pump through a horizontal cast iron pipe\n", + "L=30#length of pipe\n", + "D=0.2#diameter of pipe,m\n", + "S=(pi/4)*D**2#cross sectional area\n", + "q=0.3#vol. flow rate ,m**3/s\n", + "v=q/S#flow velocity,m/s\n", + "rho=680#density of gasoline,kg/m**3\n", + "meu=2.92e-4#viscosity of gasoline,kg/m.s\n", + "R_e=D*v*rho/meu#reynolds no.\n", + "print \"\\n reynolds no R_e=%.2f \"%(R_e)#\n", + "#since R_e is >4000 flow is turbulent\n", + "k=0.00026#roughness factor from table 14.1 for cast iron,m\n", + "K_r=k/D#relative roughness\n", + "f=0.00525#fanning friction factor from fig 14.2\n", + "#Note that the flow corresponds to complete turbulence in the rough pipe\n", + "g=9.807#gravitational acceleration\n", + "#h_f=4*f*(L/D)*(v**2/(2*g))#head loss\n", + "h_f=14.647\n", + "#applying bernoulli equation to the fluid in the pipe\n", + "#in this case the pipe is horizontal (z1=z2) with constant diameter (v1=v2) and no shaft head (h_s=0)\n", + "#first convert the friction head to a pressure difference\n", + "P_diff=rho*g*h_f#pressure difference \n", + "P_diff= 97.68*10**3#after round off\n", + "W_s_id=q*P_diff#ideal shaft work\n", + "print \"\\n ideal shaft work W_s_id=%.2f W \"%(W_s_id)#\n", + "neta=0.8#efficiency of pump\n", + "W_s_ac=W_s_id/neta#actual shaft work \n", + "print \"\\n actual shaft work W_s_ac=%.2f W\"%(W_s_ac)#\n", + "f_s=0.009#friction factor smooth\n", + "f_r=0.021#friction factor roughnes\n", + "k=f_r/f_s\n", + "f_inc=100*(k-1)#percentage increment in f due to roughness \n", + "print \"\\n f_inc=%.2f \"%(f_inc)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.15 Page no 316" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 22.15 page no 316\n", + "\n", + "\n", + "\n", + " flow velocity v=0.06 m/s\n", + "\n", + " reynolds no R_e=156991.90 \n", + "\n", + " pressure drop P_drop=1.35 Pa\n", + "\n", + " friction power loss W_dot_f=0.34 W\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"\\n Example 22.15 page no 316\\n\\n\"\n", + "#liquid benzene flows through a smooth horizontal iron pipe \n", + "D=2.3#diameter of pipe,m\n", + "L=146.304#length of pipe,m\n", + "S=(pi/4)*D**2#cross sectional area,m**2\n", + "q=4000#vol. flow rate,gal/min\n", + "v=q/(S*264.17*60)#flow velocity\n", + "print \"\\n flow velocity v=%.2f m/s\"%(v)#\n", + "rho=899#density of benzene\n", + "meu=0.0008#viscosity of benzene,kg/m.s\n", + "R_e = D*v*rho/meu#reynolds no\n", + "print \"\\n reynolds no R_e=%.2f \"%(R_e)#\n", + "#since the reynolds number falls in the turbulent regime,determine the fanning friction factor from fig. 14.2\n", + "f=0.0032#fanning friction factor\n", + "# calculation of pressure drop with the assumption of no height and velocity change , and no pump work \n", + "#since only frictional losses are to be considered\n", + "#applying eq. 14.3\n", + "P_drop = 4*f*(L/D)*(v**2/2)*rho#pressure drop\n", + "print \"\\n pressure drop P_drop=%.2f Pa\"%(P_drop)#\n", + "W_dot_f=q*P_drop/(264.17*60)#friction power loss\n", + "print \"\\n friction power loss W_dot_f=%.2f W\"%(W_dot_f)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 22.16 Page no 317" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 22.16 page no 317\n", + "\n", + "\n", + "\n", + " work extracted from the system W_s=563.54 Btu/lb \n", + "\n", + " W_dot_s =253592134.06 Btu/h\n", + "\n", + " power generated W_hp=99585.63 hp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"\\n Example 22.16 page no 317\\n\\n\"\n", + "#a power plant employs steam to generate power \n", + "#adiabatic conditions\n", + "z1=0#steam vertical position at inlet,ft\n", + "z2=-20#steam vertical position at outlet,ft\n", + "v1=120#steam velocity at inlet,ft/s\n", + "v2=330#steam velocity at outlet,ft/s\n", + "H1=1505.4#steam enthalpy at inlet \n", + "H2=940#steam enthalpy at outlet\n", + "Q=0#for adiabatic conditions\n", + "g_c=32.174#grav .acc\n", + "#applying energy equation\n", + "W_s=-(z2/778) - v2**2/(2*g_c*778) - H2 +z1 + v1**2/(2*g_c*778) + H1#work extracted from system\n", + "print \"\\n work extracted from the system W_s=%.2f Btu/lb \"%(W_s)#\n", + "m_dot=450000#mass flow rate ,lb/h\n", + "W_dot_s=m_dot*W_s#total power generated by the turbine \n", + "print \"\\n W_dot_s =%.2f Btu/h\"%(W_dot_s)##approx calculation in book \n", + "W_hp=W_dot_s*3.927e-4#power generated in horsepower hp\n", + "print \"\\n power generated W_hp=%.2f hp\"%(W_hp)##approx calculation in book" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-23_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-23_1.ipynb new file mode 100644 index 00000000..cff8faca --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-23_1.ipynb @@ -0,0 +1,516 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 23 : Particle Dynamics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.1 Page no 323" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 23.1 Page no 323\n", + "\n", + "\n", + "\n", + " d_pa1=1.98 micron\n", + "d_pa2=2.00 micron\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "from __future__ import division\n", + "print \"Example 23.1 Page no 323\\n\\n\"\n", + "#calculation of aerodynamic diameter for the following particles\n", + "d_es=1.4#equivalent dia of solid sphere,micrometer\n", + "sg_s=2#specific gravity of solid sphere\n", + "d_eh=2.8#equivalent diameter of hollow sphere, mirometer\n", + "sg_h=0.51#specific gravity of hollow sphere\n", + "d_pa1=d_es*sqrt(sg_s)#aerodynamic dia for solid sphere\n", + "d_pa2=round(d_eh*sqrt(sg_h))#aerodynamic dia for hollow sphere\n", + "print \"\\n d_pa1=%0.2f micron\\nd_pa2=%0.2f micron\"%(d_pa1,d_pa2)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.2 Page no 323 " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 23.2 Page no 323\n", + "\n", + "\n", + "\n", + " aerodynamic diameter d_pa=1.99 micron\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "from __future__ import division\n", + "print \"Example 23.2 Page no 323\\n\\n\"\n", + "#calculation of aerodynamic diameter of irregular saped sphere\n", + "d_e=1.3#eq. diameter,micron\n", + "sg=2.35\n", + "d_pa=d_e*sqrt(sg)#aerodynamic diameter\n", + "print \"\\n aerodynamic diameter d_pa=%0.2f micron\"%(d_pa)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.3 Page no 335" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 23.3 Page no 335\n", + "\n", + "\n", + "CCF C=1.41 \n" + ] + } + ], + "source": [ + "from math import exp\n", + "from __future__ import division\n", + "print \"Example 23.3 Page no 335\\n\\n\"\n", + "#calculation of cunningham correction factor \n", + "dp=0.4#particle diameter\n", + "lemda=6.53e-2\n", + "A=1.257 + 0.40*exp(-1.10*dp/(2*lemda))\n", + "C= 1 + 2*A*lemda/dp#cunningham correction factor(CCF)\n", + "print \"CCF C=%0.2f \"%(C)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.4 Page no 336" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 23.4 Page no 336\n", + "\n", + "\n", + "\n", + " dimensionless constant K1=0.01 \n", + " K2=1.44 \n", + " K3=14.42 \n", + "\n", + " terminal settling velocity for particle 1 v1=0.00 ft/s\n", + "\n", + " terminal settling velocity v2=0.31 ft/s\n", + "\n", + " terminal settling velocity v3=8.90 ft/s \n", + "\n", + " distance by 2 particle x2=9.44 ft\n", + " distance by 3 particle x3=266.88 ft\n", + "\n", + " distance travel by 1 particle x1=0.00 ft\n" + ] + } + ], + "source": [ + "from math import exp\n", + "from __future__ import division\n", + "print \"Example 23.4 Page no 336\\n\\n\"\n", + "#three different diameter sized fly ash particls settle through air \n", + "#we have to calculate the particle terminal velocity and determine how far each will fall in 30 seconds \n", + "#assume the particles are speherical \n", + "SG=2.31#specific gravity of fly ash\n", + "rho_w=62.4#density of water \n", + "rho_p=SG*rho_w#density of particles\n", + "#properties of air\n", + "R=0.7302#gas constant\n", + "T=698#temperature,R\n", + "P=1#pressure ,atm\n", + "Mw=29#mol. wt of air\n", + "rho_a=P*Mw/(R*T)#density of air,lb/ft**3\n", + "meu=1.41e-5#viscosity of air,lb/ft.s\n", + "g=32.174#grav. acc\n", + "D1=0.4#diameter of particle 1,microns\n", + "D2=40#diameter of particle 2,microns\n", + "D3=400#diameter of particle 3,microns\n", + "K1=(D1/(25400*12))*(g*rho_p*rho_a/(meu**2))**(1/3)#dimensionless constant for particle 1\n", + "K2=(D2/(25400*12))*(g*rho_p*rho_a/(meu**2))**(1/3)#dimensionless constant for particle 2\n", + "K3=(D3/(25400*12))*(g*rho_p*rho_a/(meu**2))**(1/3)#dimensionless constant for particle 3\n", + "print \"\\n dimensionless constant K1=%0.2f \\n K2=%0.2f \\n K3=%0.2f \"%(K1,K2,K3)#\n", + "#first we determine which fluid particle dynamic law applies for the above values of K\n", + "#for particle 1,strokes law applies\n", + "#for particle 2,strokes law applies\n", + "#for particle 3,intermediate law applies\n", + "#terminal settling velocity for each particle\n", + "v1=(D1/(25400*12))**2*g*rho_p/(18*meu)\n", + "print \"\\n terminal settling velocity for particle 1 v1=%0.2f ft/s\"%(v1)#\n", + "v2=(D2/(25400*12))**2*g*rho_p/(18*meu)\n", + "print \"\\n terminal settling velocity v2=%0.2f ft/s\"%(v2)#\n", + "v3=(D3/(25400*12))**1.14*0.153*g**0.71*rho_p**0.71/(rho_a**0.29*meu**0.43)\n", + "print \"\\n terminal settling velocity v3=%0.2f ft/s \"%(v3)#\n", + "#calculation of how far x,the fly ash particles will fall in 30 seconds\n", + "t=30#time,sec\n", + "x2=v2*t#distance travel by 2 particle\n", + "x3=v3*t#distance travel by 3 particle\n", + "print \"\\n distance by 2 particle x2=%0.2f ft\\n distance by 3 particle x3=%0.2f ft\"%(x2,x3)#\n", + "#for 1 particle K1 and v1 value are without the CCF.With the correction factor lemda=6.53e-8,gives\n", + "lemda=6.53e-8#correction factor\n", + "y=-1.10*(D1/(25400*12))/(2*lemda)\n", + "A =1.257 + 0.40*exp(y)\n", + "C=1 + 2*A*lemda/(D1/(25400*12))#cunningham correction factor(ccf)\n", + "#now equation 23.36 can be employed \n", + "v1_corrected=v1*C#corrected velocity of 1 particle\n", + "x1=v1_corrected*t#distance travel by 1 particle\n", + "print \"\\n distance travel by 1 particle x1=%0.2f ft\"%(x1)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.5 Page no 338" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 23.5 Page no 338\n", + "\n", + "\n", + "\n", + " dimensionless constant W=0.13 \n", + "\n", + " diameter of particle D_p=2.75e-04 ft\n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "from __future__ import division\n", + "print \"\\n Example 23.5 Page no 338\\n\\n\"\n", + "#refer to example 23.5\n", + "#we have to calculate size of a flyash particle that will settle with a velocity of 1.384 ft/s\n", + "SG=2.31#specific gravity of fly ash\n", + "rho_w=62.4#density of water \n", + "rho_p=SG*rho_w#density of particles\n", + "#properties of air\n", + "R=0.7302#gas constant\n", + "T=698#temperature,R\n", + "P=1#pressure ,atm\n", + "Mw=29#mol. wt of air\n", + "rho_a=P*Mw/(R*T)#density of air,lb/ft**3\n", + "meu=1.41e-5#viscosity of air,lb/ft.s\n", + "g=32.174#grav. acc\n", + "v=1.384#velocity at which particle settle down,ft/s\n", + "W= v**3*rho_a**2/(g*rho_p*meu)#dimensionless constant\n", + "print \"\\n dimensionless constant W=%0.2f \"%(W)#\n", + "#since W < 0.2222 stokes' law applies\n", + "D_p=sqrt(18*meu*v/(g*rho_p))#diameter of particle\n", + "print \"\\n diameter of particle D_p=%0.2e ft\"%(D_p)#\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.7 Page no 340" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 23.7 Page no 340\n", + "\n", + "\n", + "\n", + " dimensionless constant K_l=2.73e+02 \n", + "\n", + " settling velocity v_l=11.85 ft/s\n", + "\n", + " descent time t_l=33.74 second\n", + " horizontal distance L=989.79 ft\n", + "\n", + " dimensionless constant K_s=6.57e-02 \n", + "\n", + " settling velocity v_s=3.59e-04 ft/s\n", + "\n", + " descent time t_s=1114285.36 s\n", + "horizontal distance travelled by smallest particle L_s=3.27e+07 ft\n", + "\n", + " actual volume V_act=4006.41 ft**3\n", + "bulk volume V_b=8012.82 \n", + "\n", + " L_d=3.27e+07 \n", + "\n", + " deposition height H_d=2.45e-06 ft\n" + ] + } + ], + "source": [ + "from math import exp\n", + "from __future__ import division\n", + "print \"\\n Example 23.7 Page no 340\\n\\n\"\n", + "# In a plant manufacturing ivory soap detergent explodes one windy day\n", + "#we have to calculate the distance from the plant where the soap particles will start to deposit and where they will cease to deposit\n", + "#the smallest particle wll travel the greatest distance while the largest will travel the least distance \n", + "#for the minimumdistance ,we use largest particle \n", + "D_l=3.28e-3#largest diameter,ft\n", + "g=32.174#grav. acc.\n", + "SG=0.8#specific gravity of soap particle\n", + "rho_w=62.4\n", + "rho_p=SG*rho_w#density of particle\n", + "rho_a=0.0752#density of given atmosphere,lb/ft**3\n", + "meu=1.18e-5#viscosity \n", + "K_l = D_l*(g*(rho_p-rho_a)*rho_p/(meu**2))**(1/3)#dimensionless constant\n", + "print \"\\n dimensionless constant K_l=%0.2e \"%(K_l)#\n", + "#value of K indicates the intermediate range applies \n", + "#the settling velocity is given by \n", + "v_l=0.153*g**0.71*D_l**1.14*rho_p**0.71/(meu**0.43*rho_a**0.29)\n", + "print \"\\n settling velocity v_l=%0.2f ft/s\"%(v_l)#\n", + "H=400#vertical height blowen by particle,ft\n", + "t_l=H/v_l#descent time\n", + "v_w=20#wind velocity in miles/h\n", + "L=t_l*v_w*(5280/3600)#horizontal distance travelled by particles\n", + "print \"\\n descent time t_l=%0.2f second\\n horizontal distance L=%0.2f ft\"%(t_l,L)#\n", + "#for the minimum distance we use smallest particle\n", + "D_s=6.89e-6#diameter of smallest particle,ft\n", + "K_s=D_s*(g*(rho_p-rho_a)*rho_a/(meu**2))**(1/3)\n", + "print \"\\n dimensionless constant K_s=%0.2e \"%(K_s)#\n", + "#velocity is in the stokes regime and is given by\n", + "v_s=g*D_s**2*rho_p/(18*meu)\n", + "print \"\\n settling velocity v_s=%0.2e ft/s\"%(v_s)#\n", + "t_s=H/v_s#descent time \n", + "L_s=t_s*v_w*(5280/3600)#horizontal distance travelled \n", + "print \"\\n descent time t_s=%0.2f s\\nhorizontal distance travelled by smallest particle L_s=%0.2e ft\"%(t_s,L_s)#\n", + "m=100*2000#mass of particles\n", + "V_act=m/rho_p#actual volume of particles\n", + "e=0.5#void fraction\n", + "V_b=V_act/e#bulk volume\n", + "print \"\\n actual volume V_act=%0.2f ft**3\\nbulk volume V_b=%0.2f \"%(V_act,V_b)#\n", + "L_d=L_s-L#length of drop area\n", + "print \"\\n L_d=%0.2e \"%(L_d)#\n", + "W=100#width ,ft\n", + "A_d=L_d*W#deposition area\n", + "H_d=V_b/A_d#deposition height\n", + "print \"\\n deposition height H_d=%0.2e ft\"%(H_d)#\n", + "#deposition height can be ,at bestt, described asa sprinkling " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.8 Page no 342" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 23.8 Page no 342\n", + "\n", + "\n", + "\n", + " density of particle rho_p=2897.19 kg/m**3\n", + "\n", + " reynolds no R_e=0.27 \n", + "\n", + " K=1.70 \n", + "\n", + " drag coeff C_d=88.38 \n", + "\n", + " drag force F_d=0.00 N\n", + "\n", + " buoyancy force F_b=0.00 N\n", + "\n", + " k_w settling factor =158.99 \n", + "\n", + " terminal velocity in water v_t_w=0.58 m/s\n" + ] + } + ], + "source": [ + "from math import pi,sqrt\n", + "from __future__ import division\n", + "print \"Example 23.8 Page no 342\\n\\n\"\n", + "#a small sphere is observed to fall through caster oil \n", + "v_t=0.042#terminal velocity of particle \n", + "meu_f=0.9#viscosity of oil\n", + "rho_f=970#density of oil\n", + "g=9.807#grav. acc.\n", + "D_p=0.006#diameter of particle\n", + "rho_p=(18*meu_f*v_t)/(g*D_p**2) + rho_f\n", + "print \"\\n density of particle rho_p=%0.2f kg/m**3\"%(rho_p)#\n", + "neu_f=9.28e-4#dynamic viscosity of fluid\n", + "R_e=D_p*v_t/neu_f#reynolds no\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#\n", + "#since R_e < 0.3\n", + "#calculation of the settling criterion factor ,K\n", + "K=D_p*(g*rho_f*(rho_p-rho_f)/(meu_f**2))**(1/3)#the settling criterion factor\n", + "print \"\\n K=%0.2f \"%(K)#\n", + "#since K <3.3, stokes law applies \n", + "#the drag coeff. C_d \n", + "C_d=24/R_e\n", + "print \"\\n drag coeff C_d=%0.2f \"%(C_d)#\n", + "F_d=3*pi*meu_f*D_p*v_t#drag force\n", + "print \"\\n drag force F_d=%0.2f N\"%(F_d)#\n", + "F_b=(pi/6)*D_p**3*rho_f*g#buoyancy force \n", + "print \"\\n buoyancy force F_b=%0.2f N\"%(F_b)#\n", + "#Consider the case when same sphere is dropped in water \n", + "rho_w=1000#density of water,kg/m**3\n", + "meu_w=0.001#viscosity of water,kg/m.s\n", + "#the particle will move faster because of the lower viscosity of water ,stokes law will almost definietly not apply\n", + "K_w=D_p*(g*rho_w*(rho_p-rho_w)/(meu_w**2))**(1/3)#the settling criterion factor\n", + "print \"\\n k_w settling factor =%0.2f \"%(K_w)#\n", + "#since K_w = 158 > 43.6,the flow is in the Newton's law regime \n", + "#employ eq. 23.31 but include the (buoyant) density ratio factor\n", + "v_t_w=1.75*sqrt((rho_p-rho_w)/(rho_w)*g*D_p)#terminal velocity \n", + "print \"\\n terminal velocity in water v_t_w=%0.2f m/s\"%(v_t_w)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 23.9 Page no 344" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 23.9 Page no 344\n", + "\n", + "\n", + "Reynolds no R_e=2.40e+08 \n", + "\n", + "coeff. discharge C_d=1.97e-03 \n", + "\n", + " drag force F_d=1.42e+04 N\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 23.9 Page no 344\\n\\n\"\n", + "#the bottom of a ship,moving in water\n", + "rho=1000#density of water\n", + "v=12#velocity of boat,m/s\n", + "L=20#length,m\n", + "W=5#width ,m\n", + "meu=1e-3#viscosity\n", + "R_e=rho*v*L/meu#reynolds no\n", + "print \"Reynolds no R_e=%0.2e \"%(R_e)#\n", + "#from reynolds no flow is turbulent\n", + "C_d=0.031/(R_e**(1/7))#coeff. discharge\\\n", + "print \"\\ncoeff. discharge C_d=%0.2e \"%(C_d)#\n", + "#calculation of the drag on area LW\n", + "F_d=(1/2)*C_d*rho*v**2*L*W#drag force\n", + "print \"\\n drag force F_d=%0.2e N\"%(F_d)# " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-24_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-24_1.ipynb new file mode 100644 index 00000000..73a0da45 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-24_1.ipynb @@ -0,0 +1,568 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 24 : Sedimentation Centrifugation and Flotation" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.1 Page no 350" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.1 page no 350\n", + "\n", + "\n", + "\n", + " volume fraction fluid particles v_frac_f =0.62 \n", + "\n", + " volume fraction for the glass particles v_frac_p=0.38 \n", + "\n", + " bulk density of slurry rho_m=1553.00 kg/m**3 \n", + "\n", + " terminal velocity v_t=0.00 m/s\n", + "\n", + " effective mixture viscosity meu_m=0.00 kg/m.s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 24.1 page no 350\\n\\n\"\n", + "#glass sphere are settling in water at 20 deg C\n", + "#the slurry contains 60 wt% solids \n", + "# start by assuming a basis of 100 kg of slurry\n", + "m_f=40#mass of fluid,kg\n", + "rho_f=998#density of water,kg/m**3\n", + "V_f=m_f/rho_f#volume of the fluid,m**3\n", + "m_s=60#mass of solid,kg\n", + "rho_p=2467#density of glass,kg/m**3\n", + "V_s=m_s/rho_p#volume of glass,m**3\n", + "V = V_f + V_s#total volume,m**3\n", + "v_frac_f = V_f/V#volume fraction for the fluid particles\n", + "print \"\\n volume fraction fluid particles v_frac_f =%0.2f \"%(v_frac_f)#\n", + "v_frac_p=1-v_frac_f#volume fraction for the glass particles\n", + "print \"\\n volume fraction for the glass particles v_frac_p=%0.2f \"%(v_frac_p)#\n", + "rho_m=round(v_frac_f*rho_f + v_frac_p*rho_p)#bulk density of slurry\n", + "print \"\\n bulk density of slurry rho_m=%0.2f kg/m**3 \"%(rho_m)#\n", + "b=10**(1.82*(1-v_frac_f))#dimensionless correction factor\n", + "g=9.807#gravitational acc.,m/s**2\n", + "D_p=0.0001554#diameter of particle,m\n", + "meu_f=0.001#viscosity of fluid\n", + "v_t = g*D_p**2*(rho_p-rho_f)*v_frac_f**2/(18*meu_f*b)#terminal velocity\n", + "print \"\\n terminal velocity v_t=%0.2f m/s\"%(v_t)#\n", + "meu_m = meu_f*b#effective mixture viscosity\n", + "print \"\\n effective mixture viscosity meu_m=%0.2f kg/m.s\"%(meu_m)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.2 Page no 352" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.2 page no 352\n", + "\n", + "\n", + "\n", + " volume fraction fluid particles v_frac_f =0.62 \n", + "\n", + " volume fraction for the glass particles v_frac_p=0.38 \n", + "\n", + " bulk density of slurry rho_m=1553.00 kg/m**3 \n", + "\n", + " terminal velocity v_t=0.00 m/s\n", + "\n", + " effective mixture viscosity meu_m=0.00 kg/m.s\n", + "\n", + " reynolds no R_e=0.12 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 24.2 page no 352\\n\\n\"\n", + "#refer to example 24.1\n", + "m_f=40#mass of fluid,kg\n", + "rho_f=998#density of water,kg/m**3\n", + "V_f=m_f/rho_f#volume of the fluid,m**3\n", + "m_s=60#mass of solid,kg\n", + "rho_p=2467#density of glass,kg/m**3\n", + "V_s=m_s/rho_p#volume of glass,m**3\n", + "V = V_f + V_s#total volume,m**3\n", + "v_frac_f = V_f/V#volume fraction for the fluid particles\n", + "print \"\\n volume fraction fluid particles v_frac_f =%0.2f \"%(v_frac_f)#\n", + "v_frac_p=1-v_frac_f#volume fraction for the glass particles\n", + "print \"\\n volume fraction for the glass particles v_frac_p=%0.2f \"%(v_frac_p)#\n", + "rho_m=round(v_frac_f*rho_f + v_frac_p*rho_p)#bulk density of slurry\n", + "print \"\\n bulk density of slurry rho_m=%0.2f kg/m**3 \"%(rho_m)#\n", + "b=10**(1.82*(1-v_frac_f))#dimensionless correction factor\n", + "g=9.807#gravitational acc.,m/s**2\n", + "D_p=0.0001554#diameter of particle,m\n", + "meu_f=0.001#viscosity of fluid\n", + "v_t = g*D_p**2*(rho_p-rho_f)*v_frac_f**2/(18*meu_f*b)#terminal velocity\n", + "print \"\\n terminal velocity v_t=%0.2f m/s\"%(v_t)#\n", + "meu_m = meu_f*b#effective mixture viscosity\n", + "print \"\\n effective mixture viscosity meu_m=%0.2f kg/m.s\"%(meu_m)#\n", + "R_e=rho_m*v_t*D_p/(meu_m*v_frac_f)#reynolds no.\n", + "print \"\\n reynolds no R_e=%0.2f \"%(R_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.3 Page no 352" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.3 page no 352\n", + "\n", + "\n", + "\n", + " settling factor K1=11.26 \n", + "\n", + " particle diameter= D_p=2.18e-03 ft \n", + "\n", + " final settling factor K_n=28.30\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 24.3 page no 352\\n\\n\"\n", + "#classification of small speherical particles of charcoal with a specific gravity of 2.2\n", + "#the particles are falling in a vertical tower against a rising current of air\n", + "#we have to calculate the minimum size of charcoal that will settle down to the bottom of the tower\n", + "rho =0.075#density of air,lb/ft**3\n", + "meu=1.23e-5#viscosity of air,lb/ft.s\n", + "#assume stokes law to apply\n", + "SG=2.2#specific gravity of charcoal\n", + "rho_w=62.4#density of water \n", + "rho_p=SG*rho_w#density of charcoal\n", + "v=15#velocity of air\n", + "g=32.2#grav. acc\n", + "D_p1=(18*meu*v/(g*rho_p))**0.5\n", + "K1 = D_p1*(g*rho*rho_p/meu**2)**(1/3)#settling factor\n", + "print \"\\n settling factor K1=%0.2f \"%(K1)#\n", + "#from value of K,stokes law does not apply\n", + "#therefore,assume Intermediate range law applies\n", + "D_p =((v*rho**0.29*meu**0.43)/(0.153*(g*rho_p)**0.71))**(1/1.14)\n", + "print \"\\n particle diameter= D_p=%0.2e ft \"%(D_p)#\n", + "K_n=(D_p/D_p1)*K1\n", + "print \"\\n final settling factor K_n=%0.2f\"%(K_n)\n", + "#since the result is correct for the intermediate range" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exmple 24.4 Page no 354" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.4 page no 354\n", + "\n", + "\n", + "\n", + " G=7.00 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 24.4 page no 354\\n\\n\"\n", + "#a particle is spining in a 3 inch ID centrifuge \n", + "r=3/12#radius of centrifuge,ft\n", + "omega=30#rotational speed,rad/s\n", + "g=32.2\n", + "G=round(r*omega**2/g)\n", + "print \"\\n G=%0.2f \"%(G)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.5 Page no 357" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.5 page no 357\n", + "\n", + "\n", + "\n", + " omega =26.20 rad/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"Example 24.5 page no 357\\n\\n\"\n", + "#a circular cylinder filled with water is rotated a uniform ,steady angular speed about it's central axis in rigid body motion\n", + "#since the cylinder is full the water will spill the moment the cylinder starts to spin ,spilling occur when omega > 0 rpm\n", + "# to determine the angular speed for 1/3 of the water to spill , consider the cylinder at rest when 1/3 of the water has already beem spilled\n", + "g=32.174#grav. acc\n", + "R = 0.25 #radius of cylinder\n", + "z_st=2/3#the stationary height, ft\n", + "h = 2*(1-z_st)#increase in height is h/2,ft\n", + "omega=sqrt(4*g*(h/2)/R**2) \n", + "print \"\\n omega =%0.2f rad/s\"%(omega)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.6 Page no 392 " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.6 page no 392\n", + "\n", + "\n", + "\n", + "pressure drop P_drop=583.84 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 26.6 page no 392\\n\\n\"\n", + "#a bed of pulverized is to be fluidized with liquid oil\n", + "D=4#diameter of bed ,ft\n", + "d_p=0.00137#particle diameter ,ft \n", + "rho_s=84#coal particle density ,lb/ft**3\n", + "rho_f=55#oil density,lb/ft**3\n", + "e_mf=0.38#void fraction\n", + "L_mf=8#bed height at minimum fluidization,ft\n", + "P_drop=(rho_s-rho_f)*(1-e_mf)*L_mf +rho_f*L_mf \n", + "print \"\\npressure drop P_drop=%0.2f psf\"%(P_drop)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.7 Page no 358" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.7 page no 358\n", + "\n", + "\n", + "\n", + " pressure P_a=990.51 Pa_gauge\n", + " pressure P_b=990.51 Pa_gauge\n", + "\n", + " pressure P_c=396.20 Pa_gauge\n", + "\n", + " r=2.12cm \n", + "\n", + " thickness film t_f=0.88 m\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"Example 24.7 page no 358\\n\\n\"\n", + "#a cylindrical cup open to the atmosphere is filled with liquid to a height of 7 cm\n", + "#rotated around it's axis\n", + "#calculation of an angular velocity that will cause the liquid to start spilling \n", + "h=0.03#height,m\n", + "R=0.03#radius,cm\n", + "#applying eq. 24.22\n", + "g=9.807#grav. acc\n", + "omega=sqrt(2*h*g/(R**2))\n", + "omega=36.2#printing mistake in book\n", + "#calculation of pressure at point A and B that is P_a and P_b\n", + "z=.1#liquid height above point A and B,m\n", + "rho=1010#density of liquid,kg/m**3\n", + "P_a = rho*g*z\n", + "P_b=P_a#from symmetry P_a = P_b\n", + "print \"\\n pressure P_a=%0.2f Pa_gauge\\n pressure P_b=%0.2f Pa_gauge\"%(P_a,P_b)#\n", + "z_c=0.04#liquid height above point c,m\n", + "P_c=rho*g*z_c#pressure at point c\n", + "print \"\\n pressure P_c=%0.2f Pa_gauge\"%(P_c)#\n", + "#to obtain the film thicknes,we have to find the original height \n", + "z_l=0.07#liquid height ,m\n", + "h_o=z_l-z_c#original height\n", + "r = 100*sqrt(2*h_o*g/(omega**2))#100 for centimeter\n", + "print \"\\n r=%0.2fcm \"%(r)#\n", + "R=3\n", + "t_f=R-r#thikness of film\n", + "print \"\\n thickness film t_f=%0.2f m\"%(t_f)##printing mistake in book" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.8 Page no 360" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.7 page no 358\n", + "\n", + "\n", + "\n", + " settling factor K_q=2.28 \n", + "\n", + " settling velocity (quartz) v_q=0.01 m/s\n", + "\n", + " settling factor K_g=1.60 \n", + "\n", + " setling velocity v_g=0.01 m/s\n", + "\n", + " water velocity v_w=0.01 m/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 24.7 page no 358\\n\\n\"\n", + "#It is desired to separate quartz particles from galena particles \n", + "SG_q = 2.65#specific gravity of quartz particle \n", + "SG_g=7.5#specific gravity of galena particles \n", + "rho_f=1000#density of water \n", + "rho_q=SG_q*rho_f#density of quartz paticles\n", + "rho_g=SG_g*rho_f#density of galena particle \n", + "#calculation of the settling veloctiy of the largest quartz particle with a diameter \n", + "D_q=9e-5#diameter of largest particle of quartz\n", + "g=9.807#grav. acc\n", + "meu_f=0.001#viscosity of water\n", + "K_q = D_q*(g*(rho_q-rho_f)*rho_f/(meu_f**2))**(1/3)#settling factor\n", + "print \"\\n settling factor K_q=%0.2f \"%(K_q)#\n", + "#since K =2.27<3.3,stokes flow regime applies ,from the equation 23.36\n", + "v_q=g*D_q**2*(rho_q-rho_f)/(18*meu_f)#settling velocity of thelargest quartz particle\n", + "print \"\\n settling velocity (quartz) v_q=%0.2f m/s\"%(v_q)#\n", + "#calculation of the settling velocity of the smallest galena partilce \n", + "d_g=4e-5#diameter of smallest galena particle\n", + "K_g = d_g*(g*(rho_g-rho_f)*rho_f/(meu_f**2))**(1/3)#settling factor\n", + "print \"\\n settling factor K_g=%0.2f \"%(K_g)#\n", + "#since K = 1.6<3.3,stokes flow regime again applies\n", + "v_g=g*d_g**2*(rho_g-rho_f)/(18*meu_f)#settling velocity for galena particles\n", + "print \"\\n setling velocity v_g=%0.2f m/s\"%(v_g)#\n", + "#to obtain pure galena the upward velociy of the water must be equal to or greater than the settling veloctiy of the quartz particle\n", + "v_w=v_q#velocity of water\n", + "print \"\\n water velocity v_w=%0.2f m/s\"%(v_w)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.9 Page no 361" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 24.9 page no 361\n", + "\n", + "\n", + "\n", + " diameter D =4.54e-05 m\n", + "\n", + " settling factor K=1.81 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"\\n Example 24.9 page no 361\\n\\n\"\n", + "#refer to illustrative example 24.8\n", + "#we have to determine the size range of the galena in the top product\n", + "#to determine the size range of the galena product ,calculate the galena particle size that has a settling velocity equal to water velocity \n", + "#assume stokes law applies\n", + "v_w=0.0073#velocity of water\n", + "v_q=v_w#velocity of quartz particles\n", + "SG_q = 2.65#specific gravity of quartz particle \n", + "SG_g=7.5#specific gravity of galena particles \n", + "rho_f=1000#density of water \n", + "rho_q=SG_q*rho_f#density of quartz paticles\n", + "rho_g=SG_g*rho_f#density of galena particle\n", + "g=9.807#grav. acc\n", + "meu_f=0.001#viscosity of water\n", + "D = sqrt(18*meu_f*v_q/(g*(rho_g-rho_f)))\n", + "print \"\\n diameter D =%0.2e m\"%(D)#\n", + "#check on the validity of stokes law by calculating the K factor \n", + "K = D*(g*(rho_g-rho_f)*rho_f/(meu_f**2))**(1/3)#settling factor\n", + "print \"\\n settling factor K=%0.2f \"%(K)#\n", + "#since K =1.82<3.3 , the flow is in the stokes law range " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 24.10 Page no 362" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 24.10 page no 362\n", + "\n", + "\n", + "\n", + "D_p_max=5.01e-04 \n", + "\n", + " settling factor K=5.58 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 24.10 page no 362\\n\\n\"\n", + "#air is being dried by bubbling through concentrated NaOH\n", + "q=4/60#flow rate of air,ft**3/min\n", + "D=2.5/12#diameter of tube\n", + "S=(pi/4)*D**2#cross sectional area\n", + "v=q/S#velocity of air,ft/s\n", + "meu=1.23e-5#viscosity of NaOH\n", + "rho=0.0775#density of air\n", + "g=32.2#grav. acc.\n", + "SG=1.34#specific gravity of NaOH\n", + "rho_w=62.4#density of water\n", + "rho_p=SG*rho_w#density of NaOH\n", + "D_p_max = (v*(rho**0.29)*(meu**0.43)/(0.153*(g*rho_p)**0.71))**(1/1.14)#assuming that the intermediate range applies ,maximum diamter of particle\n", + "print \"\\nD_p_max=%0.2e \"%(D_p_max)#\n", + "#settling factor \n", + "K=D_p_max*(g*rho*rho_p/(meu**2))**(1/3)\n", + "print \"\\n settling factor K=%0.2f \"%(K)#\n", + "#tus result for D_p_max is correct" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-25_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-25_1.ipynb new file mode 100644 index 00000000..8ec0bc11 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-25_1.ipynb @@ -0,0 +1,303 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 25 : Porous Media and Packed Beds" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 25.1 Page no 370" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 25.1 page no 370\n", + "\n", + "\n", + "\n", + " effective partcle diameter D_p=5.50 mm \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 25.1 page no 370\\n\\n\"\n", + "#calculation of efffective particle diameter for a set of packing\n", + "V=0.2#packing volume\n", + "n=100#no. of particle assume\n", + "V_p=V*1000/n#the volume of single particle,mm**2#\n", + "S_p=2.18#average surface area of particle,mm**2\n", + "a_p=S_p/V_p#specific surface area of particle ,(mm)**-1\n", + "D_p = 6/a_p#effective diameter of particle,mm\n", + "print \"\\n effective partcle diameter D_p=%.2f mm \"%(D_p)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 25.2 Page no 371" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 25.2 page no 371\n", + "\n", + "\n", + "\n", + " Reynolds no R_e=6463.00 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 25.2 page no 371\\n\\n\"\n", + "#refer to example 25.1\n", + "V=0.2#packing volume\n", + "n=100#no. of particle assume\n", + "V_p=V*1000/n#the volume of single particle,mm**2#\n", + "S_p=2.18#average surface area of particle,mm**2\n", + "a_p=S_p/V_p#specific surface area of particle ,(mm)**-1\n", + "D_p = 6/a_p#effective diameter of particle,mm\n", + "D_p=5.50#round off value for accurate answer\n", + "rho=0.235#density of fluid,g/cm**3\n", + "meu=2e-4#viscosity,g/cm.s\n", + "v=10#interstitial velocity ,cm\n", + "R_e=round((D_p/v)*rho*v/meu)#reynolds no\n", + "print \"\\n Reynolds no R_e=%.2f \"%(R_e)#\n", + "#from R_e value we can conclude that the flow of fluid would be in the turbulent region" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 25.3 Page no 372" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 25.3 page no 372\n", + "\n", + "\n", + "\n", + " particle specific surface a_p =3.47 cm**-1 \n", + "\n", + " effective particle diameter d_p_e=1.73 cm\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 25.3 page no 372\\n\\n\"\n", + "#air flows across a packed bed \n", + "d_p=1.5#diamter of cylinderical particles,cm\n", + "h=2.5#height ,cm\n", + "V_p=pi*d_p**2*h/(4)#volume of the cylinderical particles\n", + "S_p=pi*d_p*h + 2*(pi*d_p**2/4)#cylinderical particle surface area,cm**2\n", + "a_p=S_p/V_p#particle specific surface \n", + "print \"\\n particle specific surface a_p =%.2f cm**-1 \"%(a_p)#\n", + "d_p_e=6/a_p#effective particle diameter\n", + "print \"\\n effective particle diameter d_p_e=%.2f cm\"%(d_p_e)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 25.4 Page no 373" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Example 25.4 page no 373\n", + "\n", + "\n", + "\n", + " specific particle surface area a_p=8.00 in**-1\n", + "\n", + " effective particle diameter d_p_e=0.75 in\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\nExample 25.4 page no 373\\n\\n\"\n", + "#a absorber bed consists of cube particles \n", + "L=3/4#edge length of particle\n", + "V_p=L**3#volume of particle \n", + "S_p=6*L**2#surface area of particle\n", + "a_p=6*L**2/L**3#specific particle surface area\n", + "print \"\\n specific particle surface area a_p=%.2f in**-1\"%(a_p)#\n", + "d_p_e = L#effective particle diameter = edge length\n", + "print \"\\n effective particle diameter d_p_e=%.2f in\"%(d_p_e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 25.5 Page no 373" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 25.5 page no 373\n", + "\n", + "\n", + "\n", + " superficial velocity v_s=2.00 ft/s\n", + "\n", + " interstitial velocity v_i=5.00 ft/s\n", + "\n", + " bulk density rho_b=46.37 lb/ft**3\n", + "\n", + " specific surface area a_p=72.03 ft**-1\n", + "\n", + " bed specific surface a_b=43.22 ft**-1\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 25.5 page no 373\\n\\n\"\n", + "#gas(propane) flows through a catalyst tower\n", + "Mw=44.1#molecular weight\n", + "P=4320#pressre at the bottom of the catalyst bed,psf\n", + "R=10.73#gas constant\n", + "T=960#temperature,Rankine\n", + "rho=P*Mw/(R*T*144)#density of propane\n", + "L=50#height of bed,ft\n", + "D=20#diameter of bed,ft\n", + "V=pi*D**2*L/4#bed volume\n", + "theta=10#contact time,s\n", + "e=0.4#bed porosity\n", + "q=V*e/theta#volumetric flow rate\n", + "v_s=4*q/(pi*D**2)#superficial velocity\n", + "print \"\\n superficial velocity v_s=%.2f ft/s\"%(v_s)#\n", + "v_i=v_s/e#interstitial velocity\n", + "print \"\\n interstitial velocity v_i=%.2f ft/s\"%(v_i)#\n", + "rho_s=77.28#ultimate density(spheres )\n", + "rho_b=(1-e)*rho_s#bulk density\n", + "print \"\\n bulk density rho_b=%.2f lb/ft**3\"%(rho_b)#\n", + "d_p=0.0833#diameter of particles\n", + "a_p=6/d_p#specific surface area\n", + "print \"\\n specific surface area a_p=%.2f ft**-1\"%(a_p)#\n", + "a_b=a_p*(1-e)#bed specific surface\n", + "print \"\\n bed specific surface a_b=%.2f ft**-1\"%(a_b)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 25.6 Page no 375" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 25.6 page no 375\n", + "\n", + "\n", + "\n", + " hydraulic diameter D_h=0.04 ft\n", + " hydrulic radius r_h=0.009 ft\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 25.6 page no 375\\n\\n\"\n", + "#refer to example 25.5\n", + "d_p=0.0833#diameter of particles,ft\n", + "e=0.4#bed porosity\n", + "D_h=2/3*(e/(1-e))*d_p#hydraulic diameter\n", + "r_h=D_h/4#hydrulic radius\n", + "print \"\\n hydraulic diameter D_h=%.2f ft\\n hydrulic radius r_h=%.3f ft\"%(D_h,r_h)# " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-26_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-26_1.ipynb new file mode 100644 index 00000000..20c7c2bf --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-26_1.ipynb @@ -0,0 +1,580 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 26 : Fluidization" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.2 Page no 382" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.2 page no 384\n", + "\n", + "\n", + "\n", + " superficial velocity v_s=0.04 ft/s\n", + "\n", + " R_e=22.93\n", + "\n", + " superficial velocity v_s_t=0.01 ft/s\n", + "\n", + " reynolds no R_e_t=6.14 \n", + "\n", + " vol. flow rate q=2.62e-04 ft**3/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 26.2 page no 384\\n\\n\"\n", + "#a water softner unit consists of a large diameter tank ,the bottom of tank is connected to a vertical ion exchange pipe\n", + "h_f=1.25#total fluid height \n", + "h_l=h_f\n", + "g=32.174#grav. acc\n", + "e=0.25# bed porosity \n", + "d_p=0.00417#ion exchange resin particle diameter,ft\n", + "L=1#pipe length ,ft\n", + "#assume turbulent flow ,apply burke purmer equation\n", + "v_s=sqrt(g*h_f*e**3*d_p/(1.75*(1-e)*L))#superficial velocity\n", + "print \"\\n superficial velocity v_s=%.2f ft/s\"%(v_s)#\n", + "meu=6.76e-4#absolute viscosity of water\n", + "rho=62.4#density of water\n", + "#check for turbulent flow \n", + "R_e=d_p*v_s*rho/((1-e)*meu)\n", + "print \"\\n R_e=%.2f\"%(R_e)#\n", + "#since reynold no is low the calculation is not valid \n", + "#assume laminar flow and use Blake-Kozeny equation 26.9\n", + "v_s_t=rho*g*h_f*e**3*d_p**2/(150*meu*((1-e)**2)*L)#superficial velocity\n", + "print \"\\n superficial velocity v_s_t=%.2f ft/s\"%(v_s_t)#\n", + "#check the porous medium reynolds no\n", + "R_e_t=v_s_t*d_p*rho/((1-e)*meu)\n", + "print \"\\n reynolds no R_e_t=%.2f \"%(R_e_t)#\n", + "#since reynolds no R_e < 10,the flow is therfor laminar\n", + "D=0.167#diameter of pipe\n", + "S=(pi/4)*D**2#empty cross sectional area\n", + "q=v_s_t*S#volumetric flow rate\n", + "print \"\\n vol. flow rate q=%.2e ft**3/s\"%(q)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.3 Page no 384" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.3 page no 384\n", + "\n", + "\n", + "\n", + " superficial velocity v_s=0.04 ft/s\n", + "\n", + " R_e=22.93\n", + "\n", + " superficial velocity v_s_t=0.01 ft/s\n", + "\n", + " reynolds no R_e_t=6.14 \n", + "\n", + " fricion pressure drop P_drop_fr=78.00 psf\n", + "\n", + " pressure drop across across the resin bed P_drop_r=15.60 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 26.3 page no 384\\n\\n\"\n", + "#refer to Example 26.2\n", + "#a water softner unit consists of a large diameter tank ,the bottom of tank is connected to a vertical ion exchange pipe\n", + "h_f=1.25#total fluid height \n", + "h_l=h_f\n", + "g=32.174#grav. acc\n", + "e=0.25# bed porosity \n", + "d_p=0.00417#ion exchange resin particle diameter,ft\n", + "L=1#pipe length ,ft\n", + "#assume turbulent flow ,apply burke purmer equation\n", + "v_s=sqrt(g*h_f*e**3*d_p/(1.75*(1-e)*L))#superficial velocity\n", + "print \"\\n superficial velocity v_s=%.2f ft/s\"%(v_s)#\n", + "meu=6.76e-4#absolute viscosity of water\n", + "rho=62.4#density of water\n", + "#check for turbulent flow \n", + "R_e=d_p*v_s*rho/((1-e)*meu)\n", + "print \"\\n R_e=%.2f\"%(R_e)#\n", + "#since reynold no is low the calculation is not valid \n", + "#assume laminar flow and use Blake-Kozeny equation 26.9\n", + "v_s_t=rho*g*h_f*e**3*d_p**2/(150*meu*((1-e)**2)*L)#superficial velocity\n", + "print \"\\n superficial velocity v_s_t=%.2f ft/s\"%(v_s_t)#\n", + " #check the porous medium reynolds no\n", + "R_e_t=v_s_t*d_p*rho/((1-e)*meu)\n", + "print \"\\n reynolds no R_e_t=%.2f \"%(R_e_t)#\n", + "#since reynolds no R_e < 10,the flow is therfor laminar\n", + "#calculation of the pressure drop due to friction and the pressure drop across the resin bed \n", + "k=e**3*d_p**2/(150*(1-e)**2)#packed bed permeability\n", + "P_drop_fr=rho*h_f#friction pressure drop across resin bed,psf\n", + "print \"\\n fricion pressure drop P_drop_fr=%.2f psf\"%(P_drop_fr)# \n", + "z_d=-1#length from point 2 to 3,ft\n", + "P_drop_r=rho*(z_d+h_f)#pressure drop across the resi bed\n", + "print \"\\n pressure drop across across the resin bed P_drop_r=%.2f psf\"%(P_drop_r)#\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.4 Page no 387" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Example 26.4 page no 387\n", + "\n", + "\n", + "\n", + " min. fluidization velocity v_mf=0.25 m/s\n", + "\n", + " Reynolds no R_e=1.79 \n", + "\n", + " mass flow rate m_dot =0.01 kg/s\n", + "\n", + " gas pressure drop P_fr=3560.00 Pa\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"\\nExample 26.4 page no 387\\n\\n\"\n", + "#air is used to fluidize a bed of speherical particles\n", + "D=0.2#bed diameter,m\n", + "d_p=7.4e-5#diameter of 200 mesh particles from table 23.2,m\n", + "rho_s=2200#ultimate solid density\n", + "rho_f=1.2#density of air\n", + "meu=1.89e-5#viscosity of air\n", + "g=9.807#grav. constant\n", + "e=0.45#bed porosity\n", + "L_mf=0.3#length at minimum fluidization\n", + "#assume laminar flow \n", + "#applying equation 26.29\n", + "v_mf=(1-e)*g*rho_s*d_p**2/(150*e**3*meu)#minimum fluidizaton veloctiy \n", + "print \"\\n min. fluidization velocity v_mf=%.2f m/s\"%(v_mf)#\n", + "#check the flow regime\n", + "R_e=v_mf*d_p/(meu*(1-e))\n", + "print \"\\n Reynolds no R_e=%.2f \"%(R_e)#\n", + "#since R_e= 1.79 <10,flow is laminar\n", + "m_dot=pi*v_mf*D**2*rho_f/4#mass flow rate\n", + "print \"\\n mass flow rate m_dot =%.2f kg/s\"%(m_dot)#\n", + "P_fr=round((1-e)*rho_s*g*L_mf)#gas pressure drop across the bed\n", + "print \"\\n gas pressure drop P_fr=%.2f Pa\"%(P_fr)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.5 Page no 389" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.5 page no 389\n", + "\n", + "\n", + "\n", + " pressure drop P_rop=18.08 lb/ft**2\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 26.5 page no 389\\n\\n\"\n", + "#air flowing through a 10 ft packed bed\n", + "V_o=4.65#superficial velocity,ft/s\n", + "meu_g=1.3e-5#viscosity of air \n", + "rho_g=0.67#density of air,lb/ft**3\n", + "e=0.89#void volume\n", + "g_c=32.2#grav. constant\n", + "L=10#length of packed bed \n", + "d_p=0.007815#effective particle diameter\n", + "P_drop = ((150*V_o*meu_g/(g_c*d_p**2))*((1-e)**2/e**3) + (1.75*rho_g*V_o**2/(g_c*d_p))*((1-e)**2/e**3))*L#pressure drop\n", + "print \"\\n pressure drop P_rop=%.2f lb/ft**2\"%(P_drop)##calculation error in book \n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.6 Page no 392 " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.6 page no 392\n", + "\n", + "\n", + "\n", + "pressure drop P_drop=583.84 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "print \"Example 26.6 page no 392\\n\\n\"\n", + "#a bed of pulverized is to be fluidized with liquid oil\n", + "D=4#diameter of bed ,ft\n", + "d_p=0.00137#particle diameter ,ft \n", + "rho_s=84#coal particle density ,lb/ft**3\n", + "rho_f=55#oil density,lb/ft**3\n", + "e_mf=0.38#void fraction\n", + "L_mf=8#bed height at minimum fluidization,ft\n", + "P_drop=(rho_s-rho_f)*(1-e_mf)*L_mf +rho_f*L_mf \n", + "\n", + "print \"\\npressure drop P_drop=%.2f psf\"%(P_drop)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.7 Page no 393" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.7 page no 393\n", + "\n", + "\n", + "\n", + " superficial velocity v_s=0.01 ft/s\n", + "\n", + " vol. floe rate q=0.12 ft**3/s\n", + "\n", + " reynolds no R_e=0.15\n", + "\n", + " since R_e is less than 10 ,flow is laminar\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 26.7 page no 393\\n\\n\"\n", + "#refer to example 26.6\n", + "D=4#diameter of bed ,ft\n", + "d_p=0.00137#particle diameter ,ft \n", + "rho_s=84#coal particle density ,lb/ft**3\n", + "rho_f=55#oil density,lb/ft**3\n", + "meu_f=3.13e-4#viscosity of oil\n", + "e_mf=0.38#void fraction\n", + "L_mf=8#bed height at minimum fluidization,ft\n", + "L_f=10#bed height,ft\n", + "e=1-L_mf*(1-e_mf)/L_f#bed voidage\n", + "g=32.174#grav acc\n", + "v_s=(d_p**2)*g*(e**3)*(rho_s-rho_f)/(150*meu_f*(1-e)) #superficial velocity\n", + "print \"\\n superficial velocity v_s=%.2f ft/s\"%(v_s)#\n", + "q=(pi/4)*D**2*v_s#volumetric flow rate\n", + "print \"\\n vol. floe rate q=%.2f ft**3/s\"%(q)#\n", + "#check on the laminar flow assumption\n", + "meu_f=0.01\n", + "R_e=d_p*v_s*rho_f/(meu_f*(1-e))\n", + "print \"\\n reynolds no R_e=%.2f\"%(R_e)#\n", + "print \"\\n since R_e is less than 10 ,flow is laminar\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.8 Page no 393" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 26.8 page no 393\n", + "\n", + "\n", + "\n", + " head loss h_f=1224.30 ft of propane \n", + "\n", + " pressure P1=4303.69 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \" Example 26.8 page no 393\\n\\n\"\n", + "#refer to example 25.6\n", + "#obtain the porous medium friction factor usingthe burke -plummer equation \n", + "#/since the flow is turbulent ,eq.26.6 applies\n", + "f_pm=1.75#porous medium friction facot\n", + "v_s=2#superficial velocity\n", + "e=.4#porosity\n", + "L=50#length of bed\n", + "d_p=0.0833#particle diameter\n", + "g=32.174#grav. acc\n", + "h_f=(f_pm)*(v_s**2)*(1-e)*L/(g*(e**3)*d_p)#head loss\n", + "print \"\\n head loss h_f=%.2f ft of propane \"%(h_f)#\n", + "#applying bernoulli eq. between the entrance and gas exit \n", + "#neglect the dynamic head\n", + "P2=4320#pressure at the bottom of the catalyst bed\n", + "rho_f=0.0128#density of fluid\n", + "z_d=-50#length from point 2 to 3,z2-z1\n", + "P1 = P2 + rho_f*(z_d-h_f)# absolute pressure of the inlet gas\n", + "print \"\\n pressure P1=%.2f psf\"%(P1)#\n", + "#since flow is turbulent , permeablity of the medium k can not be calculated" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.9 Page no 394" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.9 page no 394\n", + "\n", + "\n", + "\n", + " superficial velocity v_s=0.75 m/s\n", + "\n", + "pressure drop P_drop=2.36e+07 Pa\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 26.9 page no 394\\n\\n\"\n", + "#turbulent flow of water through a carbon bed\n", + "d_p=0.001#particle diameter\n", + "meu=0.001#viscosity of water\n", + "e=0.25#porosity\n", + "R_e=1000#R_e is >1000 for turbulent flow,for minimum pressure drop\n", + "rho=1000#density of water,kg/m**3\n", + "v_s=R_e*meu*(1-e)/(d_p*rho)#superficial velocity\n", + "print \"\\n superficial velocity v_s=%.2f m/s\"%(v_s)#\n", + "phi_s=1#spehercity\n", + "L=0.5#length of bed,m\n", + "P_drop = 1.75*rho*L*v_s**2*(1-e)/(phi_s*d_p*(e**3))#presssure drop\n", + "print \"\\npressure drop P_drop=%.2e Pa\"%(P_drop)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.10 Page no 395" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 26.10 page no 395\n", + "\n", + "\n", + "\n", + " zero porosity bed height L_o=0.17 m\n", + "\n", + " velocity at min. fluidization v_mf=0.01 m/s\n", + "\n", + " expanded bed height L_f=1.83 m\n", + " bed inventory m=45.62 kg\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 26.10 page no 395\\n\\n\"\n", + "#a bed of 200 mesh particles is fluidized with air\n", + "d_b=0.2#diameter of bed,m\n", + "d_p=7.4e-5#particle diameter\n", + "L_mf=0.3#bed height at minimum fludization\n", + "e_mf=0.45#bed porosity at min. fluidization\n", + "L_o=L_mf*(1-e_mf)#the zero porosity bed height \n", + "print \"\\n zero porosity bed height L_o=%.2f m\"%(L_o)#\n", + "rho_s=2200#density of particles \n", + "rho_f=1.2#density of fluid\n", + "g=9.807#grav. acc\n", + "meu_f=1.89e-5#viscosity of fluid\n", + "#assuming laminar flow ,use equation 26.9\n", + "v_mf =(e_mf**3)*(g*(rho_s-rho_f)*(d_p**2))/(150*(1-e_mf)*meu_f)#velocity at minimum fluidization\n", + "print \"\\n velocity at min. fluidization v_mf=%.2f m/s\"%(v_mf)#\n", + "v_t=0.35#terminal velocity from example 26.3\n", + "e=0.91#value of e porosity from eq26.9\n", + "L_f=L_o/(1-e)#expanded bed height L_f\n", + "m=rho_s*pi*d_b**2*L_o#bed inventory\n", + "print \"\\n expanded bed height L_f=%.2f m\\n bed inventory m=%.2f kg\"%(L_f,m)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 26.11 Page no 396" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 26.11 page no 396\n", + "\n", + "\n", + "\n", + " zero porosity bed height L_o=0.17 m\n", + "\n", + " velocity at min. fluidization v_mf=0.01 m/s\n", + "\n", + " fluidization mode F_mf=0.07 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 26.11 page no 396\\n\\n\"\n", + "#refer to illustrative example 26.9\n", + "d_p=7.4e-5#particle diameter\n", + "L_mf=0.3#bed height at minimum fludization\n", + "e_mf=0.45#bed porosity at min. fluidization\n", + "L_o=L_mf*(1-e_mf)#the zero porosity bed height \n", + "print \"\\n zero porosity bed height L_o=%.2f m\"%(L_o)#\n", + "rho_s=2200#density of particles \n", + "rho_f=1.2#density of fluid\n", + "g=9.807#grav. acc\n", + "meu_f=1.89e-5#viscosity of fluid\n", + "#assuming laminar flow ,use equation 26.9\n", + "v_mf =(e_mf**3)*(g*(rho_s-rho_f)*(d_p**2))/(150*(1-e_mf)*meu_f)#velocity at minimum fluidization\n", + "print \"\\n velocity at min. fluidization v_mf=%.2f m/s\"%(v_mf)#\n", + "F_mf=v_mf**2/(g*d_p)#fluidization mode\n", + "print \"\\n fluidization mode F_mf=%.2f \"%(F_mf)#\n", + "#from value of F_mf ,fluidization is smoth,F_mf =0.66<0.13" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-27_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-27_1.ipynb new file mode 100644 index 00000000..ba8f40eb --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-27_1.ipynb @@ -0,0 +1,241 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 27 : Filteraion" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 27.2 Page no 413" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 27.2 page no 413\n", + "\n", + "\n", + "\n", + " filter colth area A=720.00 ft**2\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 27.2 page no 413\\n\\n\"\n", + "#plate and frame filter press is to be employed to filter a slurry \n", + "m_dot_slurry=600*60#mass flow rate ,lb/h\n", + "m=0.1#sluury contain 10% by mass solid\n", + "m_dot_solids = m*m_dot_slurry#the solid flow rate in the slurry\n", + "a=(1/5)#filter colth area required for 1 lb/h of solid\n", + "A=m_dot_solids*(a)#filter colth area for 3600 lb/h of solids\n", + "print \"\\n filter colth area A=%0.2f ft**2\"%(A)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 27.4 Page no 414" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 27.4 page no. 414\n", + "\n", + "\n", + "\n", + " coeff. K_c=3894.00 s/ft**6\n", + " coeff. q_r=217.00 s/ft**3\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 27.4 page no. 414\\n\\n\"\n", + "m=1947#slope of curve b/w t/V vs V,s/ft**6\n", + "K_c=2*m\n", + "c=217#intercept on graph\n", + "q_r=c#reciprocal of q\n", + "print \"\\n coeff. K_c=%0.2f s/ft**6\\n coeff. q_r=%0.2f s/ft**3\"%(K_c,q_r)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 27.5 Page no 415" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 27.5 page no 415\n", + "\n", + "\n", + "R_m=1.18e+10 ft\n", + "\n", + " alpha=1.79e+10 ft/lb\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 27.5 page no 415\\n\\n\"\n", + "#refer to example 27.4\n", + "meu=5.95e-4#viscosity \n", + "g_c=32.174#grav. acc\n", + "P_drop=20*144#pressure drop\n", + "q_o=(1/217)#flow rate \n", + "S=0.35#filteration area per unit\n", + "K_c=3894#coefficentc\n", + "c=4.142#slurry conentration \n", + "R_m=S*g_c*P_drop/(q_o*meu)#filteration coeff.\n", + "print \"R_m=%0.2e ft\"%(R_m)#\n", + "alpha=K_c*S**2*g_c*P_drop/(c*meu)#filteration coeff.\n", + "print \"\\n alpha=%0.2e ft/lb\"%(alpha)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 27.7 Page no 418" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 27.7 page no 418\n", + "\n", + "\n", + "\n", + " specific cake resistance alpha_o=9.77e+10 ft/lb\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 27.7 page no 418\\n\\n\"\n", + "#the following result were obtained during the running of a filteration experiment \n", + "alpha=4.57e+11#cake resistance,ft/lb\n", + "P_drop=1554#pressure drop ,lbf/ft**2\n", + "alpha_o=alpha/(P_drop**0.21)#specific cake resistance\n", + "print \"\\n specific cake resistance alpha_o=%0.2e ft/lb\"%(alpha_o)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 27.9 Page no 418" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 27.9 page no 418\n", + "\n", + "\n", + "\n", + " washing time t_w=16.50 min\n", + "\n", + " flow rate q_c=56.34 gal/hr \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 27.9 page no 418\\n\\n\"\n", + "#a filter press operates at a constant pressure\n", + "P=50#pressure,psig\n", + "q=10#flow rate,ft**3/min\n", + "#applying eq.27.12\n", + "#q = P/(B*V_s + C)\n", + "#in this case,V_s=0\n", + "C=P/q#constant\n", + "#for constant pressure applying equation 27.13\n", + "#t = B*V_s**2/(2P) + C*V_s/P\n", + "t=60#time ,min\n", + "V_s=100#volume,ft**3\n", + "B= 2*P*t/(V_s**2) - 2*C/V_s#constant\n", + "#during the washing cycle t_w = V_w/q_w\n", + "#B and C remain same\n", + "V_w=15#volume of water for washing per hr\n", + "t_w= V_w*(B*V_s + C)/P#time in washing\n", + "print \"\\n washing time t_w=%0.2f min\"%(t_w)#\n", + "t_d=30#time for dumping and cleanig\n", + "t_c=(t + t_w +t_d)/60#collecting time,in hr\n", + "q_c =V_s/t_c#flow rate for 100 ft**3\n", + "print \"\\n flow rate q_c=%0.2f gal/hr \"%(q_c)# " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-28_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-28_1.ipynb new file mode 100644 index 00000000..75cb6066 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-28_1.ipynb @@ -0,0 +1,477 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 28 : Environmental management" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.3 Page no 430" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 28.3 page no 430\n", + "\n", + "\n", + "\n", + " settling factor K=0.104 \n", + "\n", + "settling velocity v=1.205e-03 ft/s\n", + "\n", + " desent time t=124430.77 sec\n", + "\n", + " minimum horizontal distance x=103.69 miles\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 28.3 page no 430\\n\\n\"\n", + "#we have to determine the minimum distance downstream from a cement dust emitting source that will be free of cement deposit \n", + "#the souce is equipped with a cyclone located 150 ft above ground level \n", + "#neglect meteorological aspects\n", + "h=150#cyclone height from ground level,ft\n", + "v_w=3/3600#wind velocity,miles/second\n", + "SG=1.96#specific gravity of cement dust\n", + "rho_w=62.4#density of water,lb/ft**3\n", + "rho_p=SG*rho_w#/density cement particles\n", + "#applying ideal gas law for density of air\n", + "P=1#pressure,atm\n", + "M= 29#mol. weight of air\n", + "R=0.73#gas constant \n", + "T=520#temperature,Rankine\n", + "rho_a=P*M/(R*T)#density of air \n", + "meu=1.22e-5#viscosity of air,lb/ft.s\n", + "g=32.174#grav. acc.\n", + "d_p=2.5/(25400*12)#particle diameter,ft\n", + "K = d_p*(g*rho_p*rho_a/(meu**2))**(1/3)#settling factor\n", + "print \"\\n settling factor K=%.3f \"%(K)#\n", + "#since K=0.103<3.3,sokes law rane applies\n", + "v= g*d_p**2*rho_p/(18*meu)#terminal settling velocity)\n", + "print \"\\nsettling velocity v=%.3e ft/s\"%(v)#\n", + "t=h/v#time for desent\n", + "print \"\\n desent time t=%.2f sec\"%(t)#\n", + "x=v_w*t#horizontal distance travelled in miles\n", + "print \"\\n minimum horizontal distance x=%.2f miles\"%(x)##printing mistake in book" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.4 Page no 432" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 28.4 page no 432\n", + "\n", + "\n", + "\n", + " filtering beg area S_c=5461.54 ft**2\n", + "\n", + " area S_a=33.51 ft**2\n", + " number og bags N_a=163.00 \n", + "\n", + " area S_b=41.89 ft**2\n", + " no. of bags N_b=130.00 \n", + "\n", + " total cost TC_a=4238.00 $\n", + "\n", + " total cost TC_b=4940.00 $\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 28.4 page no 432\\n\\n\"\n", + "#it is proposed to install a pulse jet fabric filter system to clean an air stream containing particulate pollutants\n", + "#we have to select the most apporpriate filter beg fabric \n", + "q_scfm=10000#volumetric flow rate of polluted air stream at 60 deg F ,1 atm\n", + "T=520#temperature,R\n", + "T_o=710#operating temparature ,R\n", + "q_acfm=q_scfm*(T_o/T)#flow rate in acfm\n", + "v_f=2.5#filteration velocity,ft/min\n", + "S_c=q_acfm/v_f#filtering beg area\n", + "print \"\\n filtering beg area S_c=%.2f ft**2\"%(S_c)#\n", + "#(1) for bag A ,the area and N number of bags are\n", + "D_a=8/12#diamter,ft\n", + "H_a=16#height,ft\n", + "S_a =pi*D_a*H_a#area\n", + "N_a= round(S_c/S_a)#no. of bags \n", + "print \"\\n area S_a=%.2f ft**2\\n number og bags N_a=%.2f \"%(S_a,N_a)#\n", + "#(2) for bag B\n", + "D_b=10/12#diameter,ft\n", + "H_b=16#height,ft\n", + "S_b=pi*D_b*H_b#area\n", + "N_b=round(S_c/S_b)#no. of bags\n", + "print \"\\n area S_b=%.2f ft**2\\n no. of bags N_b=%.2f \"%(S_b,N_b)#\n", + "#total cost for each bag\n", + "#for bag A\n", + "c_a=26#cost per bag\n", + "TC_a=round(N_a*c_a)#total cost for A bag\n", + "print \"\\n total cost TC_a=%.2f $\"%(TC_a)#\n", + "#for bag B\n", + "c_b=38#cost per bag\n", + "TC_b=N_b*c_b#total cost for bag B\n", + "print \"\\n total cost TC_b=%.2f $\"%(TC_b)#\n", + "#since the total cost for bag A is less than bag B,select bag A" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.5 Page no 433" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 28.5 page no 433\n", + "\n", + "\n", + "\n", + " no. of bags N=106.10 \n", + "\n", + " time t=16.80 min\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"\\n Example 28.5 page no 433\\n\\n\"\n", + "#we have to determine the number if filtering bags required and cleaning frequency for a plant equipped with a fabric system\n", + "q=50000#volumetric flow rate of gas stream,acfm\n", + "v_f=10#filteration velocity,ft/min\n", + "D=1#diameter of filtering bag,ft\n", + "L=15#length of filtering bag,ft\n", + "S_c=q/v_f#filtering area,ft**2\n", + "S=pi*D*L#area per bag,ft**2\n", + "N=S_c/S#no. of bags\n", + "print \"\\n no. of bags N=%.2f \"%(N)#\n", + "c=0.0007143#dust concentration ,lb/ft**2\n", + "P_drop=8#pressure drop ,in H20\n", + "t=(P_drop-(0.2*v_f))/(5*c*v_f**2)#time sic ethe bags were cleaned\n", + "print \"\\n time t=%.2f min\"%(t)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.6 Page no 434" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 28.6 page no 434\n", + "\n", + "\n", + "\n", + " volumetric flow rate q=2045.26 ft**3/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 28.6 page no 434\\n\\n\"\n", + "#comparison between flow in pipes and open channel flow\n", + "#water is passing through a trapezodial channel\n", + "l_b=20#length of bottom base,ft\n", + "l_t=50#length of top base,ft\n", + "h=7.5#height of channel,ft\n", + "A = (l_b+ l_t)*(h/2)#cross sectional area\n", + "P = l_b +sqrt(h**2+ (2*h)**2)#perimeter of trapezoid\n", + "r_h=A/P#hydrulic radius\n", + "S=0.0008#coeff. in manning equation\n", + "n=0.02#coeff. in manning eq.\n", + "q = 1.486*A*r_h**(2/3)*S**(1/2)/n#manning equation to determine flow rate\n", + "print \"\\n volumetric flow rate q=%.2f ft**3/s\"%(q)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.7 Page no 435" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 28.7 page no 435\n", + "\n", + "\n", + "\n", + " fdischarge from the treatment plant m_dot_w=2919.00 lb/day\n", + "\n", + " total nitrogen discharge m_r=7515.12 lb/day \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 28.7 page no 435\\n\\n\"\n", + "#waste water treatment plant \n", + "#we have to compare the total nitrogen discharge from the watershed with that of the city 's sewage treatment plant\n", + "q_w=10#flow rate from waste water treatment plant\n", + "c=35#nitoren concentration,mg/l\n", + "m_dot_w=c*q_w*8.34#discharge from the treatment plant\n", + "print \"\\n fdischarge from the treatment plant m_dot_w=%.2f lb/day\"%(m_dot_w)#\n", + "S=8#area of watershed,mi**2 \n", + "r=0.06#rate of rainfall,ml/day\n", + "n=.5#50% rain reaches the sewers\n", + "q=n*r*S*(5280**2/(3600*12))#volumetric flow rate of the runoff\n", + "c_r=9#tota# nitrogen conentration in runoff,mg/l\n", + "rho=62.4#/density of water\n", + "m_r=q*c_r*1e-6*(3600*24)*rho#total nitrogen discharge from runoff\n", + "print \"\\n total nitrogen discharge m_r=%.2f lb/day \"%(m_r)#\n", + " #since the durinf rain ,the runoff is over 2.5 times that for the tratment plant" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.8 Page no 436" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 28.8 page no 436\n", + "\n", + "\n", + "\n", + " volume based on organic loading V_ol=3900.00 ft**3\n", + "\n", + " volume based on hyraulic load V_hl=7295.09 ft**3\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 28.8 page no 436\\n\\n\"\n", + "#we have to determine the siaze an aerobic digester to treat the solids \n", + "m=1000#mass of solid that is generate by municipality,lb\n", + "OL=0.2#organic loading,lbcs/ft**3.day\n", + "VS=.78#volatile solids\n", + "V_ol=m*VS/OL#volume based on organic loading\n", + "print \"\\n volume based on organic loading V_ol=%.2f ft**3\"%(V_ol)#\n", + "t_h=20#detention time hydraulic, days\n", + "TS=0.044#percentage solids enterning digester\n", + "V_hl=m*t_h/(TS*8.33*7.48)#volume based on hydrulic load\n", + "print \"\\n volume based on hyraulic load V_hl=%.2f ft**3\"%(V_hl)#\n", + "#since V_hl >V_ol,the hdraulic time controls and the design volume is V_hl" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.9 Page no 437" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 28.9 page no 437\n", + "\n", + "\n", + "\n", + " volume of cavern availible for solid waste V=8.61e+10 ft**3\n", + "\n", + " q=208000.00 \n", + "\n", + " time to fill the cavern t=4.14e+05 year\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 28.9 page no 437\\n\\n\"\n", + "#a large deep cavern has been proposed as an ultimate disposal site for both solid hazardous and municipal wastes\n", + "V_c=0.78#approximate total volume of cavern,mi**2\n", + "V_s=.75#% volume availiable for solid waste depositry \n", + "V=V_c*V_s*(5280)**3#volume of the cavern availible for the solid waste ,factor 5280 to convert mi**3 into ft**3\n", + "print \"\\n volume of cavern availible for solid waste V=%.2e ft**3\"%(V)\n", + "r=20000#proposed maximum waste feed rate to cavern ,lb/day\n", + "rho=30#average bulk density,lb/ft**3\n", + "q=(r/rho)*(6*52)#volume rate of solid deposited within the cavern in ft**3/year\n", + "print \"\\n q=%.2f \"%(q)#\n", + "t=V/q#time to fill the cavern\n", + "print \"\\n time to fill the cavern t=%.2e year\"%(t)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 28.10 Page no 438" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 28.10 page no 438\n", + "\n", + "\n", + "\n", + " particulate con. C_p=0.07 gr/dscf\n", + "\n", + " velocity v=36.72 fps\n", + "\n", + " stack flow rate v_s=6921.12 acfm\n", + "\n", + " standard volumetric flow rate q_s=5628.65 dscfm\n", + "\n", + " particulate emmision rate R_e=81.67 lb/day\n", + "\n", + " mol. weight of flue gas on dry basis MW_d=30.52 lb/lbmol\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 28.10 page no 438\\n\\n\"\n", + "# a compliance stack test on a facility yields the results ,we have to determine whether the incineratormeets the state particulate standard of 0.05 gr/dscf\n", + "g=9.807#grav. acc\n", + "rho_l=1000#density of manometer fluid,kg/m**3\n", + "rho=1.084#density of flue gas,kg/m**3\n", + "C=0.85#pitot tube constant \n", + "h=0.3772#mean pitot tube reading ,in H2O\n", + "m=0.16#mass of particulate collected ,g\n", + "V=35#volume sampled,dscf\n", + "C_p=m*15.43/V#partculate concentration,gr/dscf\n", + "print \"\\n particulate con. C_p=%.2f gr/dscf\"%(C_p)#\n", + "#since this does not exceed the particulate standard of 0.05 gr/dscf,the facility is not in compliance\n", + "#the stack flow rate is calculated from the velocity measurement\n", + "v=C*sqrt(2*g*(rho_l/rho)* 0.0254*h)/.3048#velocity\n", + "print \"\\n velocity v=%.2f fps\"%(v)#\n", + "D=2#diameter of stack,ft\n", + "v_s=(v*pi*D**2/4)*60#stack flow rate \n", + "print \"\\n stack flow rate v_s=%.2f acfm\"%(v_s)#\n", + "w_mo=0.07#% moisture in stack gas\n", + "v_dry=(1-w_mo)*v_s#dry volumetric flow rate \n", + "#correct to standard conditions of 70 deg F and 1 atm\n", + "T_s=530# standard temprature deg R\n", + "P_s=29.9#standard pressure,psi\n", + "P_g=29.6#pressure of stack gas,psi\n", + "T_g=600#temprature of standard gas,deg R\n", + "q_s=v_dry*(T_s/T_g)*(P_g/P_s)#standard volumetric flow rate\n", + "print \"\\n standard volumetric flow rate q_s=%.2f dscfm\"%(q_s) \n", + "R_e=C_p*q_s*(1440/7000)#particulate emission rate\n", + "print \"\\n particulate emmision rate R_e=%.2f lb/day\"%(R_e)#\n", + "w_co2=0.14#percentage of co2 by volume\n", + "w_N2=0.79#percentage of N2 by volume\n", + "mw_o=32#molecular weight of oxygen\n", + "mw_co2=44#molecular weight of co2\n", + "mw_N2=28#molecular weight of N2\n", + "MW_d=w_mo*mw_o + w_co2*mw_co2 +w_N2*mw_N2#molecular weight of flue gas on dry basis\n", + "print \"\\n mol. weight of flue gas on dry basis MW_d=%.2f lb/lbmol\"%(MW_d)#\n", + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-29_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-29_1.ipynb new file mode 100644 index 00000000..2aaafee7 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-29_1.ipynb @@ -0,0 +1,227 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 29 : Accident and emergency" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 29.2 Page no 455" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 29.2 page no 455\n", + "\n", + "\n", + "\n", + " probability P=1.98e-05 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import factorial\n", + "print \"Example 29.2 page no 455\\n\\n\"\n", + "#the probability distribution of the number of defectives in a sample of five pump drawn with replacement from lot of 1000 pump\n", + "#the probability distribution of x, thenumber of sucess in n performances of th erandom experiment is the probability distribution function \n", + "#P(x) = (factorial(n)/factorial(x)*(factorial n -factorial x))*(p**x*q**n-x)\n", + "n=5#no. of performances\n", + "x=3#no. of successes \n", + "p=0.05#probability of sucesses when the sample of pump is drawn with replacement\n", + "q=1-p#probability of faliure\n", + "P=factorial(n)*((p**x)*(q**(n-x)))/(factorial(x)*(factorial(n)-factorial(x)))#probability when x=3#probability when x=3/factorial(x)*(factorial(n)-factorial(x))*(p**x*q**(n-x))#probability when x=3\n", + "print \"\\n probability P=%.2e \"%(P)# #calculation error in book" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Examctple 29.3 Page no 455" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 29.3 page no 455\n", + "\n", + " reynolds no. R_e=807607.46 \n", + "\n", + " pressure drop in duct P_drop_d=12.71 lbf/ft**2\n", + "\n", + " total pressure drop P_drop_t=33.51 lbf/ft**2\n", + "\n", + " power required hp=30.46 hp \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 29.3 page no 455\"\n", + "#an iron foundry has four work stations that are connected to single duct\n", + "v_air=4000#the minimum air velocity required for general foundry dust,ft/min\n", + "v_air_s=v_air/60#velocity of air in ft/s\n", + "n=4#no. of duct\n", + "q_e=3000#each duct transport air,acfm\n", + "q=n*q_e#total transport,acfm\n", + "A=q/v_air#cross sectional area required ,ft**2\n", + "D=sqrt(4*A/pi)#duct diameter,ft\n", + "rho=0.075#density of air\n", + "meu=1.21e-5#viscosity of air\n", + "R_e=D*rho*v_air_s/meu#reynolds no\n", + "print \"\\n reynolds no. R_e=%.2f \"%(R_e)#\n", + "f=0.003#/fanning friction factor,since R_e >20000\n", + "L=400#duct length\n", + "g_c=32.2#grav. acc.\n", + "P_drop_d=(4*f*L*v_air_s**2*rho)/(2*g_c*D)#pressure drop in the duct\n", + "print \"\\n pressure drop in duct P_drop_d=%.2f lbf/ft**2\"%(P_drop_d)#\n", + "P_drop_h=0.5*5.2#pressure drop in hood\n", + "P_drop_cyc=3.5*5.2#pressure drop in cyclone cleaner\n", + "P_drop_t=P_drop_d + P_drop_h + P_drop_cyc#total prssure drop\n", + "print \"\\n total pressure drop P_drop_t=%.2f lbf/ft**2\"%(P_drop_t)#\n", + "neta=0.4#pump efficiency\n", + "hp=(P_drop_t*q/neta)*3.03e-5#power required in hp\n", + "print \"\\n power required hp=%.2f hp \"%(hp)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 29.6 Page no 458" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 29.6 page no 458\n", + "\n", + "\n", + "\n", + " penetration associated with failed bags P_tc=0.07 \n", + "\n", + " no. of bags L=1.52 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 29.6 page no 458\\n\\n\"\n", + "#a baghouse has been used to clean a particulate gas steam\n", + "l_i=5#inlet loading,grains/ft**3\n", + "l_o=0.03#outlet loading,grains/ft**3\n", + "l_o_max=0.4#maximum outlet loading,grains/ft**3\n", + "E_b=(l_i-l_o)/l_i#efficiency before bag failure\n", + "P_t=1-E_b#penetration before bag failure\n", + "E=(l_i-l_o_max)/l_i#efficiency on regulatory conditions\n", + "P_t_r=1-E#penetration regulatory conditons\n", + "P_tc=P_t_r-P_t#penetration associated with failed bags\n", + "print \"\\n penetration associated with failed bags P_tc=%.2f \"%(P_tc)#\n", + "P_drop=6#pressure drop,in of H2O\n", + "T=250#temperature,deg F\n", + "q=50000#volumetric flow rate,acfm\n", + "D=8#diamter of bags,in\n", + "L= q*P_tc/(0.582*P_drop**0.5*D**2*(T+460)**0.5)#number of bag failure that the system can tolerate and still remain in compliance\n", + "print \"\\n no. of bags L=%.2f \"%(L)#\n", + "#thus if two bags fail,baghouse is out of complance" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 29.7 Page no 461" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 29.7 page no 461\n", + "\n", + "\n", + "\n", + " n_air=45444.92 gmol\n", + "\n", + " mole fraction of HC x_hc=16503.22 ppb \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 29.7 page no 461\\n\\n\"\n", + "#a reactor is located in a relatively large laboratory,the reactor can emit as much as of hydrocarbon into the room if a safety valves ruptures\n", + "v=1100#volume of reactor,m**3\n", + "T=295#temperature of reactor,K\n", + "v_s=0.0224#volume of gas at STP,m**3\n", + "T_s=273#standard temperature,K\n", + "n_air=(v/v_s)*(T_s/T)#total gmoles of air in the room\n", + "print \"\\n n_air=%.2f gmol\"%(n_air)#\n", + "v_r=0.75#Hydrocarbon emit by reactor,gmol\n", + "x_hc= (v_r/(n_air + v_r))*10**9#mole fraction of hydrocarbon in the room,parts per billion \n", + "print \"\\n mole fraction of HC x_hc=%.2f ppb \"%(x_hc)# \n", + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-2_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-2_1.ipynb new file mode 100644 index 00000000..b7c88ff9 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-2_1.ipynb @@ -0,0 +1,195 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 2 : Unit and Dimensions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1(1) Page no.10" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 2.1(1) Page no. 10\n", + "\n", + "\n", + "8.03 yr =a\n", + "\n", + "\n", + "8.03 yr is 253234080.00 seconds \n", + "\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 2.1(1) Page no. 10\\n\\n\"\n", + "#convert 8.03 yr to seconds\n", + "print \"8.03 yr =a\\n\\n\"\n", + "yr=365#day\n", + "day=24#h\n", + "h=60#min\n", + "Min=60#second\n", + "a=8.03*365*24*60*60\n", + "print \"8.03 yr is %0.2f seconds \\n\\n\"%(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1(2) Page no. 10" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 2.1(2) Page no.10\n", + "\n", + "\n", + "150 mile/h =x\n", + "\n", + "\n", + "150 mile/h is 264000.00 yd/h\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 2.1(2) Page no.10\\n\\n\"\n", + "#convert 150 mile/h to yard/h\n", + "print \"150 mile/h =x\\n\\n\"\n", + "mile=5280.0#ft\n", + "ft=(1/3)#yd\n", + "x=150*5280*(1.0/3)\n", + "print \"150 mile/h is %0.2f yd/h\\n\"%(x)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1(3) Page no. 10" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 2.1(3) Page no. 10\n", + "\n", + "\n", + "100 m/s**2 =a\n", + "\n", + "\n", + "100 m/s**2 is 1181102.36 ft/min**2\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 2.1(3) Page no. 10\\n\\n\"\n", + "#convert 100 m/s**2 to ft/min**2\n", + "print \"100 m/s**2 =a\\n\\n\"\n", + "m =100#cm\n", + "cm=(1/30.48)#ft\n", + "min=60#sec\n", + "a=100*100*(1/30.48)*(60)**2\n", + "print \"100 m/s**2 is %0.2f ft/min**2\\n\"%(a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 2.1(4) Page no. 10" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 2.1(4) Page no.10\n", + "\n", + " \n", + "0.03g/cm**3 =x\n", + "\n", + "0.03g/cm**3 is 1.87 lb/ft**3\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 2.1(4) Page no.10\\n\\n \"\n", + "#convert 0.03g/cm**3 to lb/ft**3\n", + "print \"0.03g/cm**3 =x\\n\"\n", + "g=(1/454)#lb\n", + "ft=(30.48)**3#cm**3\n", + "x=0.03*(1.0/454)*(30.48)**3\n", + "print \"0.03g/cm**3 is %0.2f lb/ft**3\\n\"%(x)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-31_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-31_1.ipynb new file mode 100644 index 00000000..7dbac152 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-31_1.ipynb @@ -0,0 +1,213 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 31 : Numerical Methods" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 31.1 Page no 486" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 31.1 Page no 486\n", + "\n", + " \n", + "\n", + " X= \n", + "[[ 5.]\n", + " [ 3.]\n", + " [-2.]]\n", + "\n", + "X1=5.00\n", + "X2=3.00 \n", + "X3=-2.00\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import mat\n", + "print \"Example 31.1 Page no 486\\n\\n \"\n", + "#set of linear algebric equation using gauss elimination\n", + "A=mat([[3,-2,1],[1,4,-2],[2,-3,-4]])#matrix A\n", + "B=mat([[7],[21],[9]])#matrix B\n", + "X=(A**-1)*B\n", + "print \"\\n X= \\n\",(X)#\n", + "X1=X[0]#value of X1\n", + "X2=X[1]#value of X2\n", + "X3=X[2]#value of X3\n", + "print \"\\nX1=%.2f\\nX2=%.2f \\nX3=%.2f\"%(X1,X2,X3)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 31.2 Page no 492" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 31.2 Page no 492\n", + "\n", + "\n", + "\n", + " T1=1.10 k\n", + "\n", + " T2=1.01 k\n", + "\n", + " T3=1.00 k\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 31.2 Page no 492\\n\\n\"\n", + "#the vapor pressure p' for a new synthetic chemical at a given temperature\n", + "t1=1100#assume intial actual temperature,k\n", + "T1=t1*1e-3#temperature,k\n", + "print \"\\n T1=%.2f k\"%(T1)#\n", + "f1=T1**3 -2*T1**2 + 2*T1 -1#function of T,f(T)\n", + "f_d1=3*T1**2 -4*T1 + 2#derivative of f(T)\n", + "#using newton rapson formula to estimate T2\n", + "T2=T1 -(f1/f_d1)#temperature T2\n", + "print \"\\n T2=%.2f k\"%(T2)#\n", + "f2=T2**3 -2*T2**2 + 2*T2 -1\n", + "f_d2=3*T2**2 -4*T2 + 2\n", + "T3=T2 -(f2/f_d2)#temperature T3\n", + "print \"\\n T3=%.2f k\"%(T3)#\n", + "#finally the best estimate is T3,t=1.000095" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 31.3 Page no 493" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 31.3 Page no 493\n", + "\n", + "\n", + "\n", + " v6=10.09 ft/s \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from sympy import symbols, solve\n", + "print \"Example 31.3 Page no 493\\n\\n\"\n", + "#friction factor for smooth tubes can be approximated by\n", + "#f = 0.079*R_e**(-1/4),if 2000< R_e<2e-5\n", + "# average velocity in the system ,involving the flow of water at 60 deg F is given by \n", + "#v =sqrt(2180/(213.4R_e**(-1/4) + 10), flow of water at 60 deg F\n", + "#R_e=12168v,putting this value and by simplifying we get\n", + "v=symbols('v')\n", + "f=213.5*v**2 +105.03*v- 22896.08*v\n", + "#df=derivat(213.5*v**2 +105.03*v- 22896.08*v)\n", + "df=- 22791.05 + 427*v \n", + "v1=5\n", + "f1=213.5*v1**2 +105.03*v1- 22896.08*v1# value of f at v=5\n", + "df1=- 22791.05 + 427*v1#value of df at v=5\n", + "v2=v1-(f1/df1)\n", + "#by iteration we get values of v3,v4,v5,v6\n", + "#at v6 result converges\n", + "v6=10.09\n", + "print \"\\n v6=%.2f ft/s \"%(v6)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 31.4 Page no 497" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 31.4 Page no 497\n", + "\n", + "\n", + "\n", + " I=0.90 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from sympy import mpmath\n", + "print \"Example 31.4 Page no 497\\n\\n\"\n", + "#integration\n", + "I=mpmath.quad(lambda x:(1-0.4*x**2)/((1-x)*(1-0.4*x)-1.19*x**2),[0,0.468])\n", + "print \"\\n I=%.2f \"%(I)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-32_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-32_1.ipynb new file mode 100644 index 00000000..3afc5a63 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-32_1.ipynb @@ -0,0 +1,220 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 32 : Economics and Finance " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 32.5 Page no 512" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 32.5 page no 512\n", + "\n", + "\n", + "\n", + " total cost with 2 inch pipe TC_a=22112.00 $\n", + "\n", + " total cost with 4 inch pipe TC_b=13922.00 $\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 32.5 page no 512\\n\\n\"\n", + "# a fluid is transported 4 miles under turbulent flow conditions\n", + "#we have two choices in designing the system\n", + "OC_a=20000#per year pressure drop costs for the 2 inch ID pipe,$\n", + "CRF=0.1#capital recovery factor for both pipe\n", + "OC_b=OC_a/16#operating cost associated with the pressure drop cost per year for 4 inch pipe\n", + "d=4*5280#distance,feet\n", + "c_a=1# 2 inch ID pipe cost per feet,$\n", + "c_b=6# 4 inch ID pipe cost per feet,$\n", + "CC_a=d*c_a*CRF#capital cost for 2 inch ID pipe,$\n", + "CC_b=d*c_b*CRF#capital cost for 4 inch ID pipe,$\n", + "TC_a= OC_a +CC_a#total cost associated with 2 inch pipe\n", + "print \"\\n total cost with 2 inch pipe TC_a=%0.2f $\"%(TC_a)#\n", + "TC_b=OC_b + CC_b#total cost associated with 4 inch pipe\n", + "print \"\\n total cost with 4 inch pipe TC_b=%0.2f $\"%(TC_b)#\n", + "#from result we can conclude that 4 inch pipe is more economical" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 32.6 Page no 512" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 32.6 page no 512\n", + "\n", + "\n", + "\n", + " P1=54.46\n" + ] + } + ], + "source": [ + "from scipy.optimize import fsolve\n", + "from __future__ import division\n", + "print \" Example 32.6 page no 512\\n\\n\"\n", + "#a process emits gas of containg dust,a particulate device is employed for particle capture \n", + "q=50000#vol. flow rate of dust,ft**3/min\n", + "c=2/7000#inlet loading of dust\n", + "DV=0.03#value of dust\n", + "#recovered value RV can be expressed in terms of pressure drop\n", + "#RV=q*c*DV*P1/(P1+15)\n", + "C_e=0.18#cost of electricity\n", + "E_f=0.55#fractional efficiency\n", + "def f(P1):\n", + " \n", + " E=P1/(P1+15)#collection efficiency\n", + " RV=q*c*DV*E#recovered value in terms of E$/min\n", + " C_p=q*(C_e/44200)*P1/(E_f*60)\n", + "# x=q*c*DV*P1/(P1+15)-q*C_e*P1/E_f\n", + " x=RV-C_p \n", + " return x\n", + "P1=fsolve(f,100)\n", + "print \"\\n P1=%0.2f\"%(P1)#\n", + "#calculation mistake in book" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 32.8 Page no 514" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 32.8 page no 514\n", + "\n", + "\n", + "\n", + " uniform annual payment UAP=5767.91 $\n", + "\n", + " apprasial value B=26944.44 $\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 32.8 page no 514\\n\\n\"\n", + "#a filter press is in operation\n", + "#we have to determine the appraisal value of the press\n", + "i=0.03375#intrest on fund\n", + "n=9#time,year\n", + "SFDF=i/((1+i)**n -1)#sinking fund depreciation factor\n", + "P=60000#cost of filter press,$\n", + "L=500#salvage value,$\n", + "UAP= (P-L)*SFDF#uniform annual payment,$\n", + "print \"\\n uniform annual payment UAP=%0.2f $\"%(UAP)#\n", + "#in determing the appraisel value where the straight line method of depreciation is used \n", + "# B = P -(P-L/n)x\n", + "#where x refers to any time the present before the end of usable\n", + "x=5#let for 5 year\n", + "B5=P-((P-L)/n)*x#appraissl value for 5 year\n", + "print \"\\n apprasial value B=%0.2f $\"%(B5)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 32.9 Page no 516" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 32.9 page no 516\n", + "\n", + "\n", + "\n", + " annulized cost AC=51583.60 $\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 32.9 page no 516\\n\\n\"\n", + "#we have to determine the annulized cost of a new processing plant of enviromental control\n", + "#input data\n", + "CC=150000#capital cost,$\n", + "I=.07#interst\n", + "n=5#time,year\n", + "CRF=(I*(1+I)**n)/((1+I)**5-1)#capital recovery factor CRF\n", + "IC=CRF*CC#installation cost,$\n", + "OC=15000#operation cost,$\n", + "AC=IC + OC#annulized cost\n", + "print \"\\n annulized cost AC=%0.2f $\"%(AC)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-33_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-33_1.ipynb new file mode 100644 index 00000000..d8b44b5f --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-33_1.ipynb @@ -0,0 +1,400 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 33 : Biomedical Engineering " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.1 Page no 524" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.1 Page no 524\n", + "\n", + "\n", + "\n", + " viscosity meu_e=8.40e-04 lb/ft.s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 33.1 Page no 524\\n\\n\"\n", + "#unit conversion of viscosity of blood\n", + "meu_cp=1.25#vicosity of blood in cp\n", + "meu_e=meu_cp*6.72e-4#viscosity in english unit,lb/ft.s\n", + "print \"\\n viscosity meu_e=%0.2e lb/ft.s\"%(meu_e)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.2 Page no 525" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.2 Page no 525\n", + "\n", + "\n", + "\n", + " P1=3.15 inHg\n", + " P2=3.57 ft H2O\n", + "P3=42.83 in H2O\n", + " P4=1.55 psia\n", + "P5=222.74 psfa\n", + "P6=10663.16 N/m**2\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 33.2 Page no 525\\n\\n\"\n", + "#unit conversion of poressure given in mmHg into various units\n", + "P=80#pressure given in mmHg\n", + "P1=P*(29.92/760)#pressure , in Hg\n", + "P2=P*(33.91/760)#pressure ,ft H2O\n", + "P3=P2*12#pressure ,in H2O\n", + "P4=P*(14.7/760)#pressure ,psia\n", + "P5=P*(2116/760)#pressure ,psfa\n", + "P6=P*(1.013e+5/760)#pressure ,N/m**2\n", + "print \"\\n P1=%0.2f inHg\\n P2=%0.2f ft H2O\\nP3=%0.2f in H2O\\n P4=%0.2f psia\\nP5=%0.2f psfa\\nP6=%0.2f N/m**2\"%(P1,P2,P3,P4,P5,P6)##in book answers are round off after decimal but there are exact answers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.5 Page no 527" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.5 Page no 527\n", + "\n", + "\n", + "\n", + " ratio of diameters D_r=1.41 \n" + ] + } + ], + "source": [ + "from math import sqrt\n", + "from __future__ import division\n", + "print \"Example 33.5 Page no 527\\n\\n\"\n", + "#an artery branches into two smaller equal area arteries so that velocity is same\n", + "#because q1=q2,volumetric flow rate\n", + "#q1=q2=q/2\n", + "#because s1=s2,cross sectional area\n", + "#s1=s2=s/2\n", + "#let the values \n", + "q=1#flow rate at inlet artery \n", + "q1=q/2#flow rate at outlet artery\n", + "s=1#area of inlet artery\n", + "s1=s/2#area of outlet artery\n", + "#v=q/s\n", + "D_r=sqrt(q/q1)#ratio of diameters\n", + "print \"\\n ratio of diameters D_r=%0.2f \"%(D_r)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.6 Page no 528" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.6 Page no 528\n", + "\n", + "\n", + "\n", + " velocity v3=4.52 mm/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 33.6 Page no 528\\n\\n\"\n", + "#a blood vessel branches into three openings \n", + "#we have to find the velocity in 3 rd opening\n", + "a=0.2#cross sectional area of inlet 1,m**2\n", + "v=5#velocity inlet 1,mm/s\n", + "a1=0.08#area of branch1,m**2\n", + "v1=7#velocity in branch2,mm/s\n", + "a2=0.025#area of branch,m**2\n", + "v2=12#velocity in branch,mm/s\n", + "a3=0.031#area of branch,m**2\n", + "q=a*v#flow rate at inlet\n", + "q1=a1*v1#flow rate at branch 1\n", + "q2=a2*v2#flow rate at branch 2\n", + "q3=q-q1-q2#flow rate in branch 3\n", + "v3=q3/a3#velocity in branch 3\n", + "print \"\\n velocity v3=%0.2f mm/s\"%(v3)#\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.7 Page no 531" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.7 Page no 531\n", + "\n", + "\n", + "\n", + " flow velocity v=19.01 cm/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 33.7 Page no 531\\n\\n\"\n", + "#blood flowing through the arota\n", + "D=2.5#diameter of arota\n", + "S=pi*D**2/4#cross sectional area,cm**2\n", + "q=93.3#volumeric flow rate,cm**3/s\n", + "v=q/S#flow velocity\n", + "print \"\\n flow velocity v=%0.2f cm/s\"%(v)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.8 Page no 531" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.8 Page no 531\n", + "\n", + "\n", + "\n", + " no.of times heart beats T=3.11e+09 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 33.8 Page no 531\\n\\n\"\n", + "#one of the auther of this book is 74 year old ,we have to determine the no. of times that the the auther's heart has to beat to date\n", + "Y=74#age in year\n", + "d=365#days\n", + "h=24#hours\n", + "m=60#minutes\n", + "b=80#heart beats per minutes\n", + "T=Y*d*h*m*b# no. of times heart beats\n", + "print \"\\n no.of times heart beats T=%0.2e \"%(T)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.9 Page no 531" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 33.9 Page no 531\n", + "\n", + "\n", + "\n", + " Volume of blood V=2.18e+11 ml\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 33.9 Page no 531\\n\\n\"\n", + "#refer to example no 33.8\n", + "Y=74#age in year\n", + "d=365#days\n", + "h=24#hours\n", + "m=60#minutes\n", + "b=80#heart beats per minutes\n", + "T=Y*d*h*m*b# no. of times heart beats\n", + "v=70#volume of blood discharge with each blood,ml\n", + "V=T*v#volume of blood that has circulated through the auther's system over his lifetime\n", + "print \"\\n Volume of blood V=%0.2e ml\"%(V)# " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.10 Page no 532" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 33.10 Page no 532\n", + "\n", + "\n", + "\n", + " pressure drop P_drop=1.69 ft*lbf/lb\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 33.10 Page no 532\\n\\n\"\n", + "#the flow of blood from the arota to the atrium is reprsented by a vessel\n", + "meu=1.1*6.72e-4#viscosity of blood\n", + "L=0.3#length of vessel,mile\n", + "g_c=32.2#grav. acc\n", + "rho=62.4#density of blood \n", + "D=2.53/30.48#diameter of vessel,ft\n", + "P_drop=32*meu*(19/30.48)*5280*L/(rho*D**2*g_c)\n", + "print \"\\n pressure drop P_drop=%0.2f ft*lbf/lb\"%(P_drop)\n", + "#since the model is resonable from the fluid dynamics perspective" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 33.12 Page no 534" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + " Example 33.12 Page no 534\n", + "\n", + "\n", + "\n", + "power generated hp=0.55 hp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"\\n Example 33.12 Page no 534\\n\\n\"\n", + "#estimation of power generated by human heart\n", + "P_drop=60#pressure drop in the circulatory system,mmHg\n", + "q=0.0033#volumetric flow rate,ft**3/s\n", + "hp=(q*P_drop*14.7*(144/760))#power generated \n", + "print \"\\npower generated hp=%0.2f hp\"%(hp)##calculation error in book" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-34_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-34_1.ipynb new file mode 100644 index 00000000..d81ca764 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-34_1.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 34 : Open Ended Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 34.4 Page no 548" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 34.4 page no 548\n", + "\n", + "\n", + "\n", + " KE=990.13 ft.lbf/s\n" + ] + } + ], + "source": [ + "print \"Example 34.4 page no 548\\n\\n\"\n", + "#a gas stream is discharged through a stack\n", + "m_dot =10000#mass flow ratein acfm\n", + "v=50#velcoity in ft/s\n", + "KE=m_dot*v**2*(29/(379*32.2*60))#others are conversion factor for unit\n", + "print \"\\n KE=%.2f ft.lbf/s\"%(KE)##printing mistake in book" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-3_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-3_1.ipynb new file mode 100644 index 00000000..a4fff30a --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-3_1.ipynb @@ -0,0 +1,229 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 3 : Key Terms and Definitions" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.2 Page no. 25" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 3.2 Page no. 25\n", + "\n", + "\n", + "surface tension=0.07N/m\n", + " Radius = 4.00e-03 m\n", + " theta = 0 degree\n", + " g=9.81m/s**2\n", + " rho=1000.00kg/m**3\n", + "\n", + "height of liquid rise = 3.63e-03 m\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import cos\n", + "print \"Example 3.2 Page no. 25\\n\\n\"\n", + "#given temperature(T),pressure(P),capilLary tube diameter(D),water density(rho),contact angle(ththetaeta)\n", + "sigma=0.0712#surface tension (sigma)of water at 30 degree C temperature in appendix A.4\n", + "D=0.008\n", + "R=D/2\n", + "theta=0\n", + "g=9.807\n", + "rho=1000\n", + "print \"surface tension=%0.2fN/m\\n Radius = %0.2e m\\n theta = %0.f degree\\n g=%0.2fm/s**2\\n rho=%0.2fkg/m**3\\n\"%(sigma,R,theta,g,rho)\n", + "h=(2.0*sigma*cos(0))/(rho*g*R)#height rise of the liquid\n", + "print \"height of liquid rise = %0.2e m\\n\"%(h)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.3 Page no. 26" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 3.3 Page no. 26\n", + "\n", + "\n", + "rho=996.00\\kg/m**3\n", + " surface tension (sigma)=0.07 N/m\n", + "\n", + "theta=0.00 degree \n", + " g=9.81 m/s**2\n", + " h=0.001 m\n", + "\n", + "R=0.015 m\n", + " D=0.029 m\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import cos\n", + "print \"Example 3.3 Page no. 26\\n\\n\"\n", + "#given at 30 degree temerature\n", + "#properties of water from appendix A.2 density(rho),surface tension(sigma)\n", + "rho=996\n", + "sigma=0.071\n", + "print \"rho=%0.2f\\kg/m**3\\n surface tension (sigma)=%0.2f N/m\\n\"%(rho,sigma)\n", + "theta=0#negligible angle of contact\n", + "g=9.807\n", + "h=0.001#less than one milimeter\n", + "print \"theta=%0.2f degree \\n g=%0.2f m/s**2\\n h=%0.3f m\\n\"%(theta,g,h)\n", + "R=(2*sigma*cos(0))/(rho*g*h)#by capiilary rise equation\n", + "D=2*R\n", + "print \"R=%0.3f m\\n D=%0.3f m\\n\"%(R,D)\n", + "#if the tube diameter is greater than 0.029075 mm, then the capillary rise will be less than 1mm" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.4 Page no. 28" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 3.4 page no 28\n", + "\n", + "\n", + "\n", + " F_p=8.66 lbf\n", + "\n", + " F-n=5.00 lbf\n", + "\n", + " tou=4.33 psf\n", + " P=2.50 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi, sin,cos\n", + "print \"Example 3.4 page no 28\\n\\n\"#\n", + "S=2#surface area ft**2\n", + "F=10#magnitude of force,lbf\n", + "theta=pi/6#angle\n", + "F_p=F*cos(theta)#parallel comp. of force\n", + "print \"\\n F_p=%0.2f lbf\"%(F_p)#\n", + "F_n=F*sin(theta)#normal comp. of force\n", + "print \"\\n F-n=%0.2f lbf\"%(F_n)#\n", + "tou=F_p/S#shear stress\n", + "P=F_n/S#pressure\n", + "print \"\\n tou=%0.2f psf\\n P=%0.2f psf\"%(tou,P)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 3.5 Page no. 30" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 3.5 Page no. 30\n", + "\n", + "\n", + "m=1.00 kg\n", + " g=9.80 m/s**2\n", + " Z1=0.00 m\n", + " Z2=10.00 m\n", + "\n", + "PE1=0J\n", + " PE2=98.00J\n", + " PE=98.00J\n", + "\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 3.5 Page no. 30\\n\\n\"\n", + "#determine potential energy of water \n", + "# given height,mass of water,g\n", + "m=1\n", + "g=9.8\n", + "Z1=0#at ground level\n", + "Z2=10#at 10 m above from ground level\n", + "print \"m=%0.2f kg\\n g=%0.2f m/s**2\\n Z1=%0.2f m\\n Z2=%0.2f m\\n\"%(m,g,Z1,Z2)\n", + "PE1=m*g*Z1#potential energy at ground level\n", + "PE2=m*g*Z2#potential energy at 10m height\n", + "PE= PE2-PE1\n", + "print \"PE1=%0.fJ\\n PE2=%0.2fJ\\n PE=%0.2fJ\\n\"%(PE1,PE2,PE)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-5_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-5_1.ipynb new file mode 100644 index 00000000..cc974020 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-5_1.ipynb @@ -0,0 +1,186 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 5 : Newtonian Fluids" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.2 page no. 42" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 5.2 page no 42\n", + "\n", + "\n", + "given \n", + " kinamatic viscosity =1.660000 ft**2/hr\n", + " rho=0.080000 lb/ft**3\n", + " d=0.083300 ft\n", + " v1=300.00 ft/hr\n", + " v2=0.000e+00 ft/hr\n", + " gc=4.170e+08 (ft*lb/hr)/lbf*hr\n", + "\n", + " force tou_xy=1.147e-06 lbf/ft**2\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 5.2 page no 42\\n\\n\"\n", + "#To calculate the force to maintain movement of left plate \n", + "#velocity of moving plate is equal to the velocity of the plate and velocity of the gas at the surface of the stationary plate is zero\n", + "k=1.66#kinamatic viscosity of gas\n", + "rho=0.08#density of gas\n", + "d=0.0833#distance between plate\n", + "v1=300#velocity of left plate\n", + "v2=0#velocity of stationary plate\n", + "g_c=4.17*10**(8)#gravitational constant\n", + "print \"given \\n kinamatic viscosity =%2f ft**2/hr\\n rho=%2f lb/ft**3\\n d=%4f ft\\n v1=%0.2f ft/hr\\n v2=%0.3e ft/hr\\n gc=%0.3e (ft*lb/hr)/lbf*hr\"%(k,rho,d,v1,v2,g_c)#\n", + "tou_xy=-k*rho*((v2-v1)/(g_c*d))#the frce necessary to mantain the movement of the left plate\n", + "print \"\\n force tou_xy=%0.3e lbf/ft**2\"%(tou_xy)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.3 Page no. 45" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 5.3 page no. 45\n", + "\n", + "\n", + "Given :\n", + " diameter =0.25 ft\n", + " height =0.500 ft\n", + " Torque=15.300 ft.lbf\n", + "\n", + " force =122.400 lbf\n", + "\n", + " shear stress tou=311.689 psf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import pi\n", + "print \"Example 5.3 page no. 45\\n\\n\"\n", + "D=0.25#diameter of fixed inner cylinder of viscometer\n", + "L=0.5#height of fixed inner cylinder of viscometer\n", + "T=15.3#measured torque\n", + "print \"Given :\\n diameter =%.2f ft\\n height =%0.3f ft\\n Torque=%0.3f ft.lbf\"%(D,L,T)#\n", + "F=(2*T)/D\n", + "print \"\\n force =%0.3f lbf\"%(F)#\n", + "#the shear stress(force parallel to the surface) using equation 5.11\n", + "tou=F/(pi*D*L)\n", + "print \"\\n shear stress tou=%0.3f psf\"%( tou)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 5.4 page no. 45" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 5.4 page no. 45\n", + "\n", + "\n", + "\n", + " omega=26.200 rad/s\n", + " diameter D =0.250 ft\n", + " linear velocity =3.275000 ft/s\n", + "\n", + " clearance d=0.001000 ft\n", + " vel. gradient=39300.000 1/s\n", + " gravitational constant gc=32.140000 ft/s*S\n", + "\n", + " tou=311.700 psf\n", + " meu=0.255 lb/ft*s\n", + "\n", + " kinematic viscosity=0.004211 (ft*ft)/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 5.4 page no. 45\\n\\n\"\n", + "#refer to example no 5.3\n", + "#determine dynamic viscosity and kinematic viscosity\n", + "omega=26.2#angular rotation speed \n", + "D=0.25#diameter of fixed inner cylinder of viscometer\n", + "v=omega*D/2\n", + "print \"\\n omega=%0.3f rad/s\\n diameter D =%0.3f ft\\n linear velocity =%2f ft/s\"%(omega,D,v)#\n", + "d=0.001#clearance betwween two cylinder of visometer\n", + "vel_gradient =v/(d/12)#velocity gradient\n", + "gc=32.14#gravitational constant\n", + "print \"\\n clearance d=%5f ft\\n vel. gradient=%0.3f 1/s\\n gravitational constant gc=%3f ft/s*S\"%(d,vel_gradient,gc)#\n", + "tou=311.7#shear stress tou\n", + "meu=gc*tou/vel_gradient\n", + "print \"\\n tou=%0.3f psf\\n meu=%0.3f lb/ft*s\"%(tou,meu)#\n", + "rho=60.528#density of oil\n", + "neu=meu/rho#kinamatic viscosity\n", + "print \"\\n kinematic viscosity=%5f (ft*ft)/s\"%(neu)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-7_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-7_1.ipynb new file mode 100644 index 00000000..2b43a1bd --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-7_1.ipynb @@ -0,0 +1,311 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 7 : Conservation Law for Mass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.1 Page no. 64" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "example no. 7.1 page no. 64\n", + "\n", + "\n", + "\n", + " Rf=4000.000 kg/hr\n", + " Ra=8000.000 kg/hr\n", + " Rm=550.000 kg/hr\n", + " Rin=12550.000 kg/hr\n", + " Rout=12550.000 kg/hr\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"example no. 7.1 page no. 64\\n\\n\"\n", + "#applying coservation of mass\n", + "# rate of mass in-rate of mass out+rate of mass generated=rate of mass accumlated\n", + "#according to conditions in this example\n", + "#rate of mass in = rate of mass out\n", + "Rf=4000#rate of feed of gaseous waste into an incinerator\n", + "Ra=8000#rate of air feed\n", + "Rm=550#rate of methane added for combustion\n", + "Rin=Rf+Ra+Rm#total rate of mass in\n", + "Rout=Rin#Rout is rate of mass out\n", + "print \"\\n Rf=%0.3f kg/hr\\n Ra=%0.3f kg/hr\\n Rm=%0.3f kg/hr\\n Rin=%0.3f kg/hr\\n Rout=%0.3f kg/hr\"%(Rf,Ra,Rm,Rin,Rout)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.2 Page no. 65" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 7.2 page no. 65\n", + "\n", + "\n", + "\n", + " diameter D1=0.140 m\n", + " diameter D2=0.070 m\n", + " v1=2.000 m/s\n", + " Surface area S1=0.015 m**2\n", + " density of water rho=1000.000 kg/m**3 \n", + "\n", + " volumatric flow rate q1=0.031 m**3/s\n", + " mass flow ratem1=30.788 kg/s\n", + " mass flux G=2000.000 kg/m**2*s\n", + "\n", + " surface areaS1=0.015 m**2\n", + " volumatric flow rate q2=0.031 m**3/s\n", + "\n", + " velocity v2=8.000 m/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 7.2 page no. 65\\n\\n\"\n", + "#water flowing through a converging circular pipe fig 7.3\n", + "#we have to determine mass and volumatric flow rates, mass flux of water \n", + "D1=.14# diameter of pipe at section 1\n", + "D2=.07#diameter of pipe at section2\n", + "v1=2#velocity at section\n", + "S1=pi*(D1**2)/4#surface area at section 1\n", + "rho=1000#density of water\n", + "print \"\\n diameter D1=%0.3f m\\n diameter D2=%0.3f m\\n v1=%0.3f m/s\\n Surface area S1=%0.3f m**2\\n density of water rho=%0.3f kg/m**3 \"%(D1,D2,v1,S1,rho)# \n", + "q1= S1*v1#volumatric flow rate at section 1\n", + "m1=rho*q1#mass flow rate at section 1\n", + "G=m1/S1#mass flux at section 1\n", + "print \"\\n volumatric flow rate q1=%0.3f m**3/s\\n mass flow ratem1=%0.3f kg/s\\n mass flux G=%0.3f kg/m**2*s\"%(q1,m1,G)#\n", + "S2=(pi*D2**2)/4\n", + "q2=q1#q2 volumatric flow rate at section 2,due to steady flow q1=q2\n", + "print \"\\n surface areaS1=%0.3f m**2\\n volumatric flow rate q2=%0.3f m**3/s\"%(S1,q1)\n", + "v2=(v1*S1)/S2#v2 velocity at section 2\n", + "print \"\\n velocity v2=%0.3f m/s\"%(v2)\n", + "#conclusion :decrease cross section area results in an increase in flow velocity for an incompressible fluid. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.3 Page no 66" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 7.3 page no 66,fig 7.4\n", + "\n", + "\n", + "\n", + "\n", + " velocity v1=5.000 m/s \n", + " surface area S1=0.200 m**2/s\n", + " velocity v2=7.000 m/s\n", + " surface area S2=0.300 m**2/s\n", + " velocity v3=12.000 m/s\n", + " surface area S3=0.250 m**2/s\n", + " surface area S4=0.150 m**2/s\n", + "\n", + " volumatric flow rate q1=1.000 m**3/s\n", + " volumatric flow rate q2=2.100 m**3/s\n", + " volumatrisc flow rate q3=3.000 m**3/s\n", + "\n", + " volumatric flow rate q4=0.100 m**3/s\n", + " velocity v4=0.667 m/s \n", + "\n", + " mass flow rate m=80.000 kg/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 7.3 page no 66,fig 7.4\\n\\n\\n\"\n", + "#fluid device has four openings as shoen in figure\n", + "#we have to calculate magnitude and direction of velocity,mass flow rate at section 4\n", + "rho=800#density of fluid \n", + "v1=5#velocity at section 1\n", + "S1=0.2#surface area at section 1\n", + "v2=7#velocity at section 2\n", + "S2=0.3#surface area at section 2\n", + "v3=12#velocity at section 3\n", + "S3=0.25#surface area at section 3\n", + "S4=0.15#surface area at section 4\n", + "print \"\\n velocity v1=%0.3f m/s \\n surface area S1=%0.3f m**2/s\\n velocity v2=%0.3f m/s\\n surface area S2=%0.3f m**2/s\\n velocity v3=%0.3f m/s\\n surface area S3=%0.3f m**2/s\\n surface area S4=%0.3f m**2/s\"%(v1,S1,v2,S2,v3,S3,S4)#\n", + "q1=v1*S1#volumatric flow rate at section 1\n", + "q2=v2*S2#volumatric flow rate at section 2\n", + "q3=v3*S3#volumatric flow rate at section 3\n", + "print \"\\n volumatric flow rate q1=%0.3f m**3/s\\n volumatric flow rate q2=%0.3f m**3/s\\n volumatrisc flow rate q3=%0.3f m**3/s\"%(q1,q2,q3)#\n", + "#applying continuity equation\n", + "q4=q1+q2-q3#volumatric flow rate at section 4\n", + "v4=q4/S4#velocity at section 4\n", + "print \"\\n volumatric flow rate q4=%0.3f m**3/s\\n velocity v4=%0.3f m/s \"%(q4,v4)#\n", + "m=rho*q4#mass flow rate at section 4\n", + "print \"\\n mass flow rate m=%0.3f kg/s\"%(m)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.4 Page no 67" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 7.4 page no,fig 7.5\n", + "\n", + "\n", + "\n", + "\n", + " calculation:\n", + " calculation of liquid bypassed B=0.0833 \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from sympy import symbols, solve\n", + "print \"Example 7.4 page no,fig 7.5\\n\\n\"\n", + "#Given pollutant in ppm in liquid stream ,some pollutant in discharge volume \n", + "#calculate what fraction of liquid bypass\n", + "#liquid stream having 600 ppm pollutant\n", + "#pollutant in the discharge stream is 50 ppm\n", + "#if B =factio of liquid bypassed,then 1-B= fraction of liquid treated\n", + "#performing a pollutant mass balance around point2 in fig. 7.5\n", + "#B=poly([0],'x')#\n", + "B=symbols('x')\n", + "N=solve((1-B)*0+600*B-50*1,B)\n", + "print \"\\n\\n calculation:\\n calculation of liquid bypassed B=%.4f \"%N[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 7.5 Page no 67" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 7.5 page no 67\n", + "\n", + "\n", + "\n", + " diameter at inlet d1=0.090 m\n", + " volumatric flow rate at inlet q_in=0.025 m**3/s\n", + " diameter d2=0.040 m\n", + " volumatric flow rate at outlet q_out=0.004 m**3/s\n", + "\n", + " volumatric flow in tank=0.022 m**3/s\n", + " diameter of tank D=1.400 m\n", + " surface area of tank S=1.539 m**2\n", + "\n", + " rate of water level rise R_z=0.014 m/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "print \"Example 7.5 page no 67\\n\\n\"\n", + "#water flow in tank inletand outlet pipes\n", + "#applying continuity principle to the control volume\n", + "#since generation rate =0\n", + "d1=0.09#diameter of inlet pipe\n", + "v_in=4#velocity,m/s\n", + "v_out=3#velocity,m/s\n", + "q_in=(pi*d1**2)*v_in/4#volumatric flow rate at inlet \n", + "d2=0.04#diameter of outlet pipe\n", + "q_out=(pi*d2**2)*v_out/4\n", + "print \"\\n diameter at inlet d1=%0.3f m\\n volumatric flow rate at inlet q_in=%0.3f m**3/s\\n diameter d2=%0.3f m\\n volumatric flow rate at outlet q_out=%0.3f m**3/s\"%(d1,q_in,d2,q_out)#\n", + "q=q_in-q_out#for an incmpressible fluid of volume v, q=(dv/dt)=q_in-q_out\n", + "D=1.4#diameter of tank\n", + "S=(pi*D**2)/4\n", + "print \"\\n volumatric flow in tank=%0.3f m**3/s\\n diameter of tank D=%0.3f m\\n surface area of tank S=%0.3f m**2\"%( q,D,S)#\n", + "#z=fluid height\n", + "R_z=(q_in-q_out)/S#R_z rate of water level rise\n", + "print \"\\n rate of water level rise R_z=%0.3f m/s\"%(R_z)#\n", + "#R_z is positive ,the water level is rising in the tank from it's initial height of 1.5 m" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-8_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-8_1.ipynb new file mode 100644 index 00000000..88520cfd --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-8_1.ipynb @@ -0,0 +1,192 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 8 : Conservation Law of Energy" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.1 Page no 75" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 8.1 page no 75\n", + "\n", + "\n", + "\n", + " heat capacity Cp=1090.000 J/kg.deg c\n", + " mass flow rate M_dot=9.000 kg/s\n", + " gas inlet temperature T1=650.000 deg c\n", + " heat transferred Q=5500000.000 W\n", + "\n", + " temperature T2=89 deg c \n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 8.1 page no 75\\n\\n\"\n", + "# heat is transferred from a gas \n", + "Cp=1090#average heat capacity of gas\n", + "M_dot=9#mass flow rate \n", + "T1=650#gas inlet temperature\n", + "#kinetic and potential enargy effects are neglected,there is no shaft work\n", + "Q=5.5e+6#heat transferred\n", + "delta_H=Q#since there are no kinetic,potential,and shaft work effects\n", + "print \"\\n heat capacity Cp=%0.3f J/kg.deg c\\n mass flow rate M_dot=%0.3f kg/s\\n gas inlet temperature T1=%0.3f deg c\\n heat transferred Q=%0.3f W\"%(Cp,M_dot,T1,Q)#\n", + "T2=round(-Q/(M_dot*Cp)) + T1\n", + "print \"\\n temperature T2=%0.f deg c \"%(T2)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.2 Page no 77 " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 8.2 page no 77 fig 8.2 \n", + "\n", + "\n", + "\n", + "\n", + " flow rate q1=8.000 m**3/s\n", + " flow rate q2=6.000 m**3/s\n", + " flow rate q3=14.000 m**3/s\n", + " enthalpy h1=250.000 j/kg\n", + " enthalpy h2=150.000 j/kg\n", + " enthalpy h3=200.000 j/kg\n", + " density of fluid rho=800.000 kg/m**3\n", + "\n", + " enthalpy H=107.239 hp\n", + "\n", + " work W_dot=107.239 hp\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 8.2 page no 77 fig 8.2 \\n\\n\\n\"\n", + "#fluid flow in a device\n", + "#fluid flow with in the control volume is steady\n", + "q1=8#flow rate at section 1,direction in\n", + "q2=6#flow rate at section 2, direction in\n", + "q3=14#flow rate at section 3,direction out\n", + "h1=250#enthalpy at section 1\n", + "h2=150#enthalpy at section 2\n", + "h3=200#enthalpy at section 3\n", + "rho=800#density of fluid\n", + "print \"\\n flow rate q1=%0.3f m**3/s\\n flow rate q2=%0.3f m**3/s\\n flow rate q3=%0.3f m**3/s\\n enthalpy h1=%0.3f j/kg\\n enthalpy h2=%0.3f j/kg\\n enthalpy h3=%0.3f j/kg\\n density of fluid rho=%0.3f kg/m**3\"%(q1,q2,q3,h1,h2,h3,rho)#\n", + "#applying total energy balance\n", + "hp=746#1 hp=746 kw\n", + "H=rho*(q1*h1+q2*h2-q3*h3)/hp\n", + "print \"\\n enthalpy H=%0.3f hp\"%(H)#\n", + "#for adiabatic steady operation, Q_dot=0\n", + "W_dot=H#W_dot is work \n", + "print \"\\n work W_dot=%0.3f hp\"%(W_dot)#\n", + "#since work is positive ,the surroundings must be doing work on the system through some device" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 8.5 Page no 81" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Example 8.5 page no 81 fig 8.3\n", + "\n", + "\n", + "\n", + "\n", + " elevation head at section 1 z1=9.000 m\n", + " height at section h2=1.000 m\n", + " diameter of cylindrical tank D1=3.000 m\n", + " diameter of outlet hole of tank D2=0.300 m\n", + " gravitational acc. g=9.807 m/s**2\n", + "\n", + " time t=90.319 sec\n", + "\n", + " x=-0.010\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \" Example 8.5 page no 81 fig 8.3\\n\\n\\n\"\n", + "#a cylindrical tank filled with water\n", + "#applying bernoulli equation\n", + "z1=9#elevation head at section 1\n", + "h2=1#height at section 2\n", + "D1=3#diameter of cylindrical tank \n", + "D2=.3#diameter of outlet hole of tank\n", + "g=9.807#gravitational acceleration\n", + "print \"\\n elevation head at section 1 z1=%0.3f m\\n height at section h2=%0.3f m\\n diameter of cylindrical tank D1=%0.3f m\\n diameter of outlet hole of tank D2=%0.3f m\\n gravitational acc. g=%0.3f m/s**2\"%(z1,h2,D1,D2,g)#\n", + "t=2*((sqrt(z1)-sqrt(h2))/((sqrt(2*g))*(D2/D1)**2))\n", + "print \"\\n time t=%0.3f sec\"%(t)#\n", + "x=-(D2/D1)**2#ratio of a/g\n", + "print \"\\n x=%0.3f\"%(x)#\n", + "#for this example the maximum acceleration is 1% of g,therefore saftey use Bernoulli equation " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-9_1.ipynb b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-9_1.ipynb new file mode 100644 index 00000000..3b9e899c --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/Chapter-9_1.ipynb @@ -0,0 +1,282 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 9 : Conservation law for Momentum" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 9.1 Page no 87" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 9.1 page no 87\n", + "\n", + "\n", + "\n", + " density rho=62.400 lb/ft**3\n", + " horizontal velocity of water v=100.000 ft/s\n", + " flow rate q=0.500 ft**3/s\n", + "\n", + " momentum rate M_in=96.894 lbf\n", + "\n", + " net horizontal force F=-96.894 lbf\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "print \"Example 9.1 page no 87\\n\\n\"\n", + "#a horizontal water jet impinges on avertical plate\n", + "rho=62.4#density of water\n", + "v=100#horizontal velocity of water\n", + "q=0.5#flow rate\n", + "g=32.2#gravitational constant\n", + "print \"\\n density rho=%0.3f lb/ft**3\\n horizontal velocity of water v=%0.3f ft/s\\n flow rate q=%0.3f ft**3/s\"%(rho,v,q)#\n", + "M_in=(rho*q*v)/g#momentum rate of inlet water in the horizontal direction\n", + "print \"\\n momentum rate M_in=%0.3f lbf\"%(M_in)#\n", + "M_out=0#momentum rate of water out\n", + "F=M_out-M_in\n", + "print \"\\n net horizontal force F=%0.3f lbf\"%(F)#\n", + "#negative sign indicate that to hold the plate in place, a force must be exerted in a direction opposite to that of the water flow" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 9.2 Page no 87" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 9.2 page no 87\n", + "\n", + "\n", + "mass flow rate m_dot=0.150 kg/s\n", + " velocity in x direction V_in=420.000 m/s\n", + " velocity out in the x direction=0.000=m/s\n", + "\n", + " force F_x=-63.000 N\n", + "velocity in y dir V_in_y=0.000 m/s\n", + " velocity out y dir V_out_y=420.000 m/s\n", + "\n", + " force in y dir F_y=63.000 N\n", + "\n", + " resultant force F_res=89.095 N\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt\n", + "print \"Example 9.2 page no 87\\n\\n\"\n", + "#a horizontal line carries saturated steam\n", + "#water is entrained by the steam,and line is bend\n", + "#select the control volume as the fluid in the bend and apply amass balance\n", + "#since m1_dot=m2_dot,v1=v2\n", + "m_dot=0.15#mass flow rate\n", + "V_in_x=420#velocity in horizontal x direction\n", + "V_out_x=0#velocity out ,horizontal direction\n", + "print \"mass flow rate m_dot=%0.3f kg/s\\n velocity in x direction V_in=%0.3f m/s\\n velocity out in the x direction=%0.3f=m/s\"%(m_dot,V_in_x,V_out_x)#\n", + "#applying linear horizontal balance in x direction\n", + "F_x=m_dot*V_out_x-m_dot*V_in_x#force in x-dir\n", + "print \"\\n force F_x=%0.3f N\"%(F_x)#\n", + "#the x-dir force acting on the 90 deg elbow therefore,F_x=+63 N\n", + "V_in_y=0#velocity in vertical in y direction\n", + "V_out_y=420#velocity out vertical in y direction\n", + "print \"velocity in y dir V_in_y=%0.3f m/s\\n velocity out y dir V_out_y=%0.3f m/s\"%(V_in_y,V_out_y)#\n", + "F_y=m_dot*V_out_y-m_dot*V_in_y#force in y dir\n", + "print \"\\n force in y dir F_y=%0.3f N\"%(F_y)#\n", + "#y dir force is acting on the elbow is therefore F_y=-63 N\n", + "F_res=sqrt(F_x*F_x+F_y*F_y)#resultant force F_res\n", + "print \"\\n resultant force F_res=%0.3f N\"%(F_res)#\n", + "#this is the force required to hold the elbow" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 9.3 Page no 88" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 9.3 page no 88\n", + "\n", + "\n", + "density rho=62.400 lb/ft**3\n", + " diameter D=0.167 ft\n", + " momentum M_dot_out=0.000 lbf\n", + " forc in x dir F_x=5.000 lbf\n", + "\n", + " momentum M_dot_in=5.000 lbf\n", + "\n", + " surface area S=0.022 ft**2\n", + "\n", + " velocity =10.849 ft/s\n", + "\n", + " volumatric flow rate q=0.238 ft**3/s\n", + " mass flow rate m_dot=14.828 lb/s\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "print \"Example 9.3 page no 88\\n\\n\"\n", + "#water flow in a pipe\n", + "rho=62.4#density of water \n", + "D=0.167#diameter of pipe\n", + "g=32.174#gravitational constant\n", + "M_dot_out=0#momentum out in x dir\n", + "F_x=5#foce in the x dir\n", + "print \"density rho=%0.3f lb/ft**3\\n diameter D=%0.3f ft\\n momentum M_dot_out=%0.3f lbf\\n forc in x dir F_x=%0.3f lbf\"%(rho,D,M_dot_out,F_x)#\n", + "M_dot_in=M_dot_out+F_x#momentum in \n", + "print \"\\n momentum M_dot_in=%0.3f lbf\"%(M_dot_in)#\n", + "S=(pi*D**2)/4#surface area \n", + "print \"\\n surface area S=%0.3f ft**2\"%(S)#\n", + "v=sqrt((M_dot_in*g)/(rho*S))\n", + "print \"\\n velocity =%0.3f ft/s\"%(v)#\n", + "q=S*v#volumatric flow rate \n", + "m_dot=rho*q#mass flow rate\n", + "print \"\\n volumatric flow rate q=%0.3f ft**3/s\\n mass flow rate m_dot=%0.3f lb/s\"%(q,m_dot)#" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 9.4 Page no 89 " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Example 9.4 page no 89 fig. 9.2\n", + "\n", + "\n", + "\n", + "\n", + " density rho=1000.000 kg/m**3\n", + " viscosity meu=0.001000 kg/m.s\n", + " volumatric flow rate q=0.025 m**3/s\n", + " diametetr at section1 D1=0.100 m\n", + " diameter at section2 D2=0.030 m\n", + "\n", + " surface area at section 1 S1=0.008 m**2\n", + " surface area at section 2 S2=0.001 m**2\n", + "\n", + " velocity at sec1 v1=3.183 m/s\n", + " velocity at sec2 v2=35.368 m/s\n", + "\n", + " pressure at point2 P2=0.000 Pag(pascal gauge)\n", + " pressure atpoint1 P1=620373.346 Pag\n", + "\n", + " mass flow rate m_dot1=25.000 kg/s\n", + " mass flow rate m_dot2=25.000 kg/s\n", + "\n", + " momentum rate M_dot1_x=79.577 N\n", + " momentum rate M_dot2_x=884.194 N\n", + "\n", + " force from momentum balance F_x=-4067.784 N\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import sqrt,pi\n", + "print \"Example 9.4 page no 89 fig. 9.2\\n\\n\\n\"\n", + "#water is discharged through a fire hose\n", + "rho=1000#density of water \n", + "meu=0.001#viscosity of water\n", + "q=0.025#flow rate at section 1\n", + "D1=.1#diameter at section 1\n", + "D2=.03#diameter at section 2\n", + "print \"\\n density rho=%0.3f kg/m**3\\n viscosity meu=%3f kg/m.s\\n volumatric flow rate q=%0.3f m**3/s\\n diametetr at section1 D1=%0.3f m\\n diameter at section2 D2=%0.3f m\"%(rho,meu,q,D1,D2)#\n", + "S1=(pi*D1**2)/4\n", + "S2=(pi*D2**2)/4\n", + "print \"\\n surface area at section 1 S1=%0.3f m**2\\n surface area at section 2 S2=%0.3f m**2\"%(S1,S2)#\n", + "v1=q/S1#velocity at section1\n", + "v2=q/S2#velocity at section2\n", + "print \"\\n velocity at sec1 v1=%0.3f m/s\\n velocity at sec2 v2=%0.3f m/s\"%(v1,v2)#\n", + "#appuing bernoulli's equation between point 1 and 2\n", + "P2=0#pressure at point 2\n", + "P1=(rho/2)*(v2**2-v1**2)#pressure at point 1\n", + "print \"\\n pressure at point2 P2=%0.3f Pag(pascal gauge)\\n pressure atpoint1 P1=%0.3f Pag\"%(P2,P1)#\n", + "m_dot1=25#mass flow rate at section 1\n", + "m_dot2=25#mass flow rate at section 2\n", + "print \"\\n mass flow rate m_dot1=%0.3f kg/s\\n mass flow rate m_dot2=%0.3f kg/s\"%(m_dot1,m_dot2)#\n", + "M_dot1_x=m_dot1*v1#momentum rate in x dir at section 1\n", + "M_dot2_x=m_dot2*v2#momentum rate in x dir at section 2\n", + "print \"\\n momentum rate M_dot1_x=%0.3f N\\n momentum rate M_dot2_x=%0.3f N\"%(M_dot1_x,M_dot2_x)#\n", + "#applying momentum balance in the x direction\n", + "F_x=M_dot2_x-M_dot1_x-P1*S1#force from momentum balance\n", + "print \"\\n force from momentum balance F_x=%0.3f N\"%(F_x)#" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/README.txt b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/README.txt new file mode 100644 index 00000000..7217e7c0 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/README.txt @@ -0,0 +1,10 @@ +Contributed By: Suhaib Alam +Course: btech +College/Institute/Organization: Phonics Group of Institutions +Department/Designation: ME +Book Title: Fluid Flow For The Practicing Chemical Engineer +Author: J. P. Abulencia And L. Theodore +Publisher: John Wiley & Sons, U. S. A. +Year of publication: 2009 +Isbn: 978-0470-31763-1 +Edition: 1
\ No newline at end of file diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/29-6Penetration_1.png b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/29-6Penetration_1.png Binary files differnew file mode 100644 index 00000000..8baddf47 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/29-6Penetration_1.png diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/29-7MoleFraction_1.png b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/29-7MoleFraction_1.png Binary files differnew file mode 100644 index 00000000..a225f6c9 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/29-7MoleFraction_1.png diff --git a/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/PressureDrop29_3_1.png b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/PressureDrop29_3_1.png Binary files differnew file mode 100644 index 00000000..deab77d4 --- /dev/null +++ b/Fluid_Flow_For_The_Practicing_Chemical_Engineer_by_J._P._Abulencia_And_L._Theodore/screenshots/PressureDrop29_3_1.png diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/Chapter9_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/Chapter9_10.ipynb new file mode 100644 index 00000000..dc9cf7f9 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/Chapter9_10.ipynb @@ -0,0 +1,421 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:48cb33cf6ef13f754e173ca6c35bca3909b876e2908bcec42f91faa51efd7e7e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter09:Numerical Solution of Partial Differential Equations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex9.1:pg-350"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#standard five point formula\n",
+ "#example 9.1\n",
+ "#page 350\n",
+ "\n",
+ "u2=5.0\n",
+ "u3=1.0\n",
+ "for i in range(0,3):\n",
+ " u1=(u2+u3+6.0)/4.0\n",
+ " u2=(u1/2.0)+(5.0/2.0)\n",
+ " u3=(u1/2.0)+(1.0/2.0)\n",
+ " print\" the values are u1=%d\\t u2=%d\\t u3=%d\\t\\n\\n\" %(u1,u2,u3)\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " the values are u1=3\t u2=4\t u3=2\t\n",
+ "\n",
+ "\n",
+ " the values are u1=3\t u2=4\t u3=2\t\n",
+ "\n",
+ "\n",
+ " the values are u1=3\t u2=4\t u3=2\t\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex9.2:pg-351"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#solution of laplace equation by jacobi method,gauss-seidel method and SOR method\n",
+ "#example 9.2\n",
+ "#page 351\n",
+ "u1=0.25\n",
+ "u2=0.25\n",
+ "u3=0.5\n",
+ "u4=0.5 #initial values\n",
+ "print \"jacobis iteration process\\n\\n\"\n",
+ "print\"u1\\t u2\\t u3\\t u4\\t \\n\\n\"\n",
+ "print \"%f\\t %f\\t %f\\t %f\\t \\n\" %(u1,u2,u3,u4)\n",
+ "for i in range(0,7):\n",
+ " u11=(0+u2+0+u4)/4\n",
+ " u22=(u1+0+0+u3)/4\n",
+ " u33=(1+u2+0+u4)/4\n",
+ " u44=(1+0+u3+u1)/4\n",
+ " u1=u11\n",
+ " u2=u22\n",
+ " u3=u33\n",
+ " u4=u44\n",
+ " print \"%f\\t %f\\t %f\\t %f\\t \\n\" %(u11,u22,u33,u44) \n",
+ "print \" gauss seidel process\\n\\n\"\n",
+ "u1=0.25\n",
+ "u2=0.3125\n",
+ "u3=0.5625\n",
+ "u4=0.46875 #initial values\n",
+ "print \"u1\\t u2\\t u3\\t u4\\t \\n\\n\"\n",
+ "print \"%f\\t %f\\t %f\\t %f\\t \\n\" %(u1,u2,u3,u4)\n",
+ "for i in range(0,4):\n",
+ "\n",
+ " u1=(0.0+u2+0.0+u4)/4.0\n",
+ " u2=(u1+0.0+0.0+u3)/4.0\n",
+ " u3=(1.0+u2+0.0+u4)/4.0\n",
+ " u4=(1.0+0.0+u3+u1)/4.0\n",
+ " print \"%f\\t %f\\t %f\\t %f\\t \\n\" %(u1,u2,u3,u4) \n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "jacobis iteration process\n",
+ "\n",
+ "\n",
+ "u1\t u2\t u3\t u4\t \n",
+ "\n",
+ "\n",
+ "0.250000\t 0.250000\t 0.500000\t 0.500000\t \n",
+ "\n",
+ "0.187500\t 0.187500\t 0.437500\t 0.437500\t \n",
+ "\n",
+ "0.156250\t 0.156250\t 0.406250\t 0.406250\t \n",
+ "\n",
+ "0.140625\t 0.140625\t 0.390625\t 0.390625\t \n",
+ "\n",
+ "0.132812\t 0.132812\t 0.382812\t 0.382812\t \n",
+ "\n",
+ "0.128906\t 0.128906\t 0.378906\t 0.378906\t \n",
+ "\n",
+ "0.126953\t 0.126953\t 0.376953\t 0.376953\t \n",
+ "\n",
+ "0.125977\t 0.125977\t 0.375977\t 0.375977\t \n",
+ "\n",
+ " gauss seidel process\n",
+ "\n",
+ "\n",
+ "u1\t u2\t u3\t u4\t \n",
+ "\n",
+ "\n",
+ "0.250000\t 0.312500\t 0.562500\t 0.468750\t \n",
+ "\n",
+ "0.195312\t 0.189453\t 0.414551\t 0.402466\t \n",
+ "\n",
+ "0.147980\t 0.140633\t 0.385775\t 0.383439\t \n",
+ "\n",
+ "0.131018\t 0.129198\t 0.378159\t 0.377294\t \n",
+ "\n",
+ "0.126623\t 0.126196\t 0.375872\t 0.375624\t \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex9.4:pg-354"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#poisson equation\n",
+ "#exaample 9.4\n",
+ "#page 354\n",
+ "u2=0.0\n",
+ "u4=0.0\n",
+ "print \" u1\\t u2\\t u3\\t u4\\t\\n\\n\"\n",
+ "for i in range(0,6):\n",
+ " u1=(u2/2.0)+30.0\n",
+ " u2=(u1+u4+150.0)/4.0\n",
+ " u4=(u2/2.0)+45.0\n",
+ " print \"%0.2f\\t %0.2f\\t %0.2f\\t %0.2f\\n\" %(u1,u2,u2,u4)\n",
+ "print \" from last two iterates we conclude u1=67 u2=75 u3=75 u4=83\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " u1\t u2\t u3\t u4\t\n",
+ "\n",
+ "\n",
+ "30.00\t 45.00\t 45.00\t 67.50\n",
+ "\n",
+ "52.50\t 67.50\t 67.50\t 78.75\n",
+ "\n",
+ "63.75\t 73.12\t 73.12\t 81.56\n",
+ "\n",
+ "66.56\t 74.53\t 74.53\t 82.27\n",
+ "\n",
+ "67.27\t 74.88\t 74.88\t 82.44\n",
+ "\n",
+ "67.44\t 74.97\t 74.97\t 82.49\n",
+ "\n",
+ " from last two iterates we conclude u1=67 u2=75 u3=75 u4=83\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 59
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex9.6:pg-362"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#bender-schmidt formula\n",
+ "#example 9.6\n",
+ "#page 362\n",
+ "def f(x):\n",
+ " return (4*x)-(x*x)\n",
+ "#u=[f(0),f(1),f(2),f(3),f(4)]\n",
+ "u1=f(0);u2=f(1);u3=f(2);u4=f(3);u5=f(4);\n",
+ "u11=(u1+u3)/2\n",
+ "u12=(u2+u4)/2\n",
+ "u13=(u3+u5)/2\n",
+ "print \"u11=%0.2f\\t u12=%0.2f\\t u13=%0.2f\\t \\n\" %(u11,u12,u13)\n",
+ "u21=(u1+u12)/2.0\n",
+ "u22=(u11+u13)/2.0\n",
+ "u23=(u12+0)/2.0\n",
+ "print \"u21=%0.2f\\t u22=%0.2f\\t u23=%0.2f\\t \\n\" %(u21,u22,u23)\n",
+ "u31=(u1+u22)/2.0\n",
+ "u32=(u21+u23)/2.0\n",
+ "u33=(u22+u1)/2.0\n",
+ "print \"u31=%0.2f\\t u32=%0.2f\\t u33=%0.2f\\t \\n\" % (u31,u32,u33)\n",
+ "u41=(u1+u32)/2.0\n",
+ "u42=(u31+u33)/2.0\n",
+ "u43=(u32+u1)/2.0\n",
+ "print \"u41=%0.2f\\t u42=%0.2f\\t u43=%0.2f\\t \\n\" % (u41,u42,u43)\n",
+ "u51=(u1+u42)/2.0\n",
+ "u52=(u41+u43)/2.0\n",
+ "u53=(u42+u1)/2.0\n",
+ "print \"u51=%0.2f\\t u52=%0.2f\\t u53=%0.2f\\t \\n\" % (u51,u52,u53)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "u11=2.00\t u12=3.00\t u13=2.00\t \n",
+ "\n",
+ "u21=1.50\t u22=2.00\t u23=1.50\t \n",
+ "\n",
+ "u31=1.00\t u32=1.50\t u33=1.00\t \n",
+ "\n",
+ "u41=0.75\t u42=1.00\t u43=0.75\t \n",
+ "\n",
+ "u51=0.50\t u52=0.75\t u53=0.50\t \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 77
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex9.7:pg-363"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#bender-schimdt's formula and crank-nicolson formula\n",
+ "#example 9.7\n",
+ "#page 363\n",
+ "#bender -schimdt's formula\n",
+ "import math\n",
+ "from numpy import matrix\n",
+ "z=math.pi\n",
+ "def f(x,t):\n",
+ " return math.exp(z*z*t*-1)*sin(z*x)\n",
+ "#u=[f(0,0),f(0.2,0),f(0.4,0),f(0.6,0),f(0.8,0),f(1,0)]\n",
+ "u1=f(0,0)\n",
+ "u2=f(0.2,0)\n",
+ "u3=f(0.4,0)\n",
+ "u4=f(0.6,0)\n",
+ "u5=f(0.8,0)\n",
+ "u6=f(1.0,0)\n",
+ "u11=u3/2\n",
+ "u12=(u2+u4)/2\n",
+ "u13=u12\n",
+ "u14=u11\n",
+ "print \"u11=%f\\t u12=%f\\t u13=%f\\t u14=%f\\n\\n\" % (u11,u12,u13,u14)\n",
+ "u21=u12/2\n",
+ "u22=(u12+u14)/2\n",
+ "u23=u22\n",
+ "u24=u21\n",
+ "print \"u21=%f\\t u22=%f\\t u23=%f\\t u24=%f\\n\\n\" % (u21,u22,u23,u24)\n",
+ "print \"the error in the solution is: %f\\n\\n\" % (math.fabs(u22-f(0.6,0.04)))\n",
+ "#crank-nicolson formula\n",
+ "#by putting i=1,2,3,4 we obtain four equation\n",
+ "A=matrix([[4, -1, 0, 0] ,[-1, 4, -1, 0],[0, -1, 4, -1],[0, 0, -1, 4]])\n",
+ "C=matrix([[0.9510],[1.5388],[1.5388],[0.9510]])\n",
+ "X=A.I*C\n",
+ "print \"u00=%f\\t u10=%f\\t u20=%f\\t u30=%f\\t\\n\\n\" %(X[0][0],X[1][0],X[2][0],X[3][0])\n",
+ "print \"the error in the solution is: %f\\n\\n\" %(abs(X[1][0]-f(0.6,0.04)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "u11=0.475528\t u12=0.769421\t u13=0.769421\t u14=0.475528\n",
+ "\n",
+ "\n",
+ "u21=0.384710\t u22=0.622475\t u23=0.622475\t u24=0.384710\n",
+ "\n",
+ "\n",
+ "the error in the solution is: 0.018372\n",
+ "\n",
+ "\n",
+ "u00=0.399255\t u10=0.646018\t u20=0.646018\t u30=0.399255\t\n",
+ "\n",
+ "\n",
+ "the error in the solution is: 0.005172\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex9.8:pg-364"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#heat equation using crank-nicolson method\n",
+ "#example 9.8\n",
+ "#page 364\n",
+ "from numpy import matrix\n",
+ "import math\n",
+ "z=0.01878\n",
+ "#h=1/2 l=1/8,i=1\n",
+ "u01=0.0\n",
+ "u21=1.0/8.0\n",
+ "u11=(u21+u01)/6.0\n",
+ "print \" u11=%f\\n\\n\" % (u11)\n",
+ "print \"error is %f\\n\\n\" % (math.fabs(u11-z))\n",
+ "#h=1/4,l=1/8,i=1,2,3\n",
+ "A=matrix([[-3.0 ,-1.0 ,0.0],[1.0,-3.0,1.0],[0.0,1.0,-3.0]])\n",
+ "C=matrix([[0.0],[0.0],[-0.125]])\n",
+ "#here we found inverese of A then we multipy it with C\n",
+ "X=A.I*C\n",
+ "print \"u12=%f\\n\\n\" % (X[1][0])\n",
+ "print \"error is %f\\n\\n\" %(math.fabs(X[1][0]-z))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " u11=0.020833\n",
+ "\n",
+ "\n",
+ "error is 0.002053\n",
+ "\n",
+ "\n",
+ "u12=0.013889\n",
+ "\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "error is 0.004891\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter1_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter1_10.ipynb new file mode 100644 index 00000000..81bb2dc6 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter1_10.ipynb @@ -0,0 +1,629 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:bd492601bf0cbf93169a7f4f37f7f64caba9f8e22a4fc5648e6c332b00f367f3"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter01:Errors in Numerical Calculations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.1:pg-7"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 1.1\n",
+ "#rounding off\n",
+ "#page 7\n",
+ "a1=1.6583\n",
+ "a2=30.0567\n",
+ "a3=0.859378\n",
+ "a4=3.14159\n",
+ "print \"\\nthe numbers after rounding to 4 significant figures are given below\\n\"\n",
+ "print \" %f %.4g\\n'\" %(a1,a1)\n",
+ "print \" %f %.4g\\n\" %(a2,a2)\n",
+ "print \" %f %.4g\\n\" %(a3,a3)\n",
+ "print \" %f %.4g\\n\" %(a4,a4)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "the numbers after rounding to 4 significant figures are given below\n",
+ "\n",
+ " 1.658300 1.658\n",
+ "'\n",
+ " 30.056700 30.06\n",
+ "\n",
+ " 0.859378 0.8594\n",
+ "\n",
+ " 3.141590 3.142\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.2:pg-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 1.2\n",
+ "#percentage accuracy\n",
+ "#page 9\n",
+ "import math\n",
+ "x=0.51 # the number given\n",
+ "n=2 #correcting upto 2 decimal places\n",
+ "d=math.pow(10,-n)\n",
+ "d=d/2.0\n",
+ "p=(d/x)*100 #percentage accuracy\n",
+ "print \"the percentage accuracy of %f after correcting to two decimal places is %f\" %(x,p)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the percentage accuracy of 0.510000 after correcting to two decimal places is 0.980392\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.3:pg-9"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 1.3\n",
+ "#absolute and relative errors\n",
+ "#page 9\n",
+ "X=3.1428571 #approximate value of pi\n",
+ "T_X=3.1415926 # true value of pi\n",
+ "A_E=T_X-X #absolute error\n",
+ "R_E=A_E/T_X #relative error\n",
+ "print \"Absolute Error = %0.7f \\n Relative Error = %0.7f\" %(A_E,R_E)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Absolute Error = -0.0012645 \n",
+ " Relative Error = -0.0004025\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.4:pg-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 1.4\n",
+ "#best approximation\n",
+ "#page 10\n",
+ "import math\n",
+ "X=1/3 #the actual number\n",
+ "X1=0.30\n",
+ "X2=0.33\n",
+ "X3=0.34\n",
+ "E1=abs(X-X1)\n",
+ "E2=abs(X-X2)\n",
+ "E3=abs(X-X3)\n",
+ "if E1<E2:\n",
+ " if E1<E3:\n",
+ " B_A=X1\n",
+ "elif E2<E1:\n",
+ " if E2<E3:\n",
+ " B_A=X2\n",
+ "elif E3<E2:\n",
+ " if E3<E1:\n",
+ " B_A=X3\n",
+ "print \"the best approximation of 1/3 is %f\" %(B_A)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the best approximation of 1/3 is 0.300000\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.5:pg-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#relative error\n",
+ "#example 1.5\n",
+ "#page 10\n",
+ "import math\n",
+ "n=8.6 # the corrected number\n",
+ "N=1 #the no is rounded to one decimal places\n",
+ "E_A=math.pow(10,-N)/2\n",
+ "E_R=E_A/n\n",
+ "print \"the relative error of the number is:%0.4f\" %(E_R)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the relative error of the number is:0.0058\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.6:pg-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 1.6\n",
+ "#absolute error and relative error\n",
+ "#page 10\n",
+ "import math\n",
+ "s=math.sqrt(3)+math.sqrt(5)+math.sqrt(7) #the sum square root of 3,5,7\n",
+ "n=4\n",
+ "Ea=3*(math.pow(10,-n)/2) #absolute error\n",
+ "R_E=Ea/s\n",
+ "print \"the sum of square roots is %0.4g \\n\" %(s)\n",
+ "print \"the absolute error is %f \\n\" %(Ea)\n",
+ "print \"the relative error is %f\" %(R_E)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the sum of square roots is 6.614 \n",
+ "\n",
+ "the absolute error is 0.000150 \n",
+ "\n",
+ "the relative error is 0.000023\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.7:pg-10"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#absolute error\n",
+ "#example 1.7\n",
+ "#page 10\n",
+ "import math\n",
+ "n=[0.1532, 15.45, 0.0000354, 305.1, 8.12, 143.3, 0.0212, 0.643, 0.1734] #original numbers\n",
+ "#rounding all numbers to 2 decimal places\n",
+ "n=[305.1, 143.3, 0.15,15.45, 0.00, 8.12, 0.02, 0.64, 0.17] \n",
+ "sum=0;\n",
+ "#l=length(n);\n",
+ "for i in range(len(n)):\n",
+ " sum=sum+n[i];\n",
+ "\n",
+ "E_A=2*math.pow(10,-1)/2+7*math.pow(10,-2)/2\n",
+ "print \"the absolute error is:%0.2f\" %(E_A)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the absolute error is:0.14\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.8:pg-11"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#difference in 3 significant figures\n",
+ "#example 1.8\n",
+ "#page 11\n",
+ "import math\n",
+ "X1=math.sqrt(6.37)\n",
+ "X2=math.sqrt(6.36)\n",
+ "d=X1-X2 #difference between two numbers\n",
+ "print \"the difference corrected to 3 significant figures is %0.3g\" %(d)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the difference corrected to 3 significant figures is 0.00198\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.9:pg-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#relative error\n",
+ "#example 1.10\n",
+ "#page 12\n",
+ "import math\n",
+ "a=6.54\n",
+ "b=48.64\n",
+ "c=13.5\n",
+ "da=0.01\n",
+ "db=0.02\n",
+ "dc=0.03\n",
+ "s=math.pow(a,2)*math.sqrt(b)/math.pow(c,3)\n",
+ "print \"s=%f\" %(s)\n",
+ "r_err=2*(da/a)+(db/b)/2+3*(dc/c)\n",
+ "print \"the relative error is :%f\" %(r_err)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s=0.121241\n",
+ "the relative error is :0.009930\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.11:pg-13"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#relative error\n",
+ "#example 1.11\n",
+ "#page 13\n",
+ "import math\n",
+ "x=1\n",
+ "y=1\n",
+ "z=1\n",
+ "u=(5*x*math.pow(y,3))/math.pow(z,3)\n",
+ "dx=0.001\n",
+ "dy=0.001\n",
+ "dz=0.001\n",
+ "max=((5*math.pow(y,2))/math.pow(z,3))*dx+((10*x*y)/math.pow(z,3))*dy+((15*x*math.pow(y,2))/math.pow(z,4))*dz\n",
+ "e=max/u\n",
+ "print \" the relative error is :%f\" %(e)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " the relative error is :0.006000\n"
+ ]
+ }
+ ],
+ "prompt_number": 19
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.12:pg-12"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#taylor series\n",
+ "#example 1.12\n",
+ "#page 12\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.pow(x,3)+5*x-10\n",
+ "def f1(x):\n",
+ " return 3*math.pow(x,2)-6*x+5\n",
+ "def f2(x):\n",
+ " return 6*x-6\n",
+ "def f3(x):\n",
+ " return 6\n",
+ "D=[0,f(0), f1(0), f2(0), f3(0)]\n",
+ "S1=0;\n",
+ "h=1;\n",
+ "for i in range(1,5):\n",
+ " S1=S1+math.pow(h,i-1)*D[i]/math.factorial(i-1)\n",
+ " \n",
+ "print \"the third order taylors series approximation of f(1) is :%d\" %(S1)\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the third order taylors series approximation of f(1) is :-7\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.13:pg-16"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#taylor series\n",
+ "#example 1.13\n",
+ "#page 16\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.sin(x)\n",
+ "def f1(x):\n",
+ " return math.cos(x)\n",
+ "def f2(x):\n",
+ " return -1*math.sin(x)\n",
+ "def f3(x):\n",
+ " return -1*math.cos(x)\n",
+ "def f4(x):\n",
+ " return math.sin(x)\n",
+ "def f5(x):\n",
+ " return math.cos(x)\n",
+ "def f6(x):\n",
+ " return -1*math.sin(x)\n",
+ "def f7(x):\n",
+ " return -1*math.cos(x)\n",
+ "D=[0,f(math.pi/6), f1(math.pi/6), f2(math.pi/6), f3(math.pi/6), f4(math.pi/6), f5(math.pi/6), f6(math.pi/6), f7(math.pi/6)]\n",
+ "S1=0\n",
+ "h=math.pi/6\n",
+ "print \"order of approximation computed value of sin(pi/3) absolute eror\\n\\n\"\n",
+ "for j in range(1,10):\n",
+ " for i in range(1,j):\n",
+ " S1=S1+math.pow(h,i-1)*D[i]/math.factorial(i-1) \n",
+ " print \"%d %0.9f %0.9f\\n\" %(j,S1,abs(math.sin(math.pi/3)-S1))\n",
+ " S1=0\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "order of approximation computed value of sin(pi/3) absolute eror\n",
+ "\n",
+ "\n",
+ "1 0.000000000 0.866025404\n",
+ "\n",
+ "2 0.500000000 0.366025404\n",
+ "\n",
+ "3 0.953449841 0.087424437\n",
+ "\n",
+ "4 0.884910922 0.018885518\n",
+ "\n",
+ "5 0.864191614 0.001833790\n",
+ "\n",
+ "6 0.865757475 0.000267929\n",
+ "\n",
+ "7 0.866041490 0.000016087\n",
+ "\n",
+ "8 0.866027181 0.000001777\n",
+ "\n",
+ "9 0.866025327 0.000000077\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 32
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.14:pg-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#maclaurins expansion\n",
+ "#example 1.14\n",
+ "#page 18\n",
+ "import math\n",
+ "n=8 #correct to 8 decimal places\n",
+ "x=1\n",
+ "for i in range(1,50):\n",
+ " if x/math.factorial(i)<math.pow(10,-8)/2:\n",
+ " c=i\n",
+ " break \n",
+ "print \"no. of terms needed to correct to 8 decimal places is : %d \" %(c)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "no. of terms needed to correct to 8 decimal places is : 2 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex1.15:pg-18"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#series apprixamation\n",
+ "#example 1.15\n",
+ "#page 18\n",
+ "import math\n",
+ "x=.09090909 # 1/11 =.09090909\n",
+ "S1=0\n",
+ "for i in range(1,5,2):\n",
+ " S1=S1+math.pow(x,i)/i\n",
+ "print \"value of log(1.2) is : %0.8f\\n\\n\" %(2*S1)\n",
+ "c=0\n",
+ "for i in range(1,50):\n",
+ " if math.pow(.09090909,i)/i<2*math.pow(10,-7):\n",
+ " c=i\n",
+ " break\n",
+ "print \"min no of terms needed to get value wuth same accuracy is :%d\" %(c)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of log(1.2) is : 0.18231906\n",
+ "\n",
+ "\n",
+ "min no of terms needed to get value wuth same accuracy is :6\n"
+ ]
+ }
+ ],
+ "prompt_number": 74
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter2_(1)_1.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter2_(1)_1.ipynb new file mode 100644 index 00000000..eedd9e7d --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter2_(1)_1.ipynb @@ -0,0 +1,2188 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:dc70a89f56576070d6e170e43234641fb7b9652a8d7eff402826fb543d9ee1c5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter02:Solution of Algebric and Transcendental Equations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.1:pg-24"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.1\n",
+ "#bisection method\n",
+ "#page 24\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.pow(x,3)-x-1\n",
+ "x1=1\n",
+ "x2=2 #f(1) is negative and f(2) is positive\n",
+ "d=0.0001 #for accuracy of root\n",
+ "c=1\n",
+ "print \"Succesive approximations \\t x1\\t \\tx2\\t \\tm\\t \\tf(m)\\n\"\n",
+ "while abs(x1-x2)>d:\n",
+ " \n",
+ " m=(x1+x2)/2.0\n",
+ " print \" \\t%f\\t%f\\t%f\\t%f\\n\" %(x1,x2,m,f(m))\n",
+ " if f(m)*f(x1)>0.0:\n",
+ " x1=m\n",
+ " else:\n",
+ " x2=m \n",
+ " c=c+1 # to count number of iterations \n",
+ "print \"the solution of equation after %i iteration is %g\" %(c,m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Succesive approximations \t x1\t \tx2\t \tm\t \tf(m)\n",
+ "\n",
+ " \t1.000000\t2.000000\t1.500000\t0.875000\n",
+ "\n",
+ " \t1.000000\t1.500000\t1.250000\t-0.296875\n",
+ "\n",
+ " \t1.250000\t1.500000\t1.375000\t0.224609\n",
+ "\n",
+ " \t1.250000\t1.375000\t1.312500\t-0.051514\n",
+ "\n",
+ " \t1.312500\t1.375000\t1.343750\t0.082611\n",
+ "\n",
+ " \t1.312500\t1.343750\t1.328125\t0.014576\n",
+ "\n",
+ " \t1.312500\t1.328125\t1.320312\t-0.018711\n",
+ "\n",
+ " \t1.320312\t1.328125\t1.324219\t-0.002128\n",
+ "\n",
+ " \t1.324219\t1.328125\t1.326172\t0.006209\n",
+ "\n",
+ " \t1.324219\t1.326172\t1.325195\t0.002037\n",
+ "\n",
+ " \t1.324219\t1.325195\t1.324707\t-0.000047\n",
+ "\n",
+ " \t1.324707\t1.325195\t1.324951\t0.000995\n",
+ "\n",
+ " \t1.324707\t1.324951\t1.324829\t0.000474\n",
+ "\n",
+ " \t1.324707\t1.324829\t1.324768\t0.000214\n",
+ "\n",
+ "the solution of equation after 15 iteration is 1.32477'\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.2:pg-25"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.2\n",
+ "#bisection method\n",
+ "#page 25\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.pow(x,3)-2*x-5\n",
+ "x1=2 \n",
+ "x2=3 #f(2) is negative and f(3) is positive\n",
+ "d=0.0001 #for accuracy of root\n",
+ "c=1\n",
+ "print \"Succesive approximations \\t x1\\t \\tx2\\t \\tm\\t \\tf(m)\\n\"\n",
+ "while abs(x1-x2)>d:\n",
+ " m=(x1+x2)/2.0\n",
+ " print \" \\t%f\\t%f\\t%f\\t%f\\n\" %(x1,x2,m,f(m))\n",
+ " if f(m)*f(x1)>0:\n",
+ " x1=m\n",
+ " else:\n",
+ " x2=m \n",
+ " c=c+1;# to count number of iterations \n",
+ "print \"the solution of equation after %i iteration is %0.4g\" %(c,m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Succesive approximations \t x1\t \tx2\t \tm\t \tf(m)\n",
+ "\n",
+ " \t2.000000\t3.000000\t2.500000\t5.625000\n",
+ "\n",
+ " \t2.000000\t2.500000\t2.250000\t1.890625\n",
+ "\n",
+ " \t2.000000\t2.250000\t2.125000\t0.345703\n",
+ "\n",
+ " \t2.000000\t2.125000\t2.062500\t-0.351318\n",
+ "\n",
+ " \t2.062500\t2.125000\t2.093750\t-0.008942\n",
+ "\n",
+ " \t2.093750\t2.125000\t2.109375\t0.166836\n",
+ "\n",
+ " \t2.093750\t2.109375\t2.101562\t0.078562\n",
+ "\n",
+ " \t2.093750\t2.101562\t2.097656\t0.034714\n",
+ "\n",
+ " \t2.093750\t2.097656\t2.095703\t0.012862\n",
+ "\n",
+ " \t2.093750\t2.095703\t2.094727\t0.001954\n",
+ "\n",
+ " \t2.093750\t2.094727\t2.094238\t-0.003495\n",
+ "\n",
+ " \t2.094238\t2.094727\t2.094482\t-0.000771\n",
+ "\n",
+ " \t2.094482\t2.094727\t2.094604\t0.000592\n",
+ "\n",
+ " \t2.094482\t2.094604\t2.094543\t-0.000090\n",
+ "\n",
+ "the solution of equation after 15 iteration is 2.095\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.3:pg-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.3\n",
+ "#bisection method\n",
+ "#page 26\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.pow(x,3)+math.pow(x,2)+x+7\n",
+ "x1=-3\n",
+ "x2=-2 #f(-3) is negative and f(-2) is positive\n",
+ "d=0.0001 #for accuracy of root\n",
+ "c=1\n",
+ "print \"Succesive approximations \\t x1\\t \\tx2\\t \\tm\\t \\tf(m)\\n\"\n",
+ "while abs(x1-x2)>d:\n",
+ " m=(x1+x2)/2.0\n",
+ " print \" \\t%f\\t%f\\t%f\\t%f\\n\" %(x1,x2,m,f(m))\n",
+ " if f(m)*f(x1)>0:\n",
+ " x1=m\n",
+ " else:\n",
+ " x2=m \n",
+ " c=c+1 # to count number of iterations \n",
+ "print \"the solution of equation after %i iteration is %0.4g\" %(c,m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Succesive approximations \t x1\t \tx2\t \tm\t \tf(m)\n",
+ "\n",
+ " \t-3.000000\t-2.000000\t-2.500000\t-4.875000\n",
+ "\n",
+ " \t-2.500000\t-2.000000\t-2.250000\t-1.578125\n",
+ "\n",
+ " \t-2.250000\t-2.000000\t-2.125000\t-0.205078\n",
+ "\n",
+ " \t-2.125000\t-2.000000\t-2.062500\t0.417725\n",
+ "\n",
+ " \t-2.125000\t-2.062500\t-2.093750\t0.111481\n",
+ "\n",
+ " \t-2.125000\t-2.093750\t-2.109375\t-0.045498\n",
+ "\n",
+ " \t-2.109375\t-2.093750\t-2.101562\t0.033315\n",
+ "\n",
+ " \t-2.109375\t-2.101562\t-2.105469\t-0.006010\n",
+ "\n",
+ " \t-2.105469\t-2.101562\t-2.103516\t0.013673\n",
+ "\n",
+ " \t-2.105469\t-2.103516\t-2.104492\t0.003836\n",
+ "\n",
+ " \t-2.105469\t-2.104492\t-2.104980\t-0.001086\n",
+ "\n",
+ " \t-2.104980\t-2.104492\t-2.104736\t0.001376\n",
+ "\n",
+ " \t-2.104980\t-2.104736\t-2.104858\t0.000145\n",
+ "\n",
+ " \t-2.104980\t-2.104858\t-2.104919\t-0.000470\n",
+ "\n",
+ "the solution of equation after 15 iteration is -2.105\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.4:pg-26"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.4\n",
+ "#bisection method\n",
+ "#page 26\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x*math.exp(x)-1\n",
+ "x1=0 \n",
+ "x2=1 #f(0) is negative and f(1) is positive\n",
+ "d=0.0005 #maximun tolerance value\n",
+ "c=1\n",
+ "print \"Succesive approximations \\t x1\\t \\tx2\\t \\tm\\t \\ttol\\t \\tf(m)\\n\"\n",
+ "while abs((x2-x1)/x2)>d:\n",
+ " m=(x1+x2)/2.0 #tolerance value for each iteration\n",
+ " tol=((x2-x1)/x2)*100\n",
+ " print \" \\t%f\\t%f\\t%f\\t%f\\t%f\\n\" %(x1,x2,m,tol,f(m))\n",
+ " if f(m)*f(x1)>0:\n",
+ " x1=m\n",
+ " else:\n",
+ " x2=m \n",
+ " c=c+1 # to count number of iterations \n",
+ "print \"the solution of equation after %i iteration is %0.4g\" %(c,m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Succesive approximations \t x1\t \tx2\t \tm\t \ttol\t \tf(m)\n",
+ "\n",
+ " \t0.000000\t1.000000\t0.500000\t100.000000\t-0.175639\n",
+ "\n",
+ " \t0.500000\t1.000000\t0.750000\t50.000000\t0.587750\n",
+ "\n",
+ " \t0.500000\t0.750000\t0.625000\t33.333333\t0.167654\n",
+ "\n",
+ " \t0.500000\t0.625000\t0.562500\t20.000000\t-0.012782\n",
+ "\n",
+ " \t0.562500\t0.625000\t0.593750\t10.000000\t0.075142\n",
+ "\n",
+ " \t0.562500\t0.593750\t0.578125\t5.263158\t0.030619\n",
+ "\n",
+ " \t0.562500\t0.578125\t0.570312\t2.702703\t0.008780\n",
+ "\n",
+ " \t0.562500\t0.570312\t0.566406\t1.369863\t-0.002035\n",
+ "\n",
+ " \t0.566406\t0.570312\t0.568359\t0.684932\t0.003364\n",
+ "\n",
+ " \t0.566406\t0.568359\t0.567383\t0.343643\t0.000662\n",
+ "\n",
+ " \t0.566406\t0.567383\t0.566895\t0.172117\t-0.000687\n",
+ "\n",
+ " \t0.566895\t0.567383\t0.567139\t0.086059\t-0.000013\n",
+ "\n",
+ "the solution of equation after 13 iteration is 0.5671\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.5:pg-27"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.5\n",
+ "#bisection method\n",
+ "#page 27\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 4*math.exp(-x)*math.sin(x)-1\n",
+ "x1=0 \n",
+ "x2=0.5 #f(0) is negative and f(1) is positive\n",
+ "d=0.0001 #for accuracy of root\n",
+ "c=1 \n",
+ "print \"Succesive approximations \\t x1\\t \\tx2\\t \\tm\\t \\t \\tf(m)\\n\"\n",
+ "while abs(x2-x1)>d:\n",
+ " m=(x1+x2)/2.0\n",
+ " print \" \\t%f\\t%f\\t%f\\t%f\\n\" %(x1,x2,m,f(m))\n",
+ " if f(m)*f(x1)>0:\n",
+ " x1=m\n",
+ " else:\n",
+ " x2=m \n",
+ " c=c+1 # to count number of iterations \n",
+ "print \"the solution of equation after %i iteration is %0.3g\" %(c,m)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Succesive approximations \t x1\t \tx2\t \tm\t \t \tf(m)\n",
+ "\n",
+ " \t0.000000\t0.500000\t0.250000\t-0.229286\n",
+ "\n",
+ " \t0.250000\t0.500000\t0.375000\t0.006941\n",
+ "\n",
+ " \t0.250000\t0.375000\t0.312500\t-0.100293\n",
+ "\n",
+ " \t0.312500\t0.375000\t0.343750\t-0.044068\n",
+ "\n",
+ " \t0.343750\t0.375000\t0.359375\t-0.017925\n",
+ "\n",
+ " \t0.359375\t0.375000\t0.367188\t-0.005334\n",
+ "\n",
+ " \t0.367188\t0.375000\t0.371094\t0.000842\n",
+ "\n",
+ " \t0.367188\t0.371094\t0.369141\t-0.002236\n",
+ "\n",
+ " \t0.369141\t0.371094\t0.370117\t-0.000694\n",
+ "\n",
+ " \t0.370117\t0.371094\t0.370605\t0.000075\n",
+ "\n",
+ " \t0.370117\t0.370605\t0.370361\t-0.000310\n",
+ "\n",
+ " \t0.370361\t0.370605\t0.370483\t-0.000118\n",
+ "\n",
+ " \t0.370483\t0.370605\t0.370544\t-0.000022\n",
+ "\n",
+ "the solution of equation after 14 iteration is 0.371\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.6:pg-28"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.6\n",
+ "#false position method\n",
+ "#page 28\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x**3-2*x-5\n",
+ "a=2.0\n",
+ "b=3.0 #f(2) is negative and f(3)is positive\n",
+ "d=0.00001\n",
+ "print \"succesive iterations \\ta\\t b\\t f(a)\\t f(b)\\t\\ x1\\n\"\n",
+ "for i in range(1,25):\n",
+ " x1=b*f(a)/(f(a)-f(b))+a*f(b)/(f(b)-f(a))\n",
+ " if(f(a)*f(x1))>0:\n",
+ " b=x1\n",
+ " else:\n",
+ " a=x1\n",
+ " if abs(f(x1))<d:\n",
+ " break\n",
+ " print \" \\t%f %f %f %f %f\\n\" %(a,b,f(a),f(b),x1)\n",
+ "print \"the root of the equation is %f\" %(x1)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "succesive iterations \ta\t b\t f(a)\t f(b)\t\\ x1\n",
+ "\n",
+ " \t2.000000 2.058824 -1.000000 -0.390800 2.058824\n",
+ "\n",
+ " \t2.096559 2.058824 0.022428 -0.390800 2.096559\n",
+ "\n",
+ " \t2.094511 2.058824 -0.000457 -0.390800 2.094511\n",
+ "\n",
+ "the root of the equation is 2.094552\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.7:pg-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.7\n",
+ "#false position method\n",
+ "#page 29\n",
+ "def f(x):\n",
+ " return x**2.2-69\n",
+ "a=5.0\n",
+ "b=6.0 #f(5) is negative and f(6)is positive\n",
+ "d=0.00001\n",
+ "print \"succesive iterations \\ta\\t b\\t f(a)\\t f(b)\\t\\ x1\\n\"\n",
+ "for i in range(1,25):\n",
+ " x1=b*f(a)/(f(a)-f(b))+a*f(b)/(f(b)-f(a));\n",
+ " if(f(a)*f(x1))>0:\n",
+ " b=x1\n",
+ " else:\n",
+ " a=x1\n",
+ " if abs(f(x1))<d:\n",
+ " break\n",
+ " print \" \\t%f %f %f %f %f\\n\" %(a,b,f(a),f(b),x1)\n",
+ "print \"the root of the equation is %f\" %(x1)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "succesive iterations \ta\t b\t f(a)\t f(b)\t\\ x1\n",
+ "\n",
+ " \t7.027228 6.000000 3.933141 -17.485113 7.027228\n",
+ "\n",
+ " \t6.838593 6.000000 -0.304723 -17.485113 6.838593\n",
+ "\n",
+ " \t6.853467 6.000000 0.024411 -17.485113 6.853467\n",
+ "\n",
+ " \t6.852277 6.000000 -0.001950 -17.485113 6.852277\n",
+ "\n",
+ " \t6.852372 6.000000 0.000156 -17.485113 6.852372\n",
+ "\n",
+ " \t6.852365 6.000000 -0.000012 -17.485113 6.852365\n",
+ "\n",
+ "the root of the equation is 6.852365\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.8:pg-29"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.8\n",
+ "#false position method\n",
+ "#page 29\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 2*x-log10(x)-7\n",
+ "a=3.0\n",
+ "b=4.0 #f(3) is negative and f(4)is positive\n",
+ "d=0.00001\n",
+ "print \"succesive iterations \\ta \\t b\\t f(a)\\t f(b)\\t x1\\n\"\n",
+ "for i in range(1,25):\n",
+ " x1=b*f(a)/(f(a)-f(b))+a*f(b)/(f(b)-f(a))\n",
+ " if(f(a)*f(x1))>0:\n",
+ " b=x1\n",
+ " else:\n",
+ " a=x1\n",
+ " if abs(f(x1))<d:\n",
+ " break\n",
+ " print \" \\t%f %f %f %f %f\\n\" %(a,b,f(a),f(b),x1)\n",
+ "print \"the root of the equation is %0.4g\" %(x1)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "succesive iterations \ta \t b\t f(a)\t f(b)\t x1\n",
+ "\n",
+ " \t3.000000 3.787772 -1.477121 -0.002839 3.787772\n",
+ "\n",
+ " \t3.789289 3.787772 0.000021 -0.002839 3.789289\n",
+ "\n",
+ "the root of the equation is 3.789\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.9:pg-30"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.9\n",
+ "#false position method\n",
+ "#page 30\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 4*math.exp(-x)*math.sin(x)-1\n",
+ "a=0.0\n",
+ "b=0.5 #f(0) is negative and f(0.5)is positive\n",
+ "d=0.00001\n",
+ "print \"succesive iterations \\ta\\t b\\t f(a)\\t f(b)\\t\\ x1\\n\"\n",
+ "for i in range(1,25):\n",
+ " x1=b*f(a)/(f(a)-f(b))+a*f(b)/(f(b)-f(a))\n",
+ " if(f(a)*f(x1))>0:\n",
+ " b=x1\n",
+ " else:\n",
+ " a=x1\n",
+ " if abs(f(x1))<d:\n",
+ " break\n",
+ " print \" \\t%f %f %f %f %f\\n\" %(a,b,f(a),f(b),x1)\n",
+ "print \"the root of the equation is %f\" %(x1)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "succesive iterations \ta\t b\t f(a)\t f(b)\t\\ x1\n",
+ "\n",
+ " \t0.429869 0.500000 0.084545 0.163145 0.429869\n",
+ "\n",
+ " \t0.354433 0.500000 -0.026054 0.163145 0.354433\n",
+ "\n",
+ " \t0.374479 0.500000 0.006132 0.163145 0.374479\n",
+ "\n",
+ " \t0.369577 0.500000 -0.001547 0.163145 0.369577\n",
+ "\n",
+ " \t0.370802 0.500000 0.000384 0.163145 0.370802\n",
+ "\n",
+ " \t0.370497 0.500000 -0.000096 0.163145 0.370497\n",
+ "\n",
+ " \t0.370573 0.500000 0.000024 0.163145 0.370573\n",
+ "\n",
+ "the root of the equation is 0.370554\n"
+ ]
+ }
+ ],
+ "prompt_number": 20
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.10:pg-33"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.10\n",
+ "#iteration method\n",
+ "#page 33\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 1/(math.sqrt(x+1))\n",
+ "x1=0.75\n",
+ "x2=0.0\n",
+ "n=1\n",
+ "d=0.0001 #accuracy opto 10^-4\n",
+ "c=0 #to count no of iterations \n",
+ "print \"successive iterations \\t\\x01\\tf(x1)\\n\"\n",
+ "while abs(x1-x2)>d:\n",
+ " print \" \\t%f %f\\n\" %(x1,f(x1))\n",
+ " x2=x1\n",
+ " x1=f(x1)\n",
+ " c=c+1\n",
+ "print \" the root of the eqaution after %i iteration is %0.4g\" %(c,x1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t\u0001\tf(x1)\n",
+ "\n",
+ " \t0.750000 0.755929\n",
+ "\n",
+ " \t0.755929 0.754652\n",
+ "\n",
+ " \t0.754652 0.754926\n",
+ "\n",
+ " \t0.754926 0.754867\n",
+ "\n",
+ " the root of the eqaution after 4 iteration is 0.7549\n"
+ ]
+ }
+ ],
+ "prompt_number": 23
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.11:pg-34"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.11\n",
+ "#iteration method\n",
+ "#page34\n",
+ "import math\n",
+ "def f(x):\n",
+ " return cos(x)/2.0+3.0/2.0\n",
+ "x1=1.5 # as roots lies between 3/2 and pi/2\n",
+ "x2=0\n",
+ "d=0.0001 # accuracy opto 10^-4\n",
+ "c=0 # to count no of iterations \n",
+ "print \"successive iterations \\t\\x01\\tf(x1)\\n\"\n",
+ "while abs(x2-x1)>d:\n",
+ " \n",
+ " print \" \\t%f %f\\n\" %(x1,f(x1))\n",
+ " x2=x1\n",
+ " x1=f(x1)\n",
+ " c=c+1\n",
+ "print \" the root of the eqaution after %i iteration is %0.4g\" %(c,x1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t\u0001\tf(x1)\n",
+ "\n",
+ " \t1.500000 1.535369\n",
+ "\n",
+ " \t1.535369 1.517710\n",
+ "\n",
+ " \t1.517710 1.526531\n",
+ "\n",
+ " \t1.526531 1.522126\n",
+ "\n",
+ " \t1.522126 1.524326\n",
+ "\n",
+ " \t1.524326 1.523227\n",
+ "\n",
+ " \t1.523227 1.523776\n",
+ "\n",
+ " \t1.523776 1.523502\n",
+ "\n",
+ " \t1.523502 1.523639\n",
+ "\n",
+ " \t1.523639 1.523570\n",
+ "\n",
+ " the root of the eqaution after 10 iteration is 1.524\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.12:pg-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.12\n",
+ "#iteration method\n",
+ "#page 35\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.exp(-x)\n",
+ "x1=1.5 # as roots lies between 0 and 1\n",
+ "x2=0\n",
+ "d=0.0001 # accuracy opto 10^-4\n",
+ "c=0 # to count no of iterations \n",
+ "print \"successive iterations \\t x1 \\t f(x1)\\n\"\n",
+ "while abs(x2-x1)>d:\n",
+ " \n",
+ " print \" \\t%f %f\\n\" %(x1,f(x1))\n",
+ " x2=x1\n",
+ " x1=f(x1)\n",
+ " c=c+1\n",
+ "print \" the root of the eqaution after %i iteration is %0.4g\" %(c,x1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x1 \t f(x1)\n",
+ "\n",
+ " \t1.500000 0.223130\n",
+ "\n",
+ " \t0.223130 0.800011\n",
+ "\n",
+ " \t0.800011 0.449324\n",
+ "\n",
+ " \t0.449324 0.638059\n",
+ "\n",
+ " \t0.638059 0.528317\n",
+ "\n",
+ " \t0.528317 0.589597\n",
+ "\n",
+ " \t0.589597 0.554551\n",
+ "\n",
+ " \t0.554551 0.574330\n",
+ "\n",
+ " \t0.574330 0.563082\n",
+ "\n",
+ " \t0.563082 0.569451\n",
+ "\n",
+ " \t0.569451 0.565836\n",
+ "\n",
+ " \t0.565836 0.567885\n",
+ "\n",
+ " \t0.567885 0.566723\n",
+ "\n",
+ " \t0.566723 0.567382\n",
+ "\n",
+ " \t0.567382 0.567008\n",
+ "\n",
+ " \t0.567008 0.567220\n",
+ "\n",
+ " \t0.567220 0.567100\n",
+ "\n",
+ " \t0.567100 0.567168\n",
+ "\n",
+ " the root of the eqaution after 18 iteration is 0.5672\n"
+ ]
+ }
+ ],
+ "prompt_number": 34
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.13:pg-35"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.13\n",
+ "#iteration method\n",
+ "#page 35\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 1+math.sin(x)/10\n",
+ "x1=1.0 # as roots lies between 1 and pi evident from graph\n",
+ "x2=0\n",
+ "d=0.0001 # accuracy opto 10^-4\n",
+ "c=0 # to count no of iterations \n",
+ "print \"successive iterations \\t x1 \\t f(x1)\\n\"\n",
+ "while abs(x2-x1)>d:\n",
+ " print \" \\t%f %f\\n\" %(x1,f(x1))\n",
+ " x2=x1\n",
+ " x1=f(x1)\n",
+ " c=c+1\n",
+ "print \" the root of the eqaution after %i iteration is %0.4g\" %(c,x1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x1 \t f(x1)\n",
+ "\n",
+ " \t1.000000 1.084147\n",
+ "\n",
+ " \t1.084147 1.088390\n",
+ "\n",
+ " \t1.088390 1.088588\n",
+ "\n",
+ " \t1.088588 1.088597\n",
+ "\n",
+ " the root of the eqaution after 4 iteration is 1.089\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.14:pg-36"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.14\n",
+ "#aitken's process\n",
+ "#page 36\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 1.5+math.cos(x)/2.0\n",
+ "x0=1.5\n",
+ "y=0\n",
+ "e=0.0001\n",
+ "c=0\n",
+ "print \"successive iterations \\t x0 \\t x1 \\t x2 \\t x3 \\t y\\n\"\n",
+ "for i in range(1,10):\n",
+ " x1=f(x0)\n",
+ " x2=f(x1)\n",
+ " x3=f(x2)\n",
+ " y=x3-((x3-x2)**2)/(x3-2*x2+x1)\n",
+ " d=y-x0\n",
+ " x0=y\n",
+ " if abs(f(x0))<e:\n",
+ " break\n",
+ " c=c+1\n",
+ " print \" \\t%f %f %f %f %f\\n\" %(x0,x1,x2,x3,y)\n",
+ "print \"the root of the equation after %i iteration is %f\" %(c,y)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x0 \t x1 \t x2 \t x3 \t y\n",
+ "\n",
+ " \t1.523592 1.535369 1.517710 1.526531 1.523592\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ " \t1.523593 1.523593 1.523593 1.523593 1.523593\n",
+ "\n",
+ "the root of the equation after 9 iteration is 1.523593\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.15:pg-39"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.15\n",
+ "#newton-raphson method\n",
+ "#page 39\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x**3-2*x-5\n",
+ "def f1(x):\n",
+ " return 3*x**2-2 # first derivative of the function\n",
+ "x0=2.0 # initial value\n",
+ "d=0.0001\n",
+ "c=0\n",
+ "n=1\n",
+ "print \"successive iterations \\t x0 \\t f(x0) \\t f1(x0)\\n\"\n",
+ "while n==1:\n",
+ " x2=x0\n",
+ " x1=x0-(f(x0)/f1(x0))\n",
+ " x0=x1\n",
+ " print \" \\t%f \\t%f \\t%f \\n\" %(x2,f(x1),f1(x1))\n",
+ " c=c+1\n",
+ " if abs(f(x0))<d:\n",
+ " break\n",
+ "print \"the root of %i iteration is:%f\" %(c,x0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x0 \t f(x0) \t f1(x0)\n",
+ "\n",
+ " \t2.000000 \t0.061000 \t11.230000 \n",
+ "\n",
+ " \t2.100000 \t0.000186 \t11.161647 \n",
+ "\n",
+ " \t2.094568 \t0.000000 \t11.161438 \n",
+ "\n",
+ "the root of 3 iteration is:2.094551\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.16:pg-40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.16\n",
+ "#newton-raphson method\n",
+ "#page 40\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x*math.sin(x)+math.cos(x)\n",
+ "def f1(x):\n",
+ " return x*math.cos(x) #first derivation of the function\n",
+ "x0=math.pi # initial value\n",
+ "d=0.0001\n",
+ "c=0 \n",
+ "n=1\n",
+ "print \"successive iterations \\tx0\\t f(x0)\\t f1(x0)\\n\"\n",
+ "while n==1:\n",
+ " x2=x0\n",
+ " x1=x0-(f(x0)/f1(x0))\n",
+ " x0=x1\n",
+ " print \" \\t%f \\t%f \\t%f\\n\" %(x2,f(x1),f1(x1))\n",
+ " c=c+1\n",
+ " if abs(f(x0))<d:\n",
+ " break\n",
+ "print \"the root of %i iteration is:%f\" %(c,x0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \tx0\t f(x0)\t f1(x0)\n",
+ "\n",
+ " \t3.141593 \t-0.066186 \t-2.681457\n",
+ "\n",
+ " \t2.823283 \t-0.000564 \t-2.635588\n",
+ "\n",
+ " \t2.798600 \t-0.000000 \t-2.635185\n",
+ "\n",
+ "the root of 3 iteration is:2.798386\n"
+ ]
+ }
+ ],
+ "prompt_number": 46
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.17:pg-40"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.17\n",
+ "#newton-raphson method\n",
+ "#page 40\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x*math.exp(x)-1\n",
+ "def f1(x):\n",
+ " return math.exp(x)+x*math.exp(x) #first derivative of the function\n",
+ "x0=0 # initial value\n",
+ "d=0.0001 \n",
+ "c=0\n",
+ "n=1\n",
+ "print \"successive iterations \\tx0\\t f(x0)\\t f1(x0)\\n\"\n",
+ "while n==1:\n",
+ " x2=x0\n",
+ " x1=x0-(f(x0)/f1(x0))\n",
+ " x0=x1\n",
+ " print \" \\t%f \\t%f \\t%f\\n\" %(x2,f(x1),f1(x1))\n",
+ " c=c+1\n",
+ " if abs(f(x0))<d:\n",
+ " break\n",
+ "print \"the root of %i iteration is:%f\" %(c,x0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \tx0\t f(x0)\t f1(x0)\n",
+ "\n",
+ " \t0.000000 \t1.718282 \t5.436564\n",
+ "\n",
+ " \t1.000000 \t0.355343 \t3.337012\n",
+ "\n",
+ " \t0.683940 \t0.028734 \t2.810232\n",
+ "\n",
+ " \t0.577454 \t0.000239 \t2.763614\n",
+ "\n",
+ " \t0.567230 \t0.000000 \t2.763223\n",
+ "\n",
+ "the root of 5 iteration is:0.567143\n"
+ ]
+ }
+ ],
+ "prompt_number": 48
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.18:pg-41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.18\n",
+ "#newton-raphson method\n",
+ "#page 41\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.sin(x)-x/2.0\n",
+ "def f1(x):\n",
+ " return math.cos(x)-0.5\n",
+ "x0=math.pi/2.0 # initial value\n",
+ "d=0.0001\n",
+ "c=0\n",
+ "n=1\n",
+ "print \"successive iterations \\t x0 \\t f(x0)\\t f1(x0)\\n\"\n",
+ "while n==1:\n",
+ " x2=x0\n",
+ " x1=x0-(f(x0)/f1(x0))\n",
+ " x0=x1\n",
+ " print \" \\t%f\\t%f\\t%f\\n\" %(x2,f(x1),f1(x1))\n",
+ " c=c+1\n",
+ " if abs(f(x0))<d:\n",
+ " break\n",
+ "print \"the root of %i iteration is: %0.4g\" %(c,x0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x0 \t f(x0)\t f1(x0)\n",
+ "\n",
+ " \t1.570796\t-0.090703\t-0.916147\n",
+ "\n",
+ " \t2.000000\t-0.004520\t-0.824232\n",
+ "\n",
+ " \t1.900996\t-0.000014\t-0.819039\n",
+ "\n",
+ "the root of 3 iteration is: 1.896\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.19:pg-41"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.19\n",
+ "#newton-raphson method\n",
+ "#page 41\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 4*math.exp(-x)*math.sin(x)-1\n",
+ "def f1(x):\n",
+ " return math.cos(x)*4*math.exp(-x)-4*math.exp(-x)*math.sin(x)\n",
+ "x0=0.2 # initial value\n",
+ "d=0.0001\n",
+ "c=0 \n",
+ "n=1\n",
+ "print \"successive iterations \\t x0 \\t f(x0)\\t f1(x0)\\n\"\n",
+ "while n==1:\n",
+ " x2=x0\n",
+ " x1=x0-(f(x0)/f1(x0))\n",
+ " x0=x1\n",
+ " print \" \\t%f \\t%f \\t%f\\n\" %(x2,f(x1),f1(x1))\n",
+ " c=c+1\n",
+ " if abs(f(x0))<d:\n",
+ " break \n",
+ "print \"the root of %i iteration is: %0.3g\" %(c,x0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x0 \t f(x0)\t f1(x0)\n",
+ "\n",
+ " \t0.200000 \t-0.056593 \t1.753325\n",
+ "\n",
+ " \t0.336526 \t-0.002769 \t1.583008\n",
+ "\n",
+ " \t0.368804 \t-0.000008 \t1.573993\n",
+ "\n",
+ "the root of 3 iteration is: 0.371\n"
+ ]
+ }
+ ],
+ "prompt_number": 54
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.20:pg-42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.20\n",
+ "#generalized newton-raphson method\n",
+ "#page 42\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x**3-x**2-x+1\n",
+ "def f1(x):\n",
+ " return 3*x**2-2*x-1\n",
+ "def f2(x):\n",
+ " return 6*x-2\n",
+ "x0=0.8 # initial value to finf double root\n",
+ "n=1 \n",
+ "print \"successive iterations \\t x0 \\t x1\\t x2\\n\"\n",
+ "while n==1:\n",
+ " x1=x0-(f(x0)/f1(x0));\n",
+ " x2=x0-(f1(x0)/f2(x0));\n",
+ " if abs(x1-x2)<0.000000001:\n",
+ " x0=(x1+x2)/2.0\n",
+ " break\n",
+ " else:\n",
+ " x0=(x1+x2)/2;\n",
+ " print \" %f\\t %f\\t %f\\n\" %(x0,x1,x2)\n",
+ "print \"\\n \\nthe double root is at: %f\" %(x0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x0 \t x1\t x2\n",
+ "\n",
+ " 0.974370\t 0.905882\t 1.042857\n",
+ "\n",
+ " 0.993890\t 0.987269\t 1.000512\n",
+ "\n",
+ " 0.998489\t 0.996950\t 1.000028\n",
+ "\n",
+ " 0.999623\t 0.999245\t 1.000002\n",
+ "\n",
+ " 0.999906\t 0.999812\t 1.000000\n",
+ "\n",
+ " 0.999976\t 0.999953\t 1.000000\n",
+ "\n",
+ " 0.999994\t 0.999988\t 1.000000\n",
+ "\n",
+ " 0.999999\t 0.999997\t 1.000000\n",
+ "\n",
+ " 1.000000\t 0.999999\t 1.000000\n",
+ "\n",
+ " 1.000000\t 1.000000\t 1.000000\n",
+ "\n",
+ " 1.000000\t 1.000000\t 1.000000\n",
+ "\n",
+ " 1.000000\t 1.000000\t 1.000000\n",
+ "\n",
+ " 1.000000\t 1.000000\t 1.000000\n",
+ "\n",
+ "\n",
+ " \n",
+ "the double root is at: 1.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 57
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.21:pg-45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ramanujan's method\n",
+ "#example 2.21\n",
+ "#page 45\n",
+ "def f(x):\n",
+ " return 1-(13.0/12.0)*x-(3.0/8.0)*x**2+(1.0/24.0)*x**3\n",
+ "a1=13.0/12.0\n",
+ "a2=-3.0/8.0\n",
+ "a3=1.0/24.0\n",
+ "b1=1\n",
+ "b2=a1\n",
+ "b3=a1*b2+a2*b1\n",
+ "b4=a1*b3+a2*b2+a3*b1\n",
+ "b5=a1*b4+a2*b3+a3*b2\n",
+ "b6=a1*b5+a2*b4+a3*b3\n",
+ "b7=a1*b6+a2*b5+a3*b4\n",
+ "b8=a1*b7+a2*b6+a3*b5\n",
+ "b9=a1*b8+a2*b7+a3*b6\n",
+ "print \"\\n\\n%f\" %(b1/b2)\n",
+ "print \"\\n%f\" %(b2/b3)\n",
+ "print \"\\n%f\" %(b3/b4)\n",
+ "print \"\\n%f\" %(b4/b5)\n",
+ "print \"\\n%f\" %(b5/b6)\n",
+ "print \"\\n%f\" %(b6/b7)\n",
+ "print \"\\n%f\" %(b7/b8)\n",
+ "print \"\\n%f\" %(b8/b9)\n",
+ "print \"\\n it appears as if the roots are converging at 2\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "0.923077\n",
+ "\n",
+ "1.356522\n",
+ "\n",
+ "1.595376\n",
+ "\n",
+ "1.738402\n",
+ "\n",
+ "1.828184\n",
+ "\n",
+ "1.886130\n",
+ "\n",
+ "1.924153\n",
+ "\n",
+ "1.949345\n",
+ "\n",
+ " it appears as if the roots are converging at 2\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.22:pg-46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ramanujan's method\n",
+ "#example 2.22\n",
+ "#page 46\n",
+ "def f(x):\n",
+ " return x+x**2+(x**3)/2.0+(x**4)/6.0+(x**5)/24.0\n",
+ "a1=1.0\n",
+ "a2=1.0\n",
+ "a3=1.0/2.0\n",
+ "a4=1.0/6.0\n",
+ "a5=1.0/24.0\n",
+ "b1=1\n",
+ "b2=a2\n",
+ "b3=a1*b2+a2*b1\n",
+ "b4=a1*b3+a2*b2+a3*b1\n",
+ "b5=a1*b4+a2*b3+a3*b2\n",
+ "b6=a1*b5+a2*b4+a3*b3\n",
+ "print \"\\n%f\" %(b1/b2)\n",
+ "print \"\\n%f\" %(b2/b3)\n",
+ "print \"\\n%f\" %(b3/b4)\n",
+ "print \"\\n%f\" %(b4/b5)\n",
+ "print \"\\n%f\" %(b5/b6)\n",
+ "print \"\\n it appears as if the roots are converging at around %f\" %(b5/b6)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "1.000000\n",
+ "\n",
+ "0.500000\n",
+ "\n",
+ "0.571429\n",
+ "\n",
+ "0.583333\n",
+ "\n",
+ "0.571429\n",
+ "\n",
+ " it appears as if the roots are converging at around 0.571429\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.23:pg-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ramanujan's method\n",
+ "#example 2.23\n",
+ "#page 47\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return 1-2*((3*x/2.0+(x**2)/4.0-(x**4)/48.0+(x**6)/1440.0)-(x**8)*2/80640.0)\n",
+ "a1=3/2\n",
+ "a2=1/4\n",
+ "a3=0\n",
+ "a4=1/48\n",
+ "a5=0\n",
+ "a6=1/1440\n",
+ "a7=0\n",
+ "a8=-1/80640\n",
+ "b1=1\n",
+ "b2=a1\n",
+ "b3=a1*b2+a2*b1\n",
+ "b4=a1*b3+a2*b2+a3*b1\n",
+ "b5=a1*b4+a2*b3+a3*b2\n",
+ "b6=a1*b5+a2*b4+a3*b3\n",
+ "b7=a1*b6+a2*b5+a3*b4\n",
+ "b8=a1*b7+a2*b6+a3*b5\n",
+ "b9=a1*b8+a2*b7+a3*b6\n",
+ "print \"\\n%f\" %(b1/b2)\n",
+ "print \"\\n%f\" %(b2/b3)\n",
+ "print \"\\n%f\" %(b3/b4)\n",
+ "print \"\\n%f\" %(b4/b5)\n",
+ "print \"\\n%f\" %(b5/b6)\n",
+ "print \"\\n%f\" %(b6/b7)\n",
+ "print \"\\n%f\" %(b7/b8)\n",
+ "print \"\\n it appears as if the roots are converging at around %f\" %(b7/b8)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "0.666667\n",
+ "\n",
+ "0.600000\n",
+ "\n",
+ "0.606061\n",
+ "\n",
+ "0.605505\n",
+ "\n",
+ "0.605556\n",
+ "\n",
+ "0.605551\n",
+ "\n",
+ "0.605551\n",
+ "\n",
+ " it appears as if the roots are converging at around 0.605551\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.24:pg-47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ramanujan's method\n",
+ "#example 2.24\n",
+ "#page 47\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 1-(x-x**2.0/math.factorial(2.0)**2.0+x**3.0/math.factorial(3.0)**2.0-x**4.0/math.factorial(4.0)**2.0)\n",
+ "a1=1\n",
+ "a2=-1/math.factorial(2.0)**2.0\n",
+ "a3=1/math.factorial(3.0)**2.0\n",
+ "a4=-1/math.factorial(4.0)**2.0\n",
+ "a5=-1/math.factorial(5.0)**2.0\n",
+ "a6=1/math.factorial(6.0)**2.0\n",
+ "b1=1\n",
+ "b2=a1\n",
+ "b3=a1*b2+a2*b1\n",
+ "b4=a1*b3+a2*b2+a3*b1\n",
+ "b5=a1*b4+a2*b3+a3*b2\n",
+ "print \"\\n\\n%f\" %(b1/b2)\n",
+ "print \"\\n\\n%f\" %(b2/b3)\n",
+ "print \"\\n%f\" %(b3/b4)\n",
+ "print \"\\n%f\" %(b4/b5)\n",
+ "print \"\\n it appears as if the roots are converging at around %f\" %(b4/b5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ "1.000000\n",
+ "\n",
+ "\n",
+ "1.333333\n",
+ "\n",
+ "1.421053\n",
+ "\n",
+ "1.433962\n",
+ "\n",
+ " it appears as if the roots are converging at around 1.433962\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.25:pg-49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.25\n",
+ "#secant method\n",
+ "#page 49\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return x**3-2*x-5\n",
+ "x1=2\n",
+ "x2=3 # initial values\n",
+ "n=1\n",
+ "c=0\n",
+ "print \"successive iterations \\t x1 \\t x2 \\t x3 \\t f(x3)\\n\"\n",
+ "while n==1:\n",
+ " x3=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)) \n",
+ " print \" \\t%f \\t%f \\t%f \\t%f\\n\" %(x1,x2,x3,f(x3))\n",
+ " if f(x3)*f(x1)>0:\n",
+ " x2=x3;\n",
+ " else:\n",
+ " x1=x3 \n",
+ " if abs(f(x3))<0.000001: \n",
+ " break\n",
+ " c=c+1\n",
+ "print \"the root of the equation after %i iteration is: %f\" %(c,x3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x1 \t x2 \t x3 \t f(x3)\n",
+ "\n",
+ " \t2.000000 \t3.000000 \t2.058824 \t-0.390800\n",
+ "\n",
+ " \t2.000000 \t2.058824 \t2.096559 \t0.022428\n",
+ "\n",
+ " \t2.096559 \t2.058824 \t2.094511 \t-0.000457\n",
+ "\n",
+ " \t2.094511 \t2.058824 \t2.094552 \t0.000009\n",
+ "\n",
+ " \t2.094552 \t2.058824 \t2.094551 \t-0.000000\n",
+ "\n",
+ "the root of the equation after 4 iteration is: 2.094551\n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.26:pg-50"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 2.26\n",
+ "#secant method\n",
+ "#page 50\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return x*math.exp(x)-1\n",
+ "x1=0\n",
+ "x2=1 # initial values\n",
+ "n=1\n",
+ "c=0 \n",
+ "print \"successive iterations \\t x1 \\t x2 \\t x3 \\t f(x3)\\n\"\n",
+ "while n==1:\n",
+ " x3=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)) \n",
+ " print \" \\t%f \\t%f \\t%f \\t%f\\n\" %(x1,x2,x3,f(x3))\n",
+ " if f(x3)*f(x1)>0:\n",
+ " x2=x3\n",
+ " else:\n",
+ " x1=x3 \n",
+ " if abs(f(x3))<0.0001:\n",
+ " break\n",
+ " c=c+1\n",
+ "print \"the root of the equation after %i iteration is: %0.4g\" %(c,x3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x1 \t x2 \t x3 \t f(x3)\n",
+ "\n",
+ " \t0.000000 \t1.000000 \t0.367879 \t-0.468536\n",
+ "\n",
+ " \t0.000000 \t0.367879 \t0.692201 \t0.383091\n",
+ "\n",
+ " \t0.692201 \t0.367879 \t0.546310 \t-0.056595\n",
+ "\n",
+ " \t0.546310 \t0.367879 \t0.570823 \t0.010200\n",
+ "\n",
+ " \t0.570823 \t0.367879 \t0.566500 \t-0.001778\n",
+ "\n",
+ " \t0.566500 \t0.367879 \t0.567256 \t0.000312\n",
+ "\n",
+ " \t0.567256 \t0.367879 \t0.567124 \t-0.000055\n",
+ "\n",
+ "the root of the equation after 6 iteration is: 0.5671\n"
+ ]
+ }
+ ],
+ "prompt_number": 31
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.27:pg-52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# example 2.27\n",
+ "#mulller's method\n",
+ "#page 52\n",
+ "from __future__ import division\n",
+ "import math\n",
+ "def f(x):\n",
+ " return x**3-x-1\n",
+ "x0=0\n",
+ "x1=1\n",
+ "x2=2 # initial values\n",
+ "n=1\n",
+ "c=0\n",
+ "print \"successive iterations \\t x0 \\t x1 \\t x2 \\t f(x0)\\t f(x1)\\t f(x2)\\n\"\n",
+ "while n==1: \n",
+ " c=c+1\n",
+ " y0=f(x0)\n",
+ " y1=f(x1)\n",
+ " y2=f(x2)\n",
+ " h2=x2-x1\n",
+ " h1=x1-x0\n",
+ " d2=f(x2)-f(x1)\n",
+ " d1=f(x1)-f(x0)\n",
+ " print \" \\t%f\\t %f\\t %f\\t %f\\t %f\\t %f\\n\" %(x0,x1,x2,f(x0),f(x1),f(x2))\n",
+ " A=(d2/h2-d1/h1)/(h1+h2)\n",
+ " B=d2/h2+A*h2\n",
+ " S=math.sqrt(B**2-4*A*f(x2))\n",
+ " x3=x2-(2*f(x2))/(B+S)\n",
+ " E=abs((x3-x2)/x2)*100\n",
+ " if E<0.003:\n",
+ " break\n",
+ " else:\n",
+ " if c==1:\n",
+ " x2=x3\n",
+ " if c==2:\n",
+ " x1=x2\n",
+ " x2=x3\n",
+ " if c==3:\n",
+ " x0=x1\n",
+ " x1=x2\n",
+ " x2=x3\n",
+ " if c==3:\n",
+ " c=0\n",
+ "print \"the required root is : %0.4f\" %(x3)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "successive iterations \t x0 \t x1 \t x2 \t f(x0)\t f(x1)\t f(x2)\n",
+ "\n",
+ " \t0.000000\t 1.000000\t 2.000000\t -1.000000\t -1.000000\t 5.000000\n",
+ "\n",
+ " \t0.000000\t 1.000000\t 1.263763\t -1.000000\t -1.000000\t -0.245412\n",
+ "\n",
+ " \t0.000000\t 1.263763\t 1.331711\t -1.000000\t -0.245412\t 0.030015\n",
+ "\n",
+ " \t1.263763\t 1.331711\t 1.324583\t -0.245412\t 0.030015\t -0.000574\n",
+ "\n",
+ " \t1.263763\t 1.331711\t 1.324718\t -0.245412\t 0.030015\t -0.000000\n",
+ "\n",
+ "the required root is : 1.3247\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.28:pg-55"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#graeffe's method\n",
+ "#example 2.28\n",
+ "#page 55\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return x**3-6*(x**2)+11*x-6\n",
+ "print \"the equation is:\\n\"\n",
+ "A=[1, 14, 49, 36] #coefficients of the above equation\n",
+ "print \"%0.4g\\n\" %(math.sqrt(A[3]/A[2]))\n",
+ "print \"%0.4g\\n\" %(math.sqrt(A[2]/A[1]))\n",
+ "print \"%0.4g\\n\" %(math.sqrt(A[1]/A[0]))\n",
+ "print \"the equation is:\\n\"\n",
+ "B=[1, 98, 1393, 1296]\n",
+ "print \"%0.4g\\n\" %((B[3]/B[2])**(1/4))\n",
+ "print \"%0.4g\\n\" %((B[2]/B[1])**(1/4))\n",
+ "print \"%0.4g\\n\" %((B[1]/B[0])**(1/4))\n",
+ "print \"It is apparent from the outputs that the roots converge at 1 2 3\"\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the equation is:\n",
+ "\n",
+ "0.8571\n",
+ "\n",
+ "1.871\n",
+ "\n",
+ "3.742\n",
+ "\n",
+ "the equation is:\n",
+ "\n",
+ "0.9821\n",
+ "\n",
+ "1.942\n",
+ "\n",
+ "3.146\n",
+ "\n",
+ "It is apparent from the outputs that the roots converge at 1 2 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.29:pg-57"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#quadratic factor by lin's--bairsttow method\n",
+ "#example 2.29\n",
+ "#page 57\n",
+ "from numpy import matrix\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return x**3-x-1\n",
+ "a=[-1, -1, 0, 1]\n",
+ "r1=1\n",
+ "s1=1\n",
+ "b4=a[3]\n",
+ "def f3(r):\n",
+ " return a[2]-r*a[3]\n",
+ "def f2(r,s):\n",
+ " return a[1]-r*a[2]+r**2*a[3]-s*a[3]\n",
+ "def f1(r,s):\n",
+ " return a[0]-s*a[2]+s*r*a[3]\n",
+ "A=matrix([[1,1],[2,-1]])\n",
+ "C=matrix([[0],[1]])\n",
+ "X=A.I*C\n",
+ "X1=[[ 0.33333333],[-0.33333333]]\n",
+ "dr=X1[0][0]\n",
+ "ds=X1[1][0]\n",
+ "r2=r1+dr\n",
+ "s2=s1+ds\n",
+ "#second pproximation\n",
+ "r1=r2\n",
+ "s1=s2\n",
+ "b11=f1(r2,s2)\n",
+ "b22=f2(r2,s2)\n",
+ "h=0.001\n",
+ "dr_b1=(f1(r1+h,s1)-f1(r1,s1))/h\n",
+ "ds_b1=(f1(r1,s1+h)-f1(r1,s1))/h\n",
+ "dr_b2=(f2(r1+h,s1)-f2(r1,s1))/h\n",
+ "ds_b2=(f2(r1,s1+h)-f2(r1,s1))/h\n",
+ "A=matrix([[dr_b1,ds_b1],[dr_b2,ds_b2]])\n",
+ "C=matrix([[-f1(r1,s1)],[-f2(r1,s2)]])\n",
+ "X=A.I*C\n",
+ "r2=r1+X[0][0]\n",
+ "s2=s1+X[1][0]\n",
+ "print \"roots correct to 3 decimal places are : %0.3f %0.3f\" %(r2,s2)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "roots correct to 3 decimal places are : 1.325 0.754\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.31:pg-62"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#method of iteration\n",
+ "#example 2.31\n",
+ "#page 62\n",
+ "from __future__ import division\n",
+ "def f(x,y):\n",
+ " return (3*y*x**2+7)/10\n",
+ "def g(x,y):\n",
+ " return (y**2+4)/5\n",
+ "h=0.0001\n",
+ "x0=0.5\n",
+ "y0=0.5\n",
+ "f1_dx=(f(x0+h,y0)-f(x0,y0))/h\n",
+ "f1_dy=(f(x0,y0+h)-f(x0,y0))/h\n",
+ "g1_dx=(g(x0+h,y0)-g(x0,y0))/h\n",
+ "g1_dy=(g(x0+h,y0)-g(x0,y0))/h\n",
+ "if (f1_dx+f1_dy<1) and (g1_dx+g1_dy<1): \n",
+ " print \"coditions for convergence is satisfied\\n\\n\"\n",
+ "print \"X \\t Y\\t\\n\\n\"\n",
+ "for i in range(0,10):\n",
+ " X=(3*y0*x0**2+7)/10\n",
+ " Y=(y0**2+4)/5\n",
+ " print \"%f\\t %f\\t\\n\" %(X,Y)\n",
+ " x0=X\n",
+ " y0=Y\n",
+ "print \"\\n\\n CONVERGENCE AT (1 1) IS OBVIOUS\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "coditions for convergence is satisfied\n",
+ "\n",
+ "\n",
+ "X \t Y\t\n",
+ "\n",
+ "\n",
+ "0.737500\t 0.850000\t\n",
+ "\n",
+ "0.838696\t 0.944500\t\n",
+ "\n",
+ "0.899312\t 0.978416\t\n",
+ "\n",
+ "0.937391\t 0.991460\t\n",
+ "\n",
+ "0.961360\t 0.996598\t\n",
+ "\n",
+ "0.976320\t 0.998642\t\n",
+ "\n",
+ "0.985572\t 0.999457\t\n",
+ "\n",
+ "0.991247\t 0.999783\t\n",
+ "\n",
+ "0.994707\t 0.999913\t\n",
+ "\n",
+ "0.996807\t 0.999965\t\n",
+ "\n",
+ "\n",
+ "\n",
+ " CONVERGENCE AT (1 1) IS OBVIOUS\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.32:pg-65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#newton raphson metho\n",
+ "#example 2.32\n",
+ "#page 65\n",
+ "import numpy\n",
+ "def f(x,y):\n",
+ " return 3*y*x**2-10*x+7\n",
+ "def g(y):\n",
+ " return y**2-5*y+4\n",
+ "hh=0.0001\n",
+ "x0=0.5\n",
+ "y0=0.5 #initial values\n",
+ "f0=f(x0,y0)\n",
+ "g0=g(y0)\n",
+ "df_dx=(f(x0+hh,y0)-f(x0,y0))/hh\n",
+ "df_dy=(f(x0,y0+hh)-f(x0,y0))/hh\n",
+ "dg_dx=(g(y0)-g(y0))/hh\n",
+ "dg_dy=(g(y0+hh)-g(y0))/hh\n",
+ "d=[[df_dx,df_dy],[dg_dx,dg_dy]]\n",
+ "D1=numpy.linalg.det(d)\n",
+ "dd=[[-f0,df_dy],[-g0,dg_dy]]\n",
+ "h=numpy.linalg.det(dd)/D1\n",
+ "ddd=[[df_dx,-f0],[dg_dx,-g0]]\n",
+ "k=numpy.linalg.det(ddd)/D1;\n",
+ "x1=x0+h\n",
+ "y1=y0+k\n",
+ "f0=f(x1,y1)\n",
+ "g0=g(y1)\n",
+ "df_dx=(f(x1+hh,y1)-f(x1,y1))/hh\n",
+ "df_dy=(f(x1,y1+hh)-f(x1,y1))/hh\n",
+ "dg_dx=(g(y1)-g(y1))/hh\n",
+ "dg_dy=(g(y1+hh)-g(y1))/hh\n",
+ "dddd=[[df_dx,df_dy],[dg_dx,dg_dy]]\n",
+ "D2=numpy.linalg.det(dddd)\n",
+ "ddddd=[[-f0,df_dy],[-g0,dg_dy]]\n",
+ "h=numpy.linalg.det(ddddd)/D2\n",
+ "d6=[[df_dx,-f0],[dg_dx,-g0]]\n",
+ "k=numpy.linalg.det(d6)/D2\n",
+ "x2=x1+h\n",
+ "y2=y1+k\n",
+ "print \" the roots of the equation are x2=%f and y2=%f\" %(x2,y2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " the roots of the equation are x2=0.970803 and y2=0.998752\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.33:pg-66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#newton raphson method\n",
+ "#example 2.33\n",
+ "#page 66\n",
+ "import math\n",
+ "import numpy\n",
+ "def f(x,y):\n",
+ " return x**2+y**2-1\n",
+ "def g(x,y):\n",
+ " return y-x**2\n",
+ "hh=0.0001\n",
+ "x0=0.7071\n",
+ "y0=0.7071 #initial values\n",
+ "f0=f(x0,y0)\n",
+ "g0=g(x0,y0)\n",
+ "df_dx=(f(x0+hh,y0)-f(x0,y0))/hh\n",
+ "df_dy=(f(x0,y0+hh)-f(x0,y0))/hh\n",
+ "dg_dx=(g(x0+hh,y0)-g(x0,y0))/hh\n",
+ "dg_dy=(g(x0,y0+hh)-g(x0,y0))/hh\n",
+ "D1=numpy.linalg.det([[df_dx,df_dy],[dg_dx,dg_dy]])\n",
+ "h=numpy.linalg.det([[-f0,df_dy],[-g0,dg_dy]])/D1\n",
+ "k=numpy.linalg.det([[df_dx,-f0],[dg_dx,-g0]])/D1\n",
+ "x1=x0+h\n",
+ "y1=y0+k\n",
+ "f0=f(x1,y1)\n",
+ "g0=g(x1,y1)\n",
+ "df_dx=(f(x1+hh,y1)-f(x1,y1))/hh\n",
+ "df_dy=(f(x1,y1+hh)-f(x1,y1))/hh\n",
+ "dg_dx=(g(x1+hh,y1)-g(x1,y1))/hh\n",
+ "dg_dy=(g(x1,y1+hh)-g(x1,y1))/hh\n",
+ "D2=numpy.linalg.det([[df_dx,df_dy],[dg_dx,dg_dy]])\n",
+ "h=numpy.linalg.det([[-f0,df_dy],[-g0,dg_dy]])/D2\n",
+ "k=numpy.linalg.det([[df_dx,-f0],[dg_dx,-g0]])/D2\n",
+ "x2=x1+h\n",
+ "y2=y1+k\n",
+ "print \"the roots of the equation are x2=%f and y2=%f \" %(x2,y2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the roots of the equation are x2=0.786184 and y2=0.618039 \n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex2.34:pg-67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#newton raphson method\n",
+ "#example 2.34\n",
+ "#page 67\n",
+ "import math\n",
+ "import numpy\n",
+ "def f(x,y):\n",
+ " return math.sin(x)-y+0.9793\n",
+ "def g(x,y):\n",
+ " return math.cos(y)-x+0.6703\n",
+ "hh=0.0001\n",
+ "x0=0.5\n",
+ "y0=1.5 #initial values\n",
+ "f0=f(x0,y0)\n",
+ "g0=g(x0,y0)\n",
+ "df_dx=(f(x0+hh,y0)-f(x0,y0))/hh\n",
+ "df_dy=(f(x0,y0+hh)-f(x0,y0))/hh\n",
+ "dg_dx=(g(x0+hh,y0)-g(x0,y0))/hh\n",
+ "dg_dy=(g(x0,y0+hh)-g(x0,y0))/hh\n",
+ "d1=[[df_dx,df_dy],[dg_dx,dg_dy]]\n",
+ "D1=numpy.linalg.det(d1)\n",
+ "d2=[[-f0,df_dy],[-g0,dg_dy]]\n",
+ "h=numpy.linalg.det(d2)/D1\n",
+ "d3=[[df_dx,-f0],[dg_dx,-g0]]\n",
+ "k=numpy.linalg.det(d3)/D1\n",
+ "x1=x0+h\n",
+ "y1=y0+k\n",
+ "f0=f(x1,y1)\n",
+ "g0=g(x1,y1)\n",
+ "df_dx=(f(x1+hh,y1)-f(x1,y1))/hh\n",
+ "df_dy=(f(x1,y1+hh)-f(x1,y1))/hh\n",
+ "dg_dx=(g(x1+hh,y1)-g(x1,y1))/hh\n",
+ "dg_dy=(g(x1,y1+hh)-g(x1,y1))/hh\n",
+ "d4=[[df_dx,df_dy],[dg_dx,dg_dy]]\n",
+ "D2=numpy.linalg.det(d4)\n",
+ "h=numpy.linalg.det([[-f0,df_dy],[-g0,dg_dy]])/D2\n",
+ "k=numpy.linalg.det([[df_dx,-f0],[dg_dx,-g0]])/D2\n",
+ "x2=x1+h\n",
+ "y2=y1+k\n",
+ "print \"the roots of the equation are x2=%0.4f and y2=%0.4f\" %(x2,y2)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the roots of the equation are x2=0.6537 and y2=1.5874\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter3_(1)_1.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter3_(1)_1.ipynb new file mode 100644 index 00000000..e32d12d6 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter3_(1)_1.ipynb @@ -0,0 +1,1130 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:015160847087ed6879696359da8f3bf9f55e4d5e926aa29f46b690e2815a2fa2"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter03:Interpolation"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.4:pg-86"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.4\n",
+ "#interpolation\n",
+ "#page 86\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "x=[1, 3, 5, 7]\n",
+ "y=[24, 120, 336, 720]\n",
+ "d1=[0,0,0]\n",
+ "d2=[0,0,0]\n",
+ "d3=[0,0,0]\n",
+ "h=2 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1\n",
+ "d=[0,d1[0],d2[0],d3[0]]\n",
+ "x0=8 #value at 8\n",
+ "pp=1\n",
+ "y_x=y[0]\n",
+ "p=(x0-1)/2\n",
+ "for i in range(1,4):\n",
+ " pp=1\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+(pp*d[i])/math.factorial(i)\n",
+ "print \"value of function at %f is :%f\" %(x0,y_x)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of function at 8.000000 is :990.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.6:pg-87"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.6\n",
+ "#interpolation\n",
+ "#page 87\n",
+ "import math\n",
+ "x=[15, 20, 25, 30, 35, 40]\n",
+ "y=[0.2588190, 0.3420201, 0.4226183, 0.5, 0.5735764, 0.6427876]\n",
+ "d1=[0,0,0,0,0]\n",
+ "d2=[0,0,0,0]\n",
+ "d3=[0,0,0]\n",
+ "d4=[0,0]\n",
+ "d5=[0]\n",
+ "h=5 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d5[c]=d4[i+1]-d4[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "d=[0,d1[0], d2[0], d3[0], d4[0], d5[0]]\n",
+ "x0=38 #value at 38 degree\n",
+ "pp=1\n",
+ "y_x=y[0]\n",
+ "p=(x0-x[0])/h\n",
+ "for i in range(1,6):\n",
+ " pp=1\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+((pp*d[i])/math.factorial(i));\n",
+ "print \"value of function at %i is :%f\" %(x0,y_x)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of function at 38 is :0.615661\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.7:pg-89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.7\n",
+ "#interpolation\n",
+ "#page 89\n",
+ "x=[0, 1, 2, 4]\n",
+ "y=[1, 3, 9, 81]\n",
+ "#equation is y(5)-4*y(4)+6*y(2)-4*y(2)+y(1)\n",
+ "y3=(y[3]+6*y[2]-4*y[1]+y[0])/4\n",
+ "print \"the value of missing term of table is :%d\" %(y3)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of missing term of table is :31\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.8:pg-89"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.8\n",
+ "#interpolation\n",
+ "#page 89\n",
+ "import math\n",
+ "x=[0.10, 0.15, 0.20, 0.25, 0.30]\n",
+ "y=[0.1003, 0.1511, 0.2027, 0.2553, 0.3093]\n",
+ "d1=[0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0,0]\n",
+ "d4=[0,0,0,0,0]\n",
+ "h=0.05 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1\n",
+ "d=[0,d1[0], d2[0], d3[0], d4[0]]\n",
+ "x0=0.12 #value at 0.12;\n",
+ "pp=1\n",
+ "y_x=y[0]\n",
+ "p=(x0-x[0])/h\n",
+ "for i in range(1,5):\n",
+ " pp=1;\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+(pp*d[i])/math.factorial(i)\n",
+ "print \"value of function at %f is :%0.4g\\n \\n\" %(x0,y_x)\n",
+ "x0=0.26 #value at 0.26;\n",
+ "pp=1\n",
+ "y_x=y[0]\n",
+ "p=(x0-x[0])/h\n",
+ "for i in range(1,5):\n",
+ " pp=1\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+(pp*d[i])/math.factorial(i);\n",
+ "print \"value of function at %f is :%0.4g\\n \\n\" %(x0,y_x)\n",
+ "x0=0.40 #value at 0.40;\n",
+ "pp=1\n",
+ "y_x=y[0]\n",
+ "p=(x0-x[0])/h\n",
+ "for i in range(1,5):\n",
+ " pp=1\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+(pp*d[i])/math.factorial(i)\n",
+ "print \"value of function at %f is :%0.4g\\n \\n\" %(x0,y_x)\n",
+ "x0=0.50 #value at 0.50;\n",
+ "pp=1\n",
+ "y_x=y[0]\n",
+ "p=(x0-x[0])/h\n",
+ "for i in range(1,5):\n",
+ " pp=1\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+(pp*d[i])/math.factorial(i)\n",
+ "print \"value of function at %f is :%0.5g\\n \\n\" %(x0,y_x)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of function at 0.120000 is :0.1205\n",
+ " \n",
+ "\n",
+ "value of function at 0.260000 is :0.266\n",
+ " \n",
+ "\n",
+ "value of function at 0.400000 is :0.4241\n",
+ " \n",
+ "\n",
+ "value of function at 0.500000 is :0.5543\n",
+ " \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 33
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.9:pg-93"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.9\n",
+ "#Gauss' forward formula\n",
+ "#page 93\n",
+ "import math\n",
+ "x=[1.0, 1.05, 1.10, 1.15, 1.20, 1.25, 1.30];\n",
+ "y=[2.7183, 2.8577, 3.0042, 3.1582, 3.3201, 3.4903, 3.66693]\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "d5=[0,0]\n",
+ "d6=[0]\n",
+ "h=0.05 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d5[c]=d4[i+1]-d4[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d6[c]=d5[i+1]-d5[i]\n",
+ " c=c+1\n",
+ "d=[0,d1[3], d2[2], d3[2], d4[1], d5[0], d6[0]]\n",
+ "x0=1.17 #value at 1.17;\n",
+ "pp=1\n",
+ "y_x=y[3]\n",
+ "p=(x0-x[3])/h\n",
+ "for i in range(1,6):\n",
+ " pp=1;\n",
+ " for j in range(0,i):\n",
+ " pp=pp*(p-(j)) \n",
+ " y_x=y_x+(pp*d[i])/math.factorial(i)\n",
+ "print \"value of function at %f is :%0.4g\\n \\n\" %(x0,y_x)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value of function at 1.170000 is :3.222\n",
+ " \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.10:pg-97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#practical interpolation\n",
+ "#example 3.10\n",
+ "#page 97\n",
+ "import math\n",
+ "x=[0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67]\n",
+ "y=[1.840431, 1.858928,1.877610, 1.896481, 1.915541, 1.934792, 1.954237]\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "h=0.01 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i];\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i];\n",
+ " c=c+1\n",
+ "d=[d1[0], d2[0], d3[0], d4[0]]\n",
+ "x0=0.644\n",
+ "p=(x0-x[3])/h;\n",
+ "y_x=y[3]\n",
+ "y_x=y_x+p*(d1[2]+d1[3])/2+p**2*(d2[1])/2 #stirling formula\n",
+ "print \"the value at %f by stirling formula is : %f\\n\\n\" %(x0,y_x)\n",
+ "y_x=y[3]\n",
+ "y_x=y_x+p*d1[3]+p*(p-1)*(d2[2]+d2[3])/2\n",
+ "print \" the value at %f by bessels formula is : %f\\n\\n\" %(x0,y_x)\n",
+ "y_x=y[3]\n",
+ "q=1-p\n",
+ "y_x=q*y[3]+q*(q**2-1)*d2[2]/2+p*y[4]+p*(q**2-1)*d2[4]/2\n",
+ "print \"the value at %f by everrets formula is : %f\\n\\n\" %(x0,y_x)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value at 0.644000 by stirling formula is : 1.904082\n",
+ "\n",
+ "\n",
+ " the value at 0.644000 by bessels formula is : 1.904059\n",
+ "\n",
+ "\n",
+ "the value at 0.644000 by everrets formula is : 1.904044\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.11:pg-99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#practical interpolation\n",
+ "#example 3.11\n",
+ "#page 99\n",
+ "x=[0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67]\n",
+ "y=[1.840431, 1.858928, 1.877610, 1.896481, 1.915541, 1.934792, 1.954237]\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "h=0.01 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1\n",
+ "d=[d1[0], d2[0], d3[0], d4[0]]\n",
+ "x0=0.638\n",
+ "p=(x0-x[3])/h\n",
+ "y_x=y[3]\n",
+ "y_x=y_x+p*(d1[2]+d1[3])/2+p**2*(d2[1])/2 #stirling formula\n",
+ "print \"value at %f by stirling formula is : %f\\n\\n\" %(x0,y_x)\n",
+ "y_x=y[2]\n",
+ "p=(x0-x[2])/h\n",
+ "y_x=y_x+p*d1[2]+p*(p-1)*(d2[1])/2\n",
+ "print \"the value at %f by bessels formula is : %f\\n\\n\" %(x0,y_x)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "value at 0.638000 by stirling formula is : 1.892692\n",
+ "\n",
+ "\n",
+ "the value at 0.638000 by bessels formula is : 1.892692\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.12:pg-99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#practical interpolation\n",
+ "#example 3.12\n",
+ "#page 99\n",
+ "x=[1.72, 1.73, 1.74, 1.75, 1.76, 1.77, 1.78]\n",
+ "y=[0.1790661479, 0.1772844100, 0.1755204006, 0.1737739435, 0.1720448638, 0.1703329888, 0.1686381473]\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "h=0.01 #interval between values of x\n",
+ "c=0\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1\n",
+ "x0=1.7475\n",
+ "y_x=y[2]\n",
+ "p=(x0-x[2])/h\n",
+ "y_x=y_x+p*d1[2]+p*(p-1)*((d2[1]+d2[2])/2)/2\n",
+ "print \"the value at %f by bessels formula is : %0.10f\\n\\n\" %(x0,y_x)\n",
+ "y_x=y[3]\n",
+ "q=1-p\n",
+ "y_x=q*y[2]+q*(q**2-1)*d2[1]/6+p*y[3]+p*(p**2-1)*d2[1]/6\n",
+ "print \"the value at %f by everrets formula is : %0.10f\\n\\n\" %(x0,y_x)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value at 1.747500 by bessels formula is : 0.1742089204\n",
+ "\n",
+ "\n",
+ "the value at 1.747500 by everrets formula is : 0.1742089122\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.13:pg-104"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.13\n",
+ "#lagrange's interpolation formula\n",
+ "#page 104\n",
+ "x=[300, 304, 305, 307]\n",
+ "y=[2.4771, 2.4829, 2.4843, 2.4871]\n",
+ "x0=301\n",
+ "log_301=(-3*-4*-6*2.4771)/(-4*-5*-7)+(-4*-6*2.4829)/(4*-1*-3)+(-3*-6*2.4843)/(5*-2)+(-3*-4*2.4871)/(7*3*2)\n",
+ "print \"valie of log x at 301 is =%f\" %(log_301)\n",
+ "\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "valie of log x at 301 is =2.478597\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.14:pg-105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.14\n",
+ "#lagrange's interpolation formula\n",
+ "#page 105\n",
+ "y=[4, 12, 19]\n",
+ "x=[1, 3, 4];\n",
+ "y_x=7\n",
+ "Y_X=(-5*-12)/(-8*-15)+(3*3*-12)/(8*-7)+(3*-5*4)/(15*7)\n",
+ "print \"values is %f\" %(Y_X)\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "values is 1.857143\n"
+ ]
+ }
+ ],
+ "prompt_number": 44
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.15:pg-105"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.15\n",
+ "#lagrange's interpolation formula\n",
+ "#page 105\n",
+ "import math\n",
+ "x=[2, 2.5, 3.0]\n",
+ "y=[0.69315, 0.91629, 1.09861]\n",
+ "def l0(x):\n",
+ " return (x-2.5)*(x-3.0)/(-0.5)*(-1.0)\n",
+ "def l1(x):\n",
+ " return ((x-2.0)*(x-3.0))/((0.5)*(-0.5))\n",
+ "def l2(x):\n",
+ " return ((x-2.0)*(x-2.5))/((1.0)*(0.5))\n",
+ "f_x=l0(2.7)*y[0]+l1(2.7)*y[1]+l2(2.7)*y[2];\n",
+ "print \"the calculated value is %f:\" %(f_x)\n",
+ "print \"\\n\\n the error occured in the value is %0.9f\" %(abs(f_x-log(2.7)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the calculated value is 0.994116:\n",
+ "\n",
+ "\n",
+ " the error occured in the value is 0.000864627\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.16:pg-106"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.16\n",
+ "#lagrange's interpolation formula\n",
+ "#page 106\n",
+ "import math\n",
+ "x=[0, math.pi/4,math.pi/2]\n",
+ "y=[0, 0.70711, 1.0];\n",
+ "x0=math.pi/6\n",
+ "sin_x0=0\n",
+ "for i in range(0,3):\n",
+ " p=y[i]\n",
+ " for j in range(0,3):\n",
+ " if j!=i:\n",
+ " p=p*((x0-x[j])/( x[i]-x[j]))\n",
+ " sin_x0=sin_x0+p\n",
+ "print \"sin_x0=%f\" %(sin_x0)\n",
+ " "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "sin_x0=0.517431\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.18:pg-107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#error in lagrange's interpolation formula\n",
+ "#example 3.18\n",
+ "#page 107\n",
+ "import math\n",
+ "x=[2, 2.5, 3.0]\n",
+ "y=[0.69315, 0.91629, 1.09861]\n",
+ "def l0(x):\n",
+ " return (x-2.5)*(x-3.0)/(-0.5)*(-1.0)\n",
+ "def l1(x):\n",
+ " return ((x-2.0)*(x-3.0))/((0.5)*(-0.5))\n",
+ "def l2(x):\n",
+ " return ((x-2.0)*(x-2.5))/((1.0)*(0.5))\n",
+ "f_x=l0(2.7)*y[0]+l1(2.7)*y[1]+l2(2.7)*y[2]\n",
+ "print \"the calculated value is %f:\" %(f_x)\n",
+ "err=math.fabs(f_x-math.log10(2.7))\n",
+ "def R_n(x):\n",
+ " return (((x-2)*(x-2.5)*(x-3))/6)\n",
+ "est_err=abs(R_n(2.7)*(2/8))\n",
+ "if est_err<err:\n",
+ " print \"\\n\\n the error agrees with the actual error\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the calculated value is 0.994116:\n",
+ "\n",
+ "\n",
+ " the error agrees with the actual error\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.19:pg-107"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#error in lagrenge's interpolation\n",
+ "#example 3.19\n",
+ "#page 107\n",
+ "import math\n",
+ "x=[0, math.pi/4 ,math.pi/2]\n",
+ "y=[0, 0.70711, 1.0]\n",
+ "def l0(x):\n",
+ " return ((x-0)*(x-math.pi/2))/((math.pi/4)*(-1*math.pi/4))\n",
+ "def l1(x):\n",
+ " return ((x-0)*(x-math.pi/4))/((math.pi/2)*(math.pi/4))\n",
+ "f_x=l0(math.pi/6)*y[1]+l1(math.pi/6)*y[2]\n",
+ "err=abs(f_x-math.sin(math.pi/6))\n",
+ "def f(x):\n",
+ " return ((x-0)*(x-math.pi/4)*(x-math.pi/2))/6\n",
+ "if abs(f(math.pi/6))>err:\n",
+ " print \"\\n\\n the error agrees with the actual error\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "\n",
+ " the error agrees with the actual error\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.21:pg-110"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#hermite's interpolation formula\n",
+ "#exammple 3.21\n",
+ "#page 110\n",
+ "from __future__ import division\n",
+ "import math\n",
+ "x=[2.0, 2.5, 3.0]\n",
+ "y=[0.69315, 0.91629, 1.09861]\n",
+ "y1=[0,0,0]\n",
+ "def f(x):\n",
+ " return math.log(x)\n",
+ "h=0.0001\n",
+ "for i in range(0,3):\n",
+ " y1[i]=(f(x[i]+h)-f(x[i]))/h\n",
+ "def l0(x):\n",
+ " return (x-2.5)*(x-3.0)/(-0.5)*(-1.0)\n",
+ "def l1(x):\n",
+ " return ((x-2.0)*(x-3.0))/((0.5)*(-0.5))\n",
+ "def l2(x):\n",
+ " return ((x-2.0)*(x-2.5))/((1.0)*(0.5))\n",
+ "dl0=(l0(x[0]+h)-l0(x[0]))/h\n",
+ "dl1=(l1(x[1]+h)-l1(x[1]))/h\n",
+ "dl2=(l2(x[2]+h)-l2(x[2]))/h\n",
+ "x0=2.7\n",
+ "u0=(1-2*(x0-x[0])*dl0)*(l0(x0))**2\n",
+ "u1=(1-2*(x0-x[1])*dl1)*(l1(x0))**2\n",
+ "u2=(1-2*(x0-x[2])*dl2)*(l2(x0))**2\n",
+ "v0=(x0-x[0])*l0(x0)**2\n",
+ "v1=(x0-x[1])*l1(x0)**2\n",
+ "v2=(x0-x[2])*l2(x0)**2\n",
+ "H=u0*y[0]+u1*y[1]+u2*y[2]+v0*y1[0]+v1*y1[1]+v2*y1[2]\n",
+ "print \"the approximate value of ln(%0.2f) is %f:\" %(x0,H)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the approximate value of ln(2.70) is 0.993362:\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.22:pg-114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#newton's general interpolation formula\n",
+ "#example 3.22\n",
+ "#page 114\n",
+ "x=[300, 304, 305, 307]\n",
+ "y=[2.4771, 2.4829, 2.4843, 2.4871]\n",
+ "d1=[0,0,0]\n",
+ "d2=[0,0]\n",
+ "for i in range(0,3):\n",
+ " d1[i]=(y[i+1]-y[i])/(x[i+1]-x[i])\n",
+ "for i in range(0,2):\n",
+ " d2[i]=(d1[i+1]-d1[i])/(x[i+2]-x[i])\n",
+ "x0=301\n",
+ "log301=y[0]+(x0-x[0])*d1[0]+(x0-x[1])*d2[0]\n",
+ "print \"valure of log(%d) is :%0.4f\" %(x0,log301)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "valure of log(301) is :2.4786\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.23:pg-114"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 3.23\n",
+ "#newton's divided formula\n",
+ "#page 114\n",
+ "x=[-1, 0, 3, 6, 7]\n",
+ "y=[3, -6, 39, 822, 1611]\n",
+ "d1=[0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0,0]\n",
+ "d4=[0,0,0,0,0]\n",
+ "X=0\n",
+ "for i in range(0,3):\n",
+ " d1[i]=(y[i+1]-y[i])/(x[i+1]-x[i])\n",
+ "for i in range(0,3):\n",
+ " d2[i]=(d1[i+1]-d1[i])/(x[i+2]-x[i])\n",
+ "for i in range(0,2):\n",
+ " d3[i]=(d2[i+1]-d2[i])/(x[i+3]-x[i])\n",
+ "for i in range(0,1):\n",
+ " d4[i]=(d3[i+1]-d3[i])/(x[i+4]-x[i])\n",
+ "f_x=y[0]+(X-x[0])*d1[0]+(X-x[1])*(X-x[0])*d2[0]+(X-x[0])*(X-x[1])*(X-x[2])*d3[0]+(X-x[0])*(X-x[1])*(X-x[2])*(X-x[3])*d4[0]\n",
+ "print \"the polynomial equation is = -6 + 5X^2 -3X^3 +X^4\" "
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the polynomial equation is = -6 + 5X^2 -3X^3 +X^4\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.24:pg-116"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#interpolation by iteration\n",
+ "#example 3.24\n",
+ "#page 116\n",
+ "import numpy\n",
+ "x=[300, 304, 305, 307]\n",
+ "y=[2.4771, 2.4829, 2.4843, 2.4871]\n",
+ "x0=301\n",
+ "d1=[0,0,0]\n",
+ "d2=[0,0]\n",
+ "d3=[0]\n",
+ "for i in range(0,3):\n",
+ " a=y[i]\n",
+ " b=x[i]-x0\n",
+ " c=y[i+1]\n",
+ " e=x[i+1]-x0\n",
+ " d=matrix([[a,b],[c,e]])\n",
+ " d11=numpy.linalg.det(d)\n",
+ " d1[i]=d11/(x[i+1]-x[i])\n",
+ "for i in range(0,2):\n",
+ " a=d1[i]\n",
+ " b=x[i+1]-x0\n",
+ " c=d1[i+1]\n",
+ " e=x[i+2]-x0\n",
+ " d=matrix([[a,b],[c,e]])\n",
+ " d22=numpy.linalg.det(d)\n",
+ " f=(x[i+2]-x[i+1])\n",
+ " d2[i]=d22/f\n",
+ "for i in range(0,1):\n",
+ " a=d2[i]\n",
+ " b=x[i+2]-x0\n",
+ " c=d2[i+1]\n",
+ " e=x[i+3]-x0\n",
+ " d=matrix([[a,b],[c,e]])\n",
+ " d33=numpy.linalg.det(d)\n",
+ " d3[i]=d33/(x[i+3]-x[i+2])\n",
+ "print \"the value of log(%d) is : %f\" %(x0,d3[0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of log(301) is : 2.476900\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.25:pg-118"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#inverse intrpolation\n",
+ "#example 3.25\n",
+ "#page 118\n",
+ "from __future__ import division\n",
+ "x=[2, 3, 4, 5]\n",
+ "y=[8, 27, 64, 125]\n",
+ "d1=[0,0,0]\n",
+ "d2=[0,0]\n",
+ "d3=[0]\n",
+ "for i in range(0,3):\n",
+ " d1[i]=y[i+1]-y[i]\n",
+ "for i in range(0,2):\n",
+ " d2[i]=d1[i+1]-d1[i]\n",
+ "for i in range(0,1):\n",
+ " d3[i]=d2[i+1]-d2[i]\n",
+ "yu=10 #square rooot of 10\n",
+ "y0=y[0]\n",
+ "d=[d1[0], d2[0] ,d3[0]]\n",
+ "u1=(yu-y0)/d1[0]\n",
+ "u2=((yu-y0-u1*(u1-1)*d2[0]/2)/d1[0])\n",
+ "u3=(yu-y0-u2*(u2-1)*d2[0]/2-u2*(u2-1)*(u2-2)*d3[0]/6)/d1[0]\n",
+ "u4=(yu-y0-u3*(u3-1)*d2[0]/2-u3*(u3-1)*(u3-2)*d3[0]/6)/d1[0]\n",
+ "u5=(yu-y0-u4*(u4-1)*d2[0]/2-u4*(u4-1)*(u4-2)*d3[0]/6)/d1[0]\n",
+ "print \"%f \\n %f \\n %f \\n %f \\n %f \\n \" %(u1,u2,u3,u4,u5)\n",
+ "print \"the approximate square root of %d is: %0.3f\" %(yu,x[0]+u5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "0.105263 \n",
+ " 0.149876 \n",
+ " 0.153210 \n",
+ " 0.154107 \n",
+ " 0.154347 \n",
+ " \n",
+ "the approximate square root of 10 is: 2.154\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex3.26:pg-119"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#double interpolation \n",
+ "#example 3.26\n",
+ "#page 119\n",
+ "y=[0, 1, 2, 3, 4]\n",
+ "z=[0,0,0,0,0]\n",
+ "x=[[0, 1, 4, 9, 16],[2, 3, 6, 11, 18],[6, 7, 10, 15, 22],[12, 13, 16, 21, 28],[18, 19, 22, 27, 34]]\n",
+ "print \"X=\"\n",
+ "print x\n",
+ "#for x=2.5\n",
+ "for i in range(0,5):\n",
+ " z[i]=(x[i][2]+x[i][3])/2\n",
+ "#y=1.5\n",
+ "Z=(z[1]+z[2])/2\n",
+ "print \"the interpolated value when x=2.5 and y=1.5 is : %f\" %(Z)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X=\n",
+ "[[0, 1, 4, 9, 16], [2, 3, 6, 11, 18], [6, 7, 10, 15, 22], [12, 13, 16, 21, 28], [18, 19, 22, 27, 34]]\n",
+ "the interpolated value when x=2.5 and y=1.5 is : 10.500000\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter4_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter4_10.ipynb new file mode 100644 index 00000000..3cc767e6 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter4_10.ipynb @@ -0,0 +1,880 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4bd129a1095a40e7b77ec9dd303e159b079be83a90556977b8afeff8b76637f9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter04:Least Squares and Fourier Transforms"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.1:pg-128"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.1\n",
+ "#least square curve fitting procedure\n",
+ "#page 128\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "x=[0,1, 2, 3, 4, 5]\n",
+ "x_2=[0,0,0,0,0,0]\n",
+ "x_y=[0,0,0,0,0,0]\n",
+ "y=[0,0.6, 2.4, 3.5, 4.8, 5.7]\n",
+ "for i in range(1,5):\n",
+ " x_2[i]=x[i]**2\n",
+ " x_y[i]=x[i]*y[i]\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_x2=0 \n",
+ "S_xy=0\n",
+ "S1=0\n",
+ "S2=0\n",
+ "for i in range(1,5):\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_x2=S_x2+x_2[i]\n",
+ " S_xy=S_xy+x_y[i]\n",
+ "a1=(5*S_xy-S_x*S_y)/(5*S_x2-S_x**2)\n",
+ "a0=S_y/5-a1*S_x/5\n",
+ "print \"x\\t y\\t x^2\\t x*y\\t (y-avg(S_y)) \\t (y-a0-a1x)^2\\n\\n\"\n",
+ "for i in range (1,6):\n",
+ " print \"%d\\t %0.2f\\t %d\\t %0.2f\\t %0.2f\\t %.4f\\t\\n\" %(x[i],y[i],x_2[i],x_y[i],(y[i]-S_y/5)**2,(y[i]-a0-a1*x[i])**2)\n",
+ " S1=S1+(y[i]-S_y/5)**2 \n",
+ " S2=S2+(y[i]-a0-a1*x[i])**2\n",
+ "print \"---------------------------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %0.2f\\t %d\\t %0.2f\\t %0.2f\\t %0.4f\\t\\n\\n\" %(S_x,S_y,S_x2,S_xy,S1,S2)\n",
+ "cc=math.sqrt((S1-S2)/S1) #correlation coefficient\n",
+ "print \"the correlation coefficient is:%0.4f\" %(cc)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t x^2\t x*y\t (y-avg(S_y)) \t (y-a0-a1x)^2\n",
+ "\n",
+ "\n",
+ "1\t 0.60\t 1\t 0.60\t 2.76\t 0.1681\t\n",
+ "\n",
+ "2\t 2.40\t 4\t 4.80\t 0.02\t 0.0196\t\n",
+ "\n",
+ "3\t 3.50\t 9\t 10.50\t 1.54\t 0.0001\t\n",
+ "\n",
+ "4\t 4.80\t 16\t 19.20\t 6.45\t 0.0016\t\n",
+ "\n",
+ "5\t 5.70\t 0\t 0.00\t 11.83\t 0.0961\t\n",
+ "\n",
+ "---------------------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "10\t 11.30\t 30\t 35.10\t 22.60\t 0.2855\t\n",
+ "\n",
+ "\n",
+ "the correlation coefficient is:0.9937\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.2:pg-129"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.2\n",
+ "#least square curve fitting procedure\n",
+ "#page 129\n",
+ "from numpy import matrix\n",
+ "x=[0, 2, 5, 7]\n",
+ "y=[-1, 5, 12, 20]\n",
+ "x_2=[0,0,0,0]\n",
+ "xy=[0,0,0,0,]\n",
+ "for i in range (0,4):\n",
+ " x_2[i]=x[i]**2\n",
+ " xy[i]=x[i]*y[i]\n",
+ "print \"x\\t y\\t x^2\\t xy\\t \\n\\n\"\n",
+ "S_x=0 \n",
+ "S_y=0\n",
+ "S_x2=0\n",
+ "S_xy=0\n",
+ "for i in range(0,4):\n",
+ " print \"%d\\t %d\\t %d\\t %d\\t\\n\" %(x[i],y[i],x_2[i],xy[i])\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_x2=S_x2+x_2[i]\n",
+ " S_xy=S_xy+xy[i]\n",
+ "print \"%d\\t %d\\t %d\\t %d\\t\\n\" %(S_x,S_y,S_x2,S_xy)\n",
+ "A=matrix([[4,S_x],[S_x,S_x2]])\n",
+ "B=matrix([[S_y],[S_xy]])\n",
+ "C=A.I*B\n",
+ "print \"Best straight line fit Y=%.4f+x(%.4f)\" %(C[0][0],C[1][0])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t x^2\t xy\t \n",
+ "\n",
+ "\n",
+ "0\t -1\t 0\t 0\t\n",
+ "\n",
+ "2\t 5\t 4\t 10\t\n",
+ "\n",
+ "5\t 12\t 25\t 60\t\n",
+ "\n",
+ "7\t 20\t 49\t 140\t\n",
+ "\n",
+ "14\t 36\t 78\t 210\t\n",
+ "\n",
+ "Best straight line fit Y=-1.1379+x(2.8966)\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.3:pg-130"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.3\n",
+ "#least square curve fitting procedure\n",
+ "#page 130\n",
+ "from numpy import matrix\n",
+ "x=[0, 1, 2, 4, 6]\n",
+ "y=[0, 1, 3, 2, 8]\n",
+ "z=[2, 4, 3, 16, 8]\n",
+ "x2=[0,0,0,0,0]\n",
+ "y2=[0,0,0,0,0]\n",
+ "z2=[0,0,0,0,0]\n",
+ "xy=[0,0,0,0,0]\n",
+ "yz=[0,0,0,0,0]\n",
+ "zx=[0,0,0,0,0]\n",
+ "for i in range(0,5):\n",
+ " x2[i]=x[i]**2\n",
+ " y2[i]=y[i]**2\n",
+ " z2[i]=z[i]**2\n",
+ " xy[i]=x[i]*y[i]\n",
+ " zx[i]=z[i]*x[i]\n",
+ " yz[i]=y[i]*z[i]\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_z=0\n",
+ "S_x2=0\n",
+ "S_y2=0\n",
+ "S_z2=0\n",
+ "S_xy=0\n",
+ "S_zx=0\n",
+ "S_yz=0\n",
+ "for i in range(0,5):\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_z=S_z+z[i]\n",
+ " S_x2=S_x2+x2[i]\n",
+ " S_y2=S_y2+y2[i]\n",
+ " S_z2=S_z2+z2[i]\n",
+ " S_xy=S_xy+xy[i]\n",
+ " S_zx=S_zx+zx[i]\n",
+ " S_yz=S_yz+yz[i]\n",
+ "print \"x\\t y\\t z\\t x^2\\t xy\\t zx\\t y^2\\t yz\\n\\n\"\n",
+ "for i in range(0,5):\n",
+ " print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\n\" %(x[i],y[i],z[i],x2[i],xy[i],zx[i],y2[i],yz[i])\n",
+ "print \"-------------------------------- --------------------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\n\\n\" %(S_x,S_y,S_z,S_x2,S_xy,S_zx,S_y2,S_yz)\n",
+ "A=matrix([[5,13,14],[13,57,63],[14,63,78]])\n",
+ "B=matrix([[33],[122],[109]])\n",
+ "C=A.I*B\n",
+ "print \"solution of above equation is:a=%d b=%d c=%d\" %(C[0][0],C[1][0],C[2][0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t z\t x^2\t xy\t zx\t y^2\t yz\n",
+ "\n",
+ "\n",
+ "0\t 0\t 2\t 0\t 0\t 0\t 0\t 0\n",
+ "\n",
+ "1\t 1\t 4\t 1\t 1\t 4\t 1\t 4\n",
+ "\n",
+ "2\t 3\t 3\t 4\t 6\t 6\t 9\t 9\n",
+ "\n",
+ "4\t 2\t 16\t 16\t 8\t 64\t 4\t 32\n",
+ "\n",
+ "6\t 8\t 8\t 36\t 48\t 48\t 64\t 64\n",
+ "\n",
+ "-------------------------------- --------------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "13\t 14\t 33\t 57\t 63\t 122\t 78\t 109\n",
+ "\n",
+ "\n",
+ "solution of above equation is:a=2 b=5 c=-3\n"
+ ]
+ }
+ ],
+ "prompt_number": 37
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.4:pg-131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.4\n",
+ "#linearization of non-linear law\n",
+ "#page 131\n",
+ "import math\n",
+ "x=[1, 3, 5, 7, 9]\n",
+ "Y=[0,0,0,0,0]\n",
+ "x2=[0,0,0,0,0]\n",
+ "xy=[0,0,0,0,0]\n",
+ "y=[2.473, 6.722, 18.274, 49.673, 135.026]\n",
+ "for i in range(0,5):\n",
+ " Y[i]=math.log(y[i])\n",
+ " x2[i]=x[i]**2\n",
+ " xy[i]=x[i]*Y[i]\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_x2=0\n",
+ "S_xy=0\n",
+ "print \"X\\t Y=lny\\t X^2\\t XY\\n\\n\"\n",
+ "for i in range(0,5):\n",
+ " print \"%d\\t %0.3f\\t %d\\t %0.3f\\n\" %(x[i],Y[i],x2[i],xy[i])\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+Y[i]\n",
+ " S_x2=S_x2+x2[i]\n",
+ " S_xy=S_xy+xy[i]\n",
+ "print \"----------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %0.3f\\t %d\\t %0.3f\\t\\n\\n\" %(S_x,S_y,S_x2,S_xy)\n",
+ "A1=((S_x/5)*S_xy-S_x*S_y)/((S_x/5)*S_x2-S_x**2)\n",
+ "A0=(S_y/5)-A1*(S_x/5)\n",
+ "a=math.exp(A0)\n",
+ "print \"y=%0.3fexp(%0.2fx)\" %(a,A1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X\t Y=lny\t X^2\t XY\n",
+ "\n",
+ "\n",
+ "1\t 0.905\t 1\t 0.905\n",
+ "\n",
+ "3\t 1.905\t 9\t 5.716\n",
+ "\n",
+ "5\t 2.905\t 25\t 14.527\n",
+ "\n",
+ "7\t 3.905\t 49\t 27.338\n",
+ "\n",
+ "9\t 4.905\t 81\t 44.149\n",
+ "\n",
+ "----------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "25\t 14.527\t 165\t 92.636\t\n",
+ "\n",
+ "\n",
+ "y=1.500exp(0.50x)\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.5:pg-131"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.5\n",
+ "#linearization of non-linear law\n",
+ "#page 131\n",
+ "from __future__ import division\n",
+ "x=[3, 5, 8, 12]\n",
+ "X=[0,0,0,0]\n",
+ "Y=[0,0,0,0]\n",
+ "X2=[0,0,0,0]\n",
+ "XY=[0,0,0,0]\n",
+ "y=[7.148, 10.231, 13.509, 16.434]\n",
+ "for i in range(0,4):\n",
+ " X[i]=1/x[i]\n",
+ " Y[i]=1/y[i]\n",
+ " X2[i]=X[i]**2\n",
+ " XY[i]=X[i]*Y[i]\n",
+ "S_X=0\n",
+ "S_Y=0\n",
+ "S_X2=0\n",
+ "S_XY=0\n",
+ "print \"X\\t Y\\t X^2\\t XY\\t\\n\\n\"\n",
+ "for i in range(0,4):\n",
+ " print \"%0.3f\\t %0.3f\\t %0.3f\\t %0.3f\\t\\n\" %(X[i],Y[i],X2[i],XY[i])\n",
+ " S_X=S_X+X[i]\n",
+ " S_Y=S_Y+Y[i]\n",
+ " S_X2=S_X2+X2[i]\n",
+ " S_XY=S_XY+XY[i]\n",
+ "print \"----------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%0.3f\\t %0.3f\\t %0.3f\\t %0.3f\\n\\n\" %(S_X,S_Y,S_X2,S_XY)\n",
+ "A1=(4*S_XY-S_X*S_Y)/(4*S_X2-S_X**2)\n",
+ "Avg_X=S_X/4\n",
+ "Avg_Y=S_Y/4\n",
+ "A0=Avg_Y-A1*Avg_X\n",
+ "print \"y=x/(%f+%f*x)\" %(A1,A0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X\t Y\t X^2\t XY\t\n",
+ "\n",
+ "\n",
+ "0.333\t 0.140\t 0.111\t 0.047\t\n",
+ "\n",
+ "0.200\t 0.098\t 0.040\t 0.020\t\n",
+ "\n",
+ "0.125\t 0.074\t 0.016\t 0.009\t\n",
+ "\n",
+ "0.083\t 0.061\t 0.007\t 0.005\t\n",
+ "\n",
+ "----------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "0.742\t 0.373\t 0.174\t 0.081\n",
+ "\n",
+ "\n",
+ "y=x/(0.316200+0.034500*x)\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.6:pg-134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.6\n",
+ "#curve fitting by polynomial\n",
+ "#page 134\n",
+ "from numpy import matrix\n",
+ "x=[0, 1, 2]\n",
+ "y=[1, 6, 17]\n",
+ "x2=[0,0,0]\n",
+ "x3=[0,0,0]\n",
+ "x4=[0,0,0]\n",
+ "xy=[0,0,0]\n",
+ "x2y=[0,0,0]\n",
+ "for i in range(0,3):\n",
+ " x2[i]=x[i]**2\n",
+ " x3[i]=x[i]**3\n",
+ " x4[i]=x[i]**4\n",
+ " xy[i]=x[i]*y[i]\n",
+ " x2y[i]=x2[i]*y[i]\n",
+ "print \"x\\t y\\t x^2\\t x^3\\t x^4\\t x*y\\t x^2*y\\t\\n\\n\"\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_x2=0\n",
+ "S_x3=0\n",
+ "S_x4=0\n",
+ "S_xy=0\n",
+ "S_x2y=0\n",
+ "for i in range(0,3):\n",
+ " print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\n\" %(x[i],y[i],x2[i],x3[i],x4[i],xy[i],x2y[i])\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_x2=S_x2+x2[i]\n",
+ " S_x3=S_x3+x3[i]\n",
+ " S_x4=S_x4+x4[i]\n",
+ " S_xy=S_xy+xy[i]\n",
+ " S_x2y=S_x2y+x2y[i]\n",
+ "print \"--------------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\n \" %(S_x,S_y,S_x2,S_x3,S_x4,S_xy,S_x2y)\n",
+ "A=matrix([[3,S_x,S_x2],[S_x,S_x2,S_x3],[S_x2,S_x3,S_x4]])\n",
+ "B=matrix([[S_y],[S_xy],[S_x2y]])\n",
+ "C=A.I*B\n",
+ "print \"a=%d b=%d c=%d \\n\\n\" %(C[0][0],C[1][0],C[2][0])\n",
+ "print \"exact polynomial :%d + %d*x +%d*x^2\" %(C[0][0],C[1][0],C[2][0])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t x^2\t x^3\t x^4\t x*y\t x^2*y\t\n",
+ "\n",
+ "\n",
+ "0\t 1\t 0\t 0\t 0\t 0\t 0\n",
+ "\n",
+ "1\t 6\t 1\t 1\t 1\t 6\t 6\n",
+ "\n",
+ "2\t 17\t 4\t 8\t 16\t 34\t 68\n",
+ "\n",
+ "--------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "3\t 24\t 5\t 9\t 17\t 40\t 74\n",
+ " \n",
+ "a=1 b=2 c=3 \n",
+ "\n",
+ "\n",
+ "exact polynomial :1 + 2*x +3*x^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.7:pg-134"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 4.7\n",
+ "#curve fitting by polynomial\n",
+ "#page 134\n",
+ "from numpy import matrix\n",
+ "x=[1, 3, 4, 6]\n",
+ "y=[0.63, 2.05, 4.08, 10.78]\n",
+ "x2=[0,0,0,0]\n",
+ "x3=[0,0,0,0]\n",
+ "x4=[0,0,0,0]\n",
+ "xy=[0,0,0,0]\n",
+ "x2y=[0,0,0,0]\n",
+ "for i in range(0,4):\n",
+ " x2[i]=x[i]**2\n",
+ " x3[i]=x[i]**3\n",
+ " x4[i]=x[i]**4\n",
+ " xy[i]=x[i]*y[i]\n",
+ " x2y[i]=x2[i]*y[i]\n",
+ "print \"x\\t y\\t x^2\\t x^3\\t x^4\\t x*y\\t x^2*y\\t\\n\\n\"\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_x2=0\n",
+ "S_x3=0\n",
+ "S_x4=0\n",
+ "S_xy=0\n",
+ "S_x2y=0\n",
+ "for i in range(0,4):\n",
+ " print \"%d\\t %0.3f\\t %d\\t %d\\t %d\\t %0.3f\\t %d\\n\" %(x[i],y[i],x2[i],x3[i],x4[i],xy[i],x2y[i])\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_x2=S_x2+x2[i]\n",
+ " S_x3=S_x3+x3[i]\n",
+ " S_x4=S_x4+x4[i]\n",
+ " S_xy=S_xy+xy[i]\n",
+ " S_x2y=S_x2y+x2y[i]\n",
+ "print \"---------------------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %0.3f\\t %d\\t %d\\t %d\\t %0.3f\\t %0.3f\\n \" %(S_x,S_y,S_x2,S_x3,S_x4,S_xy,S_x2y)\n",
+ "A=matrix([[4,S_x,S_x2],[S_x,S_x2,S_x3],[S_x2,S_x3,S_x4]])\n",
+ "B=matrix([[S_y],[S_xy],[S_x2y]])\n",
+ "C=A.I*B\n",
+ "print \"a=%0.2f b=%0.2f c=%0.2f \\n\\n\" %(C[0][0],C[1][0],C[2][0])\n",
+ "print \"exact polynomial :%0.2f + %0.2f*x +%0.2f*x^2\" %(C[0][0],C[1][0],C[2][0])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t x^2\t x^3\t x^4\t x*y\t x^2*y\t\n",
+ "\n",
+ "\n",
+ "1\t 0.630\t 1\t 1\t 1\t 0.630\t 0\n",
+ "\n",
+ "3\t 2.050\t 9\t 27\t 81\t 6.150\t 18\n",
+ "\n",
+ "4\t 4.080\t 16\t 64\t 256\t 16.320\t 65\n",
+ "\n",
+ "6\t 10.780\t 36\t 216\t 1296\t 64.680\t 388\n",
+ "\n",
+ "---------------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "14\t 17.540\t 62\t 308\t 1634\t 87.780\t 472.440\n",
+ " \n",
+ "a=1.24 b=-1.05 c=0.44 \n",
+ "\n",
+ "\n",
+ "exact polynomial :1.24 + -1.05*x +0.44*x^2\n"
+ ]
+ }
+ ],
+ "prompt_number": 42
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.8:pg-137"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#curve fitting by sum of exponentials\n",
+ "#example 4.8\n",
+ "#page 137\n",
+ "import math\n",
+ "from numpy import matrix\n",
+ "x=[1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8]\n",
+ "y=[1.54, 1.67, 1.81, 1.97, 2.15, 2.35, 2.58, 2.83, 3.11]\n",
+ "y1=[0,0,0,0,0,0,0,0,0]\n",
+ "y2=[0,0,0,0,0,0,0,0,0]\n",
+ "s1=y[0]+y[4]-2*y[2]\n",
+ "h=x[1]-x[0]\n",
+ "I1=0\n",
+ "for i in range(0,3):\n",
+ " if i==0|i==2:\n",
+ " I1=I1+y[i]\n",
+ " elif i%2==0:\n",
+ " I1=I1+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " I1=I1+2*y[i] \n",
+ " I1=(I1*h)/3\n",
+ "\n",
+ "I2=0\n",
+ "for i in range(2,4):\n",
+ " if i==2|i==4:\n",
+ " I2=I2+y(i)\n",
+ " elif i%2==0:\n",
+ " I2=I2+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " I2=I2+2*y[i] \n",
+ " \n",
+ " I2=(I2*h)/3\n",
+ " for i in range(0,4):\n",
+ " y1[i]=(1.0-x[i])*y[i]\n",
+ " for i in range(4,8):\n",
+ " y2[i]=(1.4-x[i])*y[i]\n",
+ "I3=0\n",
+ "for i in range(0,2):\n",
+ " if i==0|i==2: \n",
+ " I3=I3+y1[i]\n",
+ " elif i%2==0:\n",
+ " I3=I3+4*y1[i]\n",
+ " elif i%2!=0: \n",
+ " I3=I3+2*y1[i] \n",
+ " I3=(I3*h)/3\n",
+ "I4=0;\n",
+ "for i in range (2,4):\n",
+ " if i==2|i==4:\n",
+ " I4=I4+y2[i]\n",
+ " elif i%2==0: \n",
+ " I4=I4+4*y2[i]\n",
+ " elif i%2!=0:\n",
+ " I4=I4+2*y2[i] \n",
+ " I4=(I4*h)/3\n",
+ " s2=y[4]+y[8]-2*y[6]\n",
+ "I5=0\n",
+ "for i in range(4,6):\n",
+ " if i==4|i==6: \n",
+ " I5=I5+y[i]\n",
+ " elif i%2==0:\n",
+ " I5=I5+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " I5=I5+2*y[i] \n",
+ " I5=(I5*h)/3\n",
+ "I6=0\n",
+ "for i in range(6,8):\n",
+ " if i==6|i==8:\n",
+ " I6=I6+y[i]\n",
+ " elif i%2==0:\n",
+ " I6=I6+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " I6=I6+2*y[i]\n",
+ " I6=(I6*h)/3\n",
+ "I7=0\n",
+ "for i in range(4,6):\n",
+ " if i==4|i==6:\n",
+ " I7=I7+y2[i]\n",
+ " elif i%2==0: \n",
+ " I7=I7+4*y2[i]\n",
+ " elif i%2!=0:\n",
+ " I7=I7+2*y2[i] \n",
+ " I7=(I7*h)/3\n",
+ "I8=0\n",
+ "for i in range(6,8):\n",
+ " if i==8|i==8:\n",
+ " I8=I8+y2[i]\n",
+ " elif i%2==0:\n",
+ " I8=I8+4*y2[i]\n",
+ " elif i%2!=0:\n",
+ " I8=I8+2*y2[i]\n",
+ " I8=(I8*h)/3\n",
+ "A=matrix([[1.81, 2.180],[2.88, 3.104]])\n",
+ "C=matrix([[2.10],[3.00]])\n",
+ "Z=A.I*C\n",
+ "p = np.poly1d([1,Z[0][0],Z[1][0]])\n",
+ "print \"the unknown value of equation is 1 -1 \" \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the unknown value of equation is 1 -1 \n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Es4.9:pg-139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#linear weighted least approx\n",
+ "#example 4.9\n",
+ "#page 139\n",
+ "from numpy import matrix\n",
+ "x=[0, 2, 5, 7]\n",
+ "y=[-1, 5, 12, 20]\n",
+ "w=10 #given weight 10\n",
+ "W=[1, 1, 10, 1]\n",
+ "Wx=[0,0,0,0]\n",
+ "Wx2=[0,0,0,0]\n",
+ "Wx3=[0,0,0,0]\n",
+ "Wy=[0,0,0,0]\n",
+ "Wxy=[0,0,0,0]\n",
+ "for i in range(0,4):\n",
+ " Wx[i]=W[i]*x[i]\n",
+ " Wx2[i]=W[i]*x[i]**2\n",
+ " Wx3[i]=W[i]*x[i]**3\n",
+ " Wy[i]=W[i]*y[i]\n",
+ " Wxy[i]=W[i]*x[i]*y[i]\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_W=0\n",
+ "S_Wx=0\n",
+ "S_Wx2=0\n",
+ "S_Wy=0\n",
+ "S_Wxy=0\n",
+ "for i in range(0,4):\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_W=S_W+W[i]\n",
+ " S_Wx=S_Wx+Wx[i]\n",
+ " S_Wx2=S_Wx2+Wx2[i]\n",
+ " S_Wy=S_Wy+Wy[i]\n",
+ " S_Wxy=S_Wxy+Wxy[i]\n",
+ "A=matrix([[S_W,S_Wx],[S_Wx,S_Wx2]])\n",
+ "C=matrix([[S_Wy],[S_Wxy]])\n",
+ "print \"x\\t y\\t W\\t Wx\\t Wx^2\\t Wy\\t Wxy\\t\\n\\n\"\n",
+ "for i in range(0,4):\n",
+ " print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\t\\n\" %(x[i],y[i],W[i],Wx[i],Wx2[i],Wy[i],Wxy[i])\n",
+ "print \"-------------------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\t\\n\" %(S_x,S_y,S_W,S_Wx,S_Wx2,S_Wy,S_Wxy)\n",
+ "X=A.I*C;\n",
+ "print \"\\n\\nthe equation is y=%f+%fx\" %(X[0][0],X[1][0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t W\t Wx\t Wx^2\t Wy\t Wxy\t\n",
+ "\n",
+ "\n",
+ "0\t -1\t 1\t 0\t 0\t -1\t 0\t\n",
+ "\n",
+ "2\t 5\t 1\t 2\t 4\t 5\t 10\t\n",
+ "\n",
+ "5\t 12\t 10\t 50\t 250\t 120\t 600\t\n",
+ "\n",
+ "7\t 20\t 1\t 7\t 49\t 20\t 140\t\n",
+ "\n",
+ "-------------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "14\t 36\t 13\t 59\t 303\t 144\t 750\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "the equation is y=-1.349345+2.737991x\n"
+ ]
+ }
+ ],
+ "prompt_number": 77
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex4.10:pg-139"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#linear weighted least approx\n",
+ "#example 4.10\n",
+ "#page 139\n",
+ "x=[0, 2, 5, 7]\n",
+ "y=[-1, 5, 12, 20]\n",
+ "w=100 #given weight 100\n",
+ "W=[1, 1, 100, 1]\n",
+ "Wx=[0,0,0,0]\n",
+ "Wx2=[0,0,0,0]\n",
+ "Wx3=[0,0,0,0]\n",
+ "Wy=[0,0,0,0]\n",
+ "Wxy=[0,0,0,0]\n",
+ "for i in range(0,4):\n",
+ " Wx[i]=W[i]*x[i]\n",
+ " Wx2[i]=W[i]*x[i]**2\n",
+ " Wx3[i]=W[i]*x[i]**3\n",
+ " Wy[i]=W[i]*y[i]\n",
+ " Wxy[i]=W[i]*x[i]*y[i]\n",
+ "S_x=0\n",
+ "S_y=0\n",
+ "S_W=0\n",
+ "S_Wx=0\n",
+ "S_Wx2=0\n",
+ "S_Wy=0\n",
+ "S_Wxy=0\n",
+ "for i in range(0,4):\n",
+ " S_x=S_x+x[i]\n",
+ " S_y=S_y+y[i]\n",
+ " S_W=S_W+W[i]\n",
+ " S_Wx=S_Wx+Wx[i]\n",
+ " S_Wx2=S_Wx2+Wx2[i]\n",
+ " S_Wy=S_Wy+Wy[i]\n",
+ " S_Wxy=S_Wxy+Wxy[i]\n",
+ "A=matrix([[S_W,S_Wx],[S_Wx,S_Wx2]])\n",
+ "C=matrix([[S_Wy],[S_Wxy]])\n",
+ "print \"x\\t y\\t W\\t Wx\\t Wx^2\\t Wy\\t Wxy\\t\\n\\n\"\n",
+ "for i in range(0,4):\n",
+ " print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\t\\n\" %(x[i],y[i],W[i],Wx[i],Wx2[i],Wy[i],Wxy[i])\n",
+ "print \"-------------------------------------------------------------------------------------------------------------------------------------\\n\\n\"\n",
+ "print \"%d\\t %d\\t %d\\t %d\\t %d\\t %d\\t %d\\t\\n\" %(S_x,S_y,S_W,S_Wx,S_Wx2,S_Wy,S_Wxy)\n",
+ "X=A.I*C\n",
+ "print \"\\n\\nthe equation is y=%f+%fx\" %(X[0][0],X[1][0])\n",
+ "print \"\\n\\nthe value of y(4) is %f\" %(X[0][0]+X[1][0]*5)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x\t y\t W\t Wx\t Wx^2\t Wy\t Wxy\t\n",
+ "\n",
+ "\n",
+ "0\t -1\t 1\t 0\t 0\t -1\t 0\t\n",
+ "\n",
+ "2\t 5\t 1\t 2\t 4\t 5\t 10\t\n",
+ "\n",
+ "5\t 12\t 100\t 500\t 2500\t 1200\t 6000\t\n",
+ "\n",
+ "7\t 20\t 1\t 7\t 49\t 20\t 140\t\n",
+ "\n",
+ "-------------------------------------------------------------------------------------------------------------------------------------\n",
+ "\n",
+ "\n",
+ "14\t 36\t 103\t 509\t 2553\t 1224\t 6150\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "the equation is y=-1.412584+2.690562x\n",
+ "\n",
+ "\n",
+ "the value of y(4) is 12.040227\n"
+ ]
+ }
+ ],
+ "prompt_number": 82
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter6_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter6_10.ipynb new file mode 100644 index 00000000..757bcf52 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter6_10.ipynb @@ -0,0 +1,1072 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:4f380799ddd748d7c005b7eb0afef7c77160e5af919cbc18233369be08258e51"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter06:Numerical Differentiation and Integration"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.1:pg-201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.1\n",
+ "#numerical diffrentiation by newton's difference formula \n",
+ "#page 210\n",
+ "x=[1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2]\n",
+ "y=[2.7183, 3.3201, 4.0552, 4.9530, 6.0496, 7.3891, 9.0250]\n",
+ "c=0\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "d5=[0,0]\n",
+ "d6=[0]\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d5[c]=d4[i+1]-d4[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d6[c]=d5[i+1]-d5[i]\n",
+ " c=c+1;\n",
+ "x0=1.2 #first and second derivative at 1.2\n",
+ "h=0.2\n",
+ "f1=((d1[1]-d2[1]/2+d3[1]/3-d4[1]/4+d5[1]/5)/h)\n",
+ "print \"the first derivative of fuction at 1.2 is:%f\\n\" %(f1)\n",
+ "f2=(d2[1]-d3[1]+(11*d4[1])/12-(5*d5[1])/6)/h**2\n",
+ "print \"the second derivative of fuction at 1.2 is:%f\\n\" %(f2)\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the first derivative of fuction at 1.2 is:3.320317\n",
+ "\n",
+ "the second derivative of fuction at 1.2 is:3.319167\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.2:pg-211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.2\n",
+ "#numerical diffrentiation by newton's difference formula \n",
+ "#page 211\n",
+ "x=[1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2]\n",
+ "y=[2.7183, 3.3201, 4.0552, 4.9530, 6.0496, 7.3891, 9.0250]\n",
+ "c=0\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "d5=[0,0]\n",
+ "d6=[0]\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d5[c]=d4[i+1]-d4[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d6[c]=d5[i+1]-d5[i]\n",
+ " c=c+1;\n",
+ "x0=2.2 #first and second derivative at 2.2\n",
+ "h=0.2\n",
+ "f1=((d1[5]+d2[4]/2+d3[3]/3+d4[2]/4+d5[1]/5)/h)\n",
+ "print \"the first derivative of fuction at 1.2 is:%f\\n\" %(f1)\n",
+ "f2=(d2[4]+d3[3]+(11*d4[2])/12+(5*d5[1])/6)/h**2\n",
+ "print \"the second derivative of fuction at 1.2 is:%f\\n\" %(f2)\n",
+ "x1=2.0 # first derivative also at 2.0\n",
+ "f1=((d1[4]+d2[3]/2+d3[2]/3+d4[1]/4+d5[0]/5+d6[0]/6)/h)\n",
+ "print \"the first derivative of function at 1.2 is:%f\\n\" %(f1)\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the first derivative of fuction at 1.2 is:9.022817\n",
+ "\n",
+ "the second derivative of fuction at 1.2 is:8.992083\n",
+ "\n",
+ "the first derivative of function at 1.2 is:7.389633\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.3:pg-211"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.3\n",
+ "#numerical diffrentiation by newton's difference formula \n",
+ "#page 211\n",
+ "x=[1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2]\n",
+ "y=[2.7183, 3.3201, 4.0552, 4.9530, 6.0496, 7.3891, 9.0250]\n",
+ "c=0\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "d5=[0,0]\n",
+ "d6=[0]\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d5[c]=d4[i+1]-d4[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d6[c]=d5[i+1]-d5[i]\n",
+ " c=c+1;\n",
+ "x0=1.6 #first and second derivative at 1.6\n",
+ "h=0.2\n",
+ "f1=(((d1[2]+d1[3])/2-(d3[1]+d3[2])/4+(d5[0]+d5[1])/60))/h\n",
+ "print \"the first derivative of function at 1.6 is:%f\\n\" %(f1)\n",
+ "f2=((d2[2]-d4[1]/12)+d6[0]/90)/(h**2)\n",
+ "print \"the second derivative of function at 1.6 is:%f\\n\" %(f2)\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the first derivative of function at 1.6 is:4.885975\n",
+ "\n",
+ "the second derivative of function at 1.6 is:4.953361\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.4:pg-213"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.4\n",
+ "#estimation of errors \n",
+ "#page 213\n",
+ "x=[1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2]\n",
+ "y=[2.7183, 3.3201, 4.0552, 4.9530, 6.0496, 7.3891, 9.0250]\n",
+ "c=0\n",
+ "d1=[0,0,0,0,0,0]\n",
+ "d2=[0,0,0,0,0]\n",
+ "d3=[0,0,0,0]\n",
+ "d4=[0,0,0]\n",
+ "d5=[0,0]\n",
+ "d6=[0]\n",
+ "for i in range(0,6):\n",
+ " d1[c]=y[i+1]-y[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,5):\n",
+ " d2[c]=d1[i+1]-d1[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,4):\n",
+ " d3[c]=d2[i+1]-d2[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,3):\n",
+ " d4[c]=d3[i+1]-d3[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " d5[c]=d4[i+1]-d4[i]\n",
+ " c=c+1;\n",
+ "c=0\n",
+ "for i in range(0,1):\n",
+ " d6[c]=d5[i+1]-d5[i]\n",
+ " c=c+1\n",
+ "x0=1.6 #first and second derivative at 1.6\n",
+ "h=0.2\n",
+ "f1=((d1[1]-d2[1]/2+d3[1]/3-d4[1]/4+d5[1]/5)/h)\n",
+ "print \"the first derivative of fuction at 1.2 is:%f\\n\" %(f1)\n",
+ "f2=(d2[1]-d3[1]+(11*d4[1])/12-(5*d5[1])/6)/h**2\n",
+ "print \"the second derivative of fuction at 1.2 is:%f\\n\" %(f2)\n",
+ "T_error1=((d3[1]+d3[2])/2)/(6*h) #truncation error\n",
+ "e=0.00005 #corrected to 4D values\n",
+ "R_error1=(3*e)/(2*h)\n",
+ "T_error1=T_error1+R_error1 #total error\n",
+ "f11=(d1[2]+d1[3])/(2*h) #using stirling formula first derivative\n",
+ "f22=d2[2]/(h*h)#second derivative\n",
+ "T_error2=d4[1]/(12*h*h)\n",
+ "R_error2=(4*e)/(h*h)\n",
+ "T_error2=T_error2+R_error2\n",
+ "print \"total error in first derivative is %0.4g:\\n\" %(T_error1)\n",
+ "print \"total error in second derivative is %0.4g:\" %(T_error2)\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the first derivative of fuction at 1.2 is:3.320317\n",
+ "\n",
+ "the second derivative of fuction at 1.2 is:3.319167\n",
+ "\n",
+ "total error in first derivative is 0.03379:\n",
+ "\n",
+ "total error in second derivative is 0.02167:\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.5:pg-214"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic spline method\n",
+ "#example 6.5\n",
+ "#page 214\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "x=[0, math.pi/2, math.pi]\n",
+ "y=[0, 1, 0]\n",
+ "M0=0\n",
+ "M2=0\n",
+ "h=math.pi/2\n",
+ "M1=(6*(y[0]-2*y[1]+y[2])/(h**2)-M0-M2)/4\n",
+ "def s1(x):\n",
+ " return (2/math.pi)*(-2*3*x*x/(math.pi**2)+3/2)\n",
+ "S1=s1(math.pi/4)\n",
+ "print \"S1(pi/4)=%f\" %(S1)\n",
+ "def s2(x):\n",
+ " return (-24*x)/(math.pi**3)\n",
+ "S2=s2(math.pi/4)\n",
+ "print \"S2(pi/4)=%f\" %(S2)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "S1(pi/4)=0.716197\n",
+ "S2(pi/4)=-0.607927\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.6:pg-216"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#derivative by cubic spline method\n",
+ "#example 6.6\n",
+ "#page 216\n",
+ "x=[-2, -1, 2, 3]\n",
+ "y=[-12, -8, 3, 5] \n",
+ "def f(x):\n",
+ " return x**3/15-3*x**2/20+241*x/60-3.9\n",
+ "def s2(x):\n",
+ " return (((2-x)**3)/6*(14/55)+((x+1)**3)/6*(-74/55))/3+(-8-21/55)*(2-x)/3+(3-(9/6)*(-74/55))*(x+1)/3\n",
+ "h=0.0001\n",
+ "x0=1.0\n",
+ "y1=(s2(x0+h)-s2(x0))/h\n",
+ "print \"the value y1(%0.2f) is : %f\" %(x0,y1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value y1(1.00) is : 3.527232\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.7:pg-218"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#maximun and minimun of functions\n",
+ "#example 6.7\n",
+ "#page 218\n",
+ "x=[1.2, 1.3, 1.4, 1.5, 1.6]\n",
+ "y=[0.9320, 0.9636, 0.9855, 0.9975, 0.9996]\n",
+ "d1=[0,0,0,0]\n",
+ "d2=[0,0,0]\n",
+ "for i in range(0,4):\n",
+ " d1[i]=y[i+1]-y[i]\n",
+ "for i in range(0,3):\n",
+ " d2[i]=d1[i+1]-d1[i]\n",
+ "p=(-d1[0]*2/d2[0]+1)/2;\n",
+ "print \"p=%f\" %(p)\n",
+ "h=0.1\n",
+ "x0=1.2\n",
+ "X=x0+p*h\n",
+ "print \" the value of X correct to 2 decimal places is : %0.2f\" %(X)\n",
+ "Y=y[4]-0.2*d1[3]+(-0.2)*(-0.2+1)*d2[2]/2\n",
+ "print \"the value Y=%f\" %(Y)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "p=3.757732\n",
+ " the value of X correct to 2 decimal places is : 1.58\n",
+ "the value Y=0.999972\n"
+ ]
+ }
+ ],
+ "prompt_number": 26
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.8:pg-226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.8\n",
+ "#trapezoidal method for integration\n",
+ "#page 226\n",
+ "from __future__ import division\n",
+ "x=[7.47, 7.48, 7.49, 7.0, 7.51, 7.52]\n",
+ "f_x=[1.93, 1.95, 1.98, 2.01, 2.03, 2.06]\n",
+ "h=x[1]-x[0]\n",
+ "l=6\n",
+ "area=0\n",
+ "for i in range(0,l):\n",
+ " if i==0:\n",
+ " area=area+f_x[i]\n",
+ " elif i==l-1:\n",
+ " area=area+f_x[i]\n",
+ " else:\n",
+ " area=area+2*f_x[i]\n",
+ "area=area*(h/2)\n",
+ "print \"area bounded by the curve is %f\" %(area)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "area bounded by the curve is 0.099650\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.9:pg-226"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.9\n",
+ "#simpson 1/3rd method for integration\n",
+ "#page 226\n",
+ "from __future__ import division\n",
+ "import math\n",
+ "x=[0,0.00, 0.25, 0.50, 0.75, 1.00]\n",
+ "y=[0,1.000, 0.9896, 0.9589, 0.9089, 0.8415]\n",
+ "h=x[2]-x[1]\n",
+ "area=0\n",
+ "for i in range(0,6):\n",
+ " y[i]=y[i]**2\n",
+ "for i in range(1,6):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==5:\n",
+ " area=area+y[i]\n",
+ " elif i%2==0:\n",
+ " area=area+4*y[i]\n",
+ " elif i%2!=0: \n",
+ " area=area+2*y[i]\n",
+ "area=(area/3)*(h*math.pi)\n",
+ "print \"area bounded by the curve is %f\" %(area)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "area bounded by the curve is 2.819247\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.10:pg-228"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.10\n",
+ "#integration by trapezoidal and simpson's method\n",
+ "#page 228\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return 1/(1+x)\n",
+ "h=0.5\n",
+ "x=[0,0.0,0.5,1.0]\n",
+ "y=[0,0,0,0]\n",
+ "l=4\n",
+ "for i in range(0,l):\n",
+ " y[i]=f(x[i])\n",
+ "area=0 #trapezoidal method\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " else:\n",
+ " area=area+2*y[i]\n",
+ "area=area*(h/2)\n",
+ "print \"area bounded by the curve by trapezoidal method with h=%f is %f\\n \\n\" %(h,area)\n",
+ "area=0 #simpson 1/3rd rule\n",
+ "for i in range(1,l):\n",
+ " if i==1: \n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " elif i%2==0:\n",
+ " area=area+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " area=area+2*y[i]\n",
+ "area=(area*h)/3\n",
+ "print \"area bounded by the curve by simpson 1/3rd method with h=%f is %f\\n \\n\" %(h,area)\n",
+ "h=0.25\n",
+ "x=[0,0.0,0.25,0.5,0.75,1.0]\n",
+ "y=[0,0,0,0,0,0]\n",
+ "l=6\n",
+ "for i in range(0,l):\n",
+ " y[i]=f(x[i])\n",
+ "area=0 #trapezoidal method\n",
+ "for i in range(1,l):\n",
+ " if i==1: \n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " else:\n",
+ " area=area+2*y[i]\n",
+ "area=area*(h/2)\n",
+ "print \"area bounded by the curve by trapezoidal method with h=%f is %f\\n \\n\" %(h,area)\n",
+ "area=0 #simpson 1/3rd rule\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " elif i%2==0:\n",
+ " area=area+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " area=area+2*y[i]\n",
+ "area=(area*h)/3\n",
+ "print \"area bounded by the curve by simpson 1/3rd method with h=%f is %f\\n \\n\" %(h,area)\n",
+ "h=0.125\n",
+ "x=[0,0.0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1.0]\n",
+ "y=[0,0,0,0,0,0,0,0,0,0]\n",
+ "l=10\n",
+ "for i in range(0,l):\n",
+ " y[i]=f(x[i])\n",
+ "area=0 #trapezoidal method\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " elif i%2==0:\n",
+ " area=area+2*y[i]\n",
+ " elif i%2!=0:\n",
+ " area=area+2*y[i]\n",
+ "area=area*(h/2)\n",
+ "print \"area bounded by the curve by trapezoidal method with h=%f is %f\\n \\n\" %(h,area)\n",
+ "area=0 #simpson 1/3rd rule\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " elif i%2==0:\n",
+ " area=area+4*y[i]\n",
+ " elif i%2!=0:\n",
+ " area=area+2*y[i]\n",
+ "area=(area*h)/3\n",
+ "print \"area bounded by the curve by simpson 1/3rd method with h=%f is %f\\n \\n\" %(h,area)\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ " \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "area bounded by the curve by trapezoidal method with h=0.500000 is 0.708333\n",
+ " \n",
+ "\n",
+ "area bounded by the curve by simpson 1/3rd method with h=0.500000 is 0.694444\n",
+ " \n",
+ "\n",
+ "area bounded by the curve by trapezoidal method with h=0.250000 is 0.697024\n",
+ " \n",
+ "\n",
+ "area bounded by the curve by simpson 1/3rd method with h=0.250000 is 0.693254\n",
+ " \n",
+ "\n",
+ "area bounded by the curve by trapezoidal method with h=0.125000 is 0.694122\n",
+ " \n",
+ "\n",
+ "area bounded by the curve by simpson 1/3rd method with h=0.125000 is 0.693155\n",
+ " \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 36
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.11:pg-229"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.11\n",
+ "#rommberg's method\n",
+ "#page 229\n",
+ "from __future__ import division\n",
+ "def f(x):\n",
+ " return 1/(1+x)\n",
+ "k=0\n",
+ "h=0.5\n",
+ "x=[0,0.0,0.5,1.0]\n",
+ "y=[0,0,0,0]\n",
+ "I=[0,0,0]\n",
+ "I1=[0,0]\n",
+ "T2=[0]\n",
+ "l=4\n",
+ "for i in range(0,l):\n",
+ " y[i]=f(x[i])\n",
+ "area=0 #trapezoidal method\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " else:\n",
+ " area=area+2*y[i]\n",
+ "area=area*(h/2)\n",
+ "I[k]=area\n",
+ "k=k+1\n",
+ "h=0.25\n",
+ "x=[0,0.0,0.25,0.5,0.75,1.0]\n",
+ "y=[0,0,0,0,0,0]\n",
+ "l=6\n",
+ "for i in range(0,l):\n",
+ " y[i]=f(x[i])\n",
+ "area=0 #trapezoidal method\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " else:\n",
+ " area=area+2*y[i]\n",
+ "area=area*(h/2)\n",
+ "I[k]=area\n",
+ "k=k+1\n",
+ "h=0.125\n",
+ "x=[0,0.0,0.125,0.25,0.375,0.5,0.625,0.75,0.875,1.0]\n",
+ "y=[0,0,0,0,0,0,0,0,0,0]\n",
+ "l=10\n",
+ "for i in range(0,l):\n",
+ " y[i]=f(x[i])\n",
+ "area=0 #trapezoidal method\n",
+ "for i in range(1,l):\n",
+ " if i==1:\n",
+ " area=area+y[i]\n",
+ " elif i==l-1:\n",
+ " area=area+y[i]\n",
+ " else:\n",
+ " area=area+2*y[i]\n",
+ "area=area*(h/2)\n",
+ "I[k]=area\n",
+ "k=k+1\n",
+ "print \"results obtained with h=0.5 0.25 0.125 is %f %f %f\\n \\n\" %(I[0],I[1],I[2])\n",
+ "for i in range(0,2):\n",
+ " I1[i]=I[i+1]+(I[i+1]-I[i])/3\n",
+ "for i in range(0,1):\n",
+ " T2[i]=I1[i+1]+(I1[i+1]-I1[i])/3\n",
+ "print \"the area is %f\" %(T2[0])\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "results obtained with h=0.5 0.25 0.125 is 0.708333 0.697024 0.694122\n",
+ " \n",
+ "\n",
+ "the area is 0.693121\n"
+ ]
+ }
+ ],
+ "prompt_number": 43
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.13:pg-230"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#area using cubic spline method\n",
+ "#example 6.13\n",
+ "#page 230\n",
+ "x=[0, 0.5, 1.0]\n",
+ "y=[0, 1.0, 0.0]\n",
+ "h=0.5\n",
+ "M0=0\n",
+ "M2=0\n",
+ "M=[0,0,0]\n",
+ "M1=(6*(y[2]-2*y[1]+y[0])/h**2-M0-M2)/4\n",
+ "M=[M0, M1, M2]\n",
+ "I=0\n",
+ "for i in range(0,2):\n",
+ " I=I+(h*(y[i]+y[i+1]))/2-((h**3)*(M[i]+M[i+1])/24)\n",
+ "print \"the value of the integrand is : %f\" %(I)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of the integrand is : 0.625000\n"
+ ]
+ }
+ ],
+ "prompt_number": 45
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.15:pg-233"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#euler's maclaurin formula\n",
+ "#example 6.15\n",
+ "#page 233\n",
+ "import math\n",
+ "y=[0, 1, 0]\n",
+ "h=math.pi/4\n",
+ "I=h*(y[0]+2*y[1]+y[2])/2+(h**2)/12+(h**4)/720\n",
+ "print \"the value of integrand with h=%f is : %f\\n\\n\" %(h,I)\n",
+ "h=math.pi/8\n",
+ "y=[0, math.sin(math.pi/8), math.sin(math.pi*2/8), math.sin(math.pi*3/8), math.sin(math.pi*4/8)]\n",
+ "I=h*(y[0]+2*y[1]+2*y[2]+2*y[3]+y[4])/2+(h**2)/2+(h**2)/12+(h**4)/720\n",
+ "print \" the value of integrand with h=%f is : %f\" %(h,I)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of integrand with h=0.785398 is : 0.837331\n",
+ "\n",
+ "\n",
+ " the value of integrand with h=0.392699 is : 1.077106\n"
+ ]
+ }
+ ],
+ "prompt_number": 47
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.17:pg-236"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# example 6.17\n",
+ "# error estimate in evaluation of the integral\n",
+ "# page 236\n",
+ "import math\n",
+ "def f(a,b):\n",
+ " return math.cos(a)+4*math.cos((a+b)/2)+math.cos(b)\n",
+ "a=0\n",
+ "b=math.pi/2\n",
+ "c=math.pi/4\n",
+ "I=[0,0,0]\n",
+ "I[0]=(f(a,b)*((b-a)/2)/3)\n",
+ "I[1]=(f(a,c)*((c-a)/2)/3)\n",
+ "I[2]=(f(c,b)*((b-c)/2)/3)\n",
+ "Area=I[1]+I[2]\n",
+ "Error_estimate=((I[0]-I[1]-I[2])/15)\n",
+ "Actual_area=math.sin(math.pi/2)-math.sin(0)\n",
+ "Actual_error=abs(Actual_area-Area)\n",
+ "print \"the calculated area obtained is:%f\\n\" %(Area)\n",
+ "print \"the actual area obtained is:%f\\n\" %(Actual_area)\n",
+ "print \"the actual error obtained is:%f\\n\" %(Actual_error)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the calculated area obtained is:1.000135\n",
+ "\n",
+ "the actual area obtained is:1.000000\n",
+ "\n",
+ "the actual error obtained is:0.000135\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 49
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.18:pg-237"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "# example 6.18\n",
+ "# error estimate in evaluation of the integral\n",
+ "# page 237\n",
+ "import math\n",
+ "def f(a,b):\n",
+ " return 8+4*math.sin(a)+4*(8+4*math.sin((a+b)/2))+8+4*math.sin(b)\n",
+ "a=0\n",
+ "b=math.pi/2\n",
+ "c=math.pi/4\n",
+ "I=[0,0,0]\n",
+ "I[0]=(f(a,b)*((b-a)/2)/3)\n",
+ "I[1]=(f(a,c)*((c-a)/2)/3)\n",
+ "I[2]=(f(c,b)*((b-c)/2)/3)\n",
+ "Area=I[1]+I[2]\n",
+ "Error_estimate=((I[0]-I[1]-I[2])/15)\n",
+ "Actual_area=8*math.pi/2+4*math.sin(math.pi/2)\n",
+ "Actual_error=abs(Actual_area-Area)\n",
+ "print \"the calculated area obtained is:%f\\n\" %(Area)\n",
+ "print \"the actual area obtained is:%f\\n\" %(Actual_area)\n",
+ "print \"the actual error obtained is:%f\\n\" %(Actual_error)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the calculated area obtained is:16.566909\n",
+ "\n",
+ "the actual area obtained is:16.566371\n",
+ "\n",
+ "the actual error obtained is:0.000538\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 50
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.19:pg-242"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#gauss' formula\n",
+ "#example 6.19\n",
+ "#page 242\n",
+ "u=[-0.86113, -0.33998, 0.33998, 0.86113]\n",
+ "W=[0.34785, 0.65214, 0.65214, 0.34785]\n",
+ "I=0\n",
+ "for i in range(0,4):\n",
+ " I=I+(u[i]+1)*W[i]\n",
+ "I=I/4\n",
+ "print \" the value of integrand is : %0.5f\" %(I)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " the value of integrand is : 0.49999\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex6.20:pg-247"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 6.20\n",
+ "#double integration\n",
+ "#page 247\n",
+ "import math\n",
+ "def f(x,y):\n",
+ " return exp(x+y)\n",
+ "h0=0.5\n",
+ "k0=0.5\n",
+ "x=[[0,0,0],[0,0,0],[0,0,0]]\n",
+ "h=[0, 0.5, 1]\n",
+ "k=[0, 0.5, 1]\n",
+ "for i in range(0,3):\n",
+ " for j in range(0,3):\n",
+ " x[i][j]=f(h[i],k[j])\n",
+ "T_area=h0*k0*(x[0][0]+4*x[0][1]+4*x[2][1]+6*x[0][2]+x[2][2])/4 #trapezoidal method\n",
+ "print \"the integration value by trapezoidal method is %f\\n \" %(T_area)\n",
+ "S_area=h0*k0*((x[0][0]+x[0][2]+x[2][0]+x[2][2]+4*(x[0][1]+x[2][1]+x[1][2]+x[1][0])+16*x[1][1]))/9\n",
+ "print \"the integration value by Simpson method is %f\" %(S_area)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the integration value by trapezoidal method is 3.076274\n",
+ " \n",
+ "the integration value by Simpson method is 2.954484\n"
+ ]
+ }
+ ],
+ "prompt_number": 55
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter7_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter7_10.ipynb new file mode 100644 index 00000000..aba1eb4b --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter7_10.ipynb @@ -0,0 +1,714 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:0058f29553d8742ab5006900201b226161b38e64bcaf47caebba35d96ab2998b"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter07:Numerical Linear Algebra"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.1:pg-256"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 7.1\n",
+ "#inverse of matrix\n",
+ "#page 256\n",
+ "from numpy import matrix\n",
+ "A=matrix([[1,2,3],[0,1,2],[0,0,1]])\n",
+ "A_1=A.I #inverse of matrix\n",
+ "print A_1"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "[[ 1. -2. 1.]\n",
+ " [ 0. 1. -2.]\n",
+ " [ 0. 0. 1.]]\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex-7.2:pg-259"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 7.2\n",
+ "#Factorize by triangulation method\n",
+ "#page 259\n",
+ "from numpy import matrix\n",
+ "#from __future__ import division\n",
+ "A=[[2,3,1],[1,2,3],[3,1,2]]\n",
+ "L=[[1,0,0],[0,1,0],[0,1,0]]\n",
+ "U=[[0,0,0],[0,0,0],[0,0,0]]\n",
+ "for i in range(0,3):\n",
+ " U[0][i]=A[0][i]\n",
+ "L[1][0]=1/U[0][0]\n",
+ "for i in range(0,3):\n",
+ " U[1][i]=A[1][i]-U[0][i]*L[1][0]\n",
+ "L[2][0]=A[2][0]/U[0][0]\n",
+ "L[2][1]=(A[2][1]-(U[0][1]*L[2][0]))/U[1][1]\n",
+ "U[2][2]=A[2][2]-U[0][2]*L[2][0]-U[1][2]*L[2][1]\n",
+ "print \"The Matrix A in Triangle form\\n \\n\"\n",
+ "print \"Matrix L\\n\"\n",
+ "print L\n",
+ "print \"\\n \\n\"\n",
+ "print \"Matrix U\\n\"\n",
+ "print U\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Matrix A in Triangle form\n",
+ " \n",
+ "\n",
+ "Matrix L\n",
+ "\n",
+ "[[1, 0, 0], [0.5, 1, 0], [1.5, -7.0, 0]]\n",
+ "\n",
+ " \n",
+ "\n",
+ "Matrix U\n",
+ "\n",
+ "[[2, 3, 1], [0.0, 0.5, 2.5], [0, 0, 18.0]]\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.3:pg-262"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 7.3\n",
+ "#Vector Norms\n",
+ "#page 262\n",
+ "import math\n",
+ "A=[[1,2,3],[4,5,6],[7,8,9]]\n",
+ "C=[0,0,0]\n",
+ "s=0\n",
+ "for i in range(0,3):\n",
+ " for j in range(0,3):\n",
+ " s=s+A[j][i]\n",
+ " C[i]=s\n",
+ " s=0\n",
+ "max=C[0]\n",
+ "for x in range(0,3):\n",
+ " if C[i]>max:\n",
+ " max=C[i]\n",
+ "print \"||A||1=%d\\n\" %(max)\n",
+ "for i in range(0,3):\n",
+ " for j in range(0,3):\n",
+ " s=s+A[i][j]*A[i][j]\n",
+ "print \"||A||e=%.3f\\n\" %(math.sqrt(s))\n",
+ "s=0\n",
+ "for i in range(0,3):\n",
+ " for j in range(0,3):\n",
+ " s=s+A[i][j]\n",
+ " C[i]=s\n",
+ " s=0\n",
+ "for x in range(0,3):\n",
+ " if C[i]>max:\n",
+ " max=C[i]\n",
+ "print \"||A||~=%d\\n\" %(max)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "||A||1=18\n",
+ "\n",
+ "||A||e=16.882\n",
+ "\n",
+ "||A||~=24\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.4:pg-266"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 7.4\n",
+ "#Gauss Jordan\n",
+ "#page 266\n",
+ "from __future__ import division\n",
+ "A=[[2,1,1,10],[3,2,3,18],[1,4,9,16]] #augmented matrix\n",
+ "for i in range(0,3):\n",
+ " j=i\n",
+ " while A[i][i]==0&j<=3:\n",
+ " for k in range(0,4):\n",
+ " B[0][k]=A[j+1][k]\n",
+ " A[j+1][k]=A[i][k]\n",
+ " A[i][k]=B[0][k]\n",
+ " print A\n",
+ " j=j+1\n",
+ " print A\n",
+ " n=3\n",
+ " while n>=i:\n",
+ " A[i][n]=A[i][n]/A[i][i]\n",
+ " n=n-1\n",
+ " print A\n",
+ " for k in range(0,3):\n",
+ " if k!=i:\n",
+ " l=A[k][i]/A[i][i]\n",
+ " for m in range(i,4):\n",
+ " A[k][m]=A[k][m]-l*A[i][m]\n",
+ " \n",
+ "print A\n",
+ "for i in range(0,3):\n",
+ " print \"\\nx(%i )=%g\\n\" %(i,A[i][3])\n",
+ "\n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "[[2, 1, 1, 10], [3, 2, 3, 18], [1, 4, 9, 16]]\n",
+ "[[1.0, 0.5, 0.5, 5.0], [3, 2, 3, 18], [1, 4, 9, 16]]\n",
+ "[[1.0, 0.5, 0.5, 5.0], [0.0, 0.5, 1.5, 3.0], [0.0, 3.5, 8.5, 11.0]]\n",
+ "[[1.0, 0.5, 0.5, 5.0], [0.0, 1.0, 3.0, 6.0], [0.0, 3.5, 8.5, 11.0]]\n",
+ "[[1.0, 0.0, -1.0, 2.0], [0.0, 1.0, 3.0, 6.0], [0.0, 0.0, -2.0, -10.0]]\n",
+ "[[1.0, 0.0, -1.0, 2.0], [0.0, 1.0, 3.0, 6.0], [0.0, 0.0, 1.0, 5.0]]\n",
+ "[[1.0, 0.0, 0.0, 7.0], [0.0, 1.0, 0.0, -9.0], [0.0, 0.0, 1.0, 5.0]]\n",
+ "\n",
+ "x(0 )=7\n",
+ "\n",
+ "\n",
+ "x(1 )=-9\n",
+ "\n",
+ "\n",
+ "x(2 )=5\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 28
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.8:pg-273"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#LU decomposition method\n",
+ "#example 7.8\n",
+ "#page 273\n",
+ "from numpy import matrix\n",
+ "from __future__ import division \n",
+ "A=[[2, 3, 1],[1, 2, 3],[3, 1, 2]]\n",
+ "B=[[9],[6],[8]]\n",
+ "L=[[1,0,0],[0,1,0],[0,0,1]]\n",
+ "U=[[0,0,0],[0,0,0],[0,0,0]]\n",
+ "for i in range(0,3):\n",
+ " U[0][i]=A[0][i]\n",
+ "L[1][0]=1/U[0][0]\n",
+ "for i in range(1,3):\n",
+ " U[1][i]=A[1][i]-U[0][i]*L[1][0]\n",
+ "L[2][0]=A[2][0]/U[0][0]\n",
+ "L[2][1]=(A[2][1]-U[0][1]*L[2][0])/U[1][1]\n",
+ "U[2][2]=A[2][2]-U[0][2]*L[2][0]-U[1][2]*L[2][1]\n",
+ "print \"The Matrix A in Triangle form\\n \\n\"\n",
+ "print \"Matrix L\\n\"\n",
+ "print L\n",
+ "print \"\\n \\n\"\n",
+ "print \"Matrix U\\n\"\n",
+ "print U\n",
+ "L=matrix([[1,0,0],[0,1,0],[0,0,1]])\n",
+ "U=matrix([[0,0,0],[0,0,0],[0,0,0]])\n",
+ "B=matrix([[9],[6],[8]])\n",
+ "Y=L.I*B\n",
+ "X=matrix([[1.944444],[1.611111],[0.277778]])\n",
+ "print \"the values of x=%f,y=%f,z=%f\" %(X[0][0],X[1][0],X[2][0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "The Matrix A in Triangle form\n",
+ " \n",
+ "\n",
+ "Matrix L\n",
+ "\n",
+ "[[1, 0, 0], [0.5, 1, 0], [1.5, -7.0, 1]]\n",
+ "\n",
+ " \n",
+ "\n",
+ "Matrix U\n",
+ "\n",
+ "[[2, 3, 1], [0, 0.5, 2.5], [0, 0, 18.0]]\n",
+ "the values of x=1.944444,y=1.611111,z=0.277778\n"
+ ]
+ }
+ ],
+ "prompt_number": 41
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.9:pg-276"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ill conditioned linear systems\n",
+ "#example 7.9\n",
+ "#page 276\n",
+ "from numpy import matrix\n",
+ "import math\n",
+ "A=matrix([[2, 1],[2,1.01]])\n",
+ "B=matrix([[2],[2.01]])\n",
+ "X=A.I*B\n",
+ "Ae=0\n",
+ "Ae=math.sqrt(Ae)\n",
+ "inv_A=A.I\n",
+ "invA_e=0\n",
+ "invA_e=math.sqrt(invA_e)\n",
+ "C=A_e*invA_e\n",
+ "k=2\n",
+ "if k<1:\n",
+ " print \"the fuction is ill conditioned\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 56
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.10:pg-277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ill condiioned linear systems\n",
+ "#example 7.10\n",
+ "#page 277\n",
+ "import numpy\n",
+ "from __future__ import division \n",
+ "A=[[1/2, 1/3, 1/4],[1/5, 1/6, 1/7],[1/8,1/9, 1/10]] #hilbert's matrix\n",
+ "de_A=numpy.linalg.det(A)\n",
+ "if de_A<1:\n",
+ " print \"A is ill-conditioned\"\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "A is ill-conditioned\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.11:pg-277"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ill conditioned linear system\n",
+ "#example 7.11\n",
+ "#page 277\n",
+ "import numpy\n",
+ "import math\n",
+ "A=[[25, 24, 10],[66, 78, 37],[92, -73, -80]]\n",
+ "de_A=numpy.linalg.det(A)\n",
+ "for i in range(0,2):\n",
+ " s=0\n",
+ " for j in range(0,2):\n",
+ " s=s+A[i][j]**2\n",
+ " s=math.sqrt(s)\n",
+ " k=de_A/s\n",
+ "if k<1:\n",
+ " print\" the fuction is ill conditioned\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " the fuction is ill conditioned\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.12:pg-278"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#ill-conditioned system\n",
+ "#example 7.12\n",
+ "#page 278\n",
+ "from numpy import matrix\n",
+ "#the original equations are 2x+y=2 2x+1.01y=2.01\n",
+ "A1=matrix([[2, 1],[2, 1.01]])\n",
+ "C1=matrix([[2],[2.01]])\n",
+ "x1=1\n",
+ "y1=1 # approximate values\n",
+ "A2=matrix([[2, 1],[2, 1.01]])\n",
+ "C2=matrix([[3],[3.01]])\n",
+ "C=C1-C2\n",
+ "X=A1.I*C\n",
+ "x=X[0][0]+x1\n",
+ "y=X[1][0]+y1\n",
+ "print \"the exact solution is X=%f \\t Y=%f\" %(x,y)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the exact solution is X=0.500000 \t Y=1.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.14:pg-282"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#solution of equations by iteration method\n",
+ "#example 7.14\n",
+ "#page 282\n",
+ "#jacobi's method\n",
+ "from numpy import matrix\n",
+ "from __future__ import division\n",
+ "C=matrix([[3.333],[1.5],[1.4]])\n",
+ "X=matrix([[3.333],[1.5],[1.4]])\n",
+ "B=matrix([[0, -0.1667, -0.1667],[-0.25, 0, 0.25],[-0.2, 0.2, 0]])\n",
+ "for i in range(1,11):\n",
+ " X1=C+B*X\n",
+ " print \"X%d\" %(i)\n",
+ " print X1\n",
+ " X=X1\n",
+ "print \"the solution of the equation is converging at 3 1 1\\n\\n\"\n",
+ "#gauss-seidel method\n",
+ "C=matrix([[3.333],[1.5],[1.4]])\n",
+ "X=matrix([[3.333],[1.5],[1.4]])\n",
+ "B=matrix([[0, -0.1667, -0.1667],[-0.25, 0, 0.25],[-0.2, 0.2, 0]])\n",
+ "X1=C+B*X\n",
+ "x=X1[0][0]\n",
+ "y=X1[1][0]\n",
+ "z=X1[2][0]\n",
+ "for i in range(0,5):\n",
+ " x=3.333-0.1667*y-0.1667*z\n",
+ " y=1.5-0.25*x+0.25*z\n",
+ " z=1.4-0.2*x+0.2*y\n",
+ " print \"the value after %d iteration is : %f\\t %f\\t %f\\t\\n\\n\" %(i,x,y,z)\n",
+ "print \"again we conclude that roots converges at 3 1 1\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X1\n",
+ "[[ 2.84957]\n",
+ " [ 1.01675]\n",
+ " [ 1.0334 ]]\n",
+ "X2\n",
+ "[[ 2.99124 ]\n",
+ " [ 1.0459575]\n",
+ " [ 1.033436 ]]\n",
+ "X3\n",
+ "[[ 2.9863651]\n",
+ " [ 1.010549 ]\n",
+ " [ 1.0109435]]\n",
+ "X4\n",
+ "[[ 2.9960172 ]\n",
+ " [ 1.0061446 ]\n",
+ " [ 1.00483678]]\n",
+ "X5\n",
+ "[[ 2.9977694 ]\n",
+ " [ 1.00220489]\n",
+ " [ 1.00202548]]\n",
+ "X6\n",
+ "[[ 2.9988948 ]\n",
+ " [ 1.00106402]\n",
+ " [ 1.0008871 ]]\n",
+ "X7\n",
+ "[[ 2.99927475]\n",
+ " [ 1.00049808]\n",
+ " [ 1.00043384]]\n",
+ "X8\n",
+ "[[ 2.99944465]\n",
+ " [ 1.00028977]\n",
+ " [ 1.00024467]]\n",
+ "X9\n",
+ "[[ 2.99951091]\n",
+ " [ 1.0002 ]\n",
+ " [ 1.00016902]]\n",
+ "X10\n",
+ "[[ 2.99953848]\n",
+ " [ 1.00016453]\n",
+ " [ 1.00013782]]\n",
+ "the solution of the equation is converging at 3 1 1\n",
+ "\n",
+ "\n",
+ "the value after 0 iteration is : 2.991240\t 1.010540\t 1.003860\t\n",
+ "\n",
+ "\n",
+ "the value after 1 iteration is : 2.997200\t 1.001665\t 1.000893\t\n",
+ "\n",
+ "\n",
+ "the value after 2 iteration is : 2.999174\t 1.000430\t 1.000251\t\n",
+ "\n",
+ "\n",
+ "the value after 3 iteration is : 2.999486\t 1.000191\t 1.000141\t\n",
+ "\n",
+ "\n",
+ "the value after 4 iteration is : 2.999545\t 1.000149\t 1.000121\t\n",
+ "\n",
+ "\n",
+ "again we conclude that roots converges at 3 1 1\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.16:pg-286"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#largest eigenvalue and eigenvectors\n",
+ "#example 7.16\n",
+ "#page 286\n",
+ "from numpy import matrix\n",
+ "A=matrix([[1,6,1],[1,2,0],[0,0,3]])\n",
+ "I=matrix([[1],[0],[0]]) #initial eigen vector\n",
+ "X0=A*I\n",
+ "print \"X0=\"\n",
+ "print X0\n",
+ "X1=A*X0\n",
+ "print \"X1=\"\n",
+ "print X1\n",
+ "X2=A*X1\n",
+ "print \"X2=\"\n",
+ "print X2\n",
+ "X3=X2/3\n",
+ "print \"X3=\"\n",
+ "print X3\n",
+ "X4=A*X3\n",
+ "X5=X4/4\n",
+ "print \"X5=\"\n",
+ "print X5\n",
+ "X6=A*X5;\n",
+ "X7=X6/(4*4)\n",
+ "print \"X7=\"\n",
+ "print X7\n",
+ "print \"as it can be seen that highest eigen value is 4 \\n\\n the eigen vector is %d %d %d\" %(X7[0],X7[1],X7[2])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "X0=\n",
+ "[[1]\n",
+ " [1]\n",
+ " [0]]\n",
+ "X1=\n",
+ "[[7]\n",
+ " [3]\n",
+ " [0]]\n",
+ "X2=\n",
+ "[[25]\n",
+ " [13]\n",
+ " [ 0]]\n",
+ "X3=\n",
+ "[[8]\n",
+ " [4]\n",
+ " [0]]\n",
+ "X5=\n",
+ "[[8]\n",
+ " [4]\n",
+ " [0]]\n",
+ "X7=\n",
+ "[[2]\n",
+ " [1]\n",
+ " [0]]\n",
+ "as it can be seen that highest eigen value is 4 \n",
+ "\n",
+ " the eigen vector is 2 1 0\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex7.17:pg-290"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#housrholder's method\n",
+ "#example 7.17\n",
+ "#page 290\n",
+ "from numpy import matrix\n",
+ "from __future__ import division\n",
+ "import math\n",
+ "A=[[1, 3, 4],[3, 2, -1],[4, -1, 1]]\n",
+ "print A[1][1]\n",
+ "S=math.sqrt(A[0][1]**2+A[0][2]**2)\n",
+ "v2=math.sqrt((1+A[0][1]/S)/2)\n",
+ "v3=A[0][2]/(2*S)\n",
+ "v3=v3/v2\n",
+ "V=matrix([[0],[v2],[v3]])\n",
+ "P1=matrix([[1, 0, 0],[0, 1-2*v2**2, -2*v2*v3],[0, -2*v2*v3, 1-2*v3**2]])\n",
+ "A1=P1*A*P1\n",
+ "print \"the reduced matrix is \\n\\n\"\n",
+ "print A1\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "2\n",
+ "the reduced matrix is \n",
+ "\n",
+ "\n",
+ "[[ 1.00000000e+00 -5.00000000e+00 -8.88178420e-16]\n",
+ " [ -5.00000000e+00 4.00000000e-01 2.00000000e-01]\n",
+ " [ -8.88178420e-16 2.00000000e-01 2.60000000e+00]]\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter8_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter8_10.ipynb new file mode 100644 index 00000000..f9594f07 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter8_10.ipynb @@ -0,0 +1,1093 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:2931d18383652f9ddbbffb4012198b4962547d461a3374ea2ad7fe562dec2ad9"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter08:Numerical Solution of Ordinary Differential Equations"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.1:pg-304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.1\n",
+ "#taylor's method\n",
+ "#page 304\n",
+ "import math\n",
+ "f=1 #value of function at 0\n",
+ "def f1(x):\n",
+ " return x-f**2\n",
+ "def f2(x):\n",
+ " return 1-2*f*f1(x)\n",
+ "def f3(x):\n",
+ " return -2*f*f2(x)-2*f2(x)**2\n",
+ "def f4(x):\n",
+ " return -2*f*f3(x)-6*f1(x)*f2(x)\n",
+ "def f5(x):\n",
+ " return -2*f*f4(x)-8*f1(x)*f3(x)-6*f2(x)**2\n",
+ "h=0.1 #value at 0.1\n",
+ "k=f \n",
+ "for j in range(1,5):\n",
+ " if j==1:\n",
+ " k=k+h*f1(0);\n",
+ " elif j==2:\n",
+ " k=k+(h**j)*f2(0)/math.factorial(j)\n",
+ " elif j ==3:\n",
+ " k=k+(h**j)*f3(0)/math.factorial(j)\n",
+ " elif j ==4:\n",
+ " k=k+(h**j)*f4(0)/math.factorial(j)\n",
+ " elif j==5:\n",
+ " k=k+(h**j)*f5(0)/math.factorial(j)\n",
+ "print \"the value of the function at %.2f is :%0.4f\" %(h,k)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of the function at 0.10 is :0.9113\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.2:pg-304"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#taylor's method\n",
+ "#example 8.2\n",
+ "#page 304\n",
+ "import math\n",
+ "f=1 #value of function at 0\n",
+ "f1=0 #value of first derivatie at 0\n",
+ "def f2(x):\n",
+ " return x*f1+f\n",
+ "def f3(x):\n",
+ " return x*f2(x)+2*f1\n",
+ "def f4(x):\n",
+ " return x*f3(x)+3*f2(x)\n",
+ "def f5(x):\n",
+ " return x*f4(x)+4*f3(x)\n",
+ "def f6(x):\n",
+ " return x*f5(x)+5*f4(x)\n",
+ "h=0.1 #value at 0.1\n",
+ "k=f\n",
+ "for j in range(1,6):\n",
+ " if j==1:\n",
+ " k=k+h*f1\n",
+ " elif j==2:\n",
+ " k=k+(h**j)*f2(0)/math.factorial(j)\n",
+ " elif j ==3:\n",
+ " k=k+(h**j)*f3(0)/math.factorial(j)\n",
+ " elif j ==4:\n",
+ " k=k+(h**j)*f4(0)/math.factorial(j)\n",
+ " elif j==5:\n",
+ " k=k+(h**j)*f5(0)/math.factorial(j)\n",
+ " else:\n",
+ " k=k+(h**j)*f6(0)/math.factorial (j)\n",
+ "print \"the value of the function at %.2f is :%0.7f\" %(h,k)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of the function at 0.10 is :1.0050125\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.3:pg-306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.3\n",
+ "#picard's method\n",
+ "#page 306\n",
+ "from scipy import integrate\n",
+ "from __future__ import division\n",
+ "def f(x,y):\n",
+ " return x+y**2\n",
+ "y=[0,0,0,0]\n",
+ "y[1]=1\n",
+ "for i in range(1,3):\n",
+ " a=integrate.quad(lambda x:x+y[i]**2,0,i/10)\n",
+ " y[i+1]=a[0]+y[1]\n",
+ " print \"\\n y (%g) = %g\\n\" %(i/10,y[i+1])"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " y (0.1) = 1.105\n",
+ "\n",
+ "\n",
+ " y (0.2) = 1.26421\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 22
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.4:pg-306"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.4\n",
+ "#picard's method\n",
+ "#page 306\n",
+ "from scipy import integrate\n",
+ "y=[0,0,0,0] #value at 0\n",
+ "c=0.25\n",
+ "for i in range(0,3):\n",
+ " a=integrate.quad(lambda x:(x**2/(y[i]**2+1)),0,c)\n",
+ " y[i+1]=y[0]+a[0]\n",
+ " print \"\\n y(%0.2f) = %g\\n\" %(c,y[i+1])\n",
+ " c=c*2"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " y(0.25) = 0.00520833\n",
+ "\n",
+ "\n",
+ " y(0.50) = 0.0416655\n",
+ "\n",
+ "\n",
+ " y(1.00) = 0.332756\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.5:pg-308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.5\n",
+ "#euler's method\n",
+ "#page 308\n",
+ "def f(y):\n",
+ " return -1*y\n",
+ "y=[0,0,0,0,0]\n",
+ "y[0]=1 #value at 0\n",
+ "h=0.01\n",
+ "c=0.01\n",
+ "for i in range(0,4):\n",
+ " y[i+1]=y[i]+h*f(y[i])\n",
+ " print \"\\ny(%g)=%g\\n\" %(c,y[i+1])\n",
+ " c=c+0.01\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "y(0.01)=0.99\n",
+ "\n",
+ "\n",
+ "y(0.02)=0.9801\n",
+ "\n",
+ "\n",
+ "y(0.03)=0.970299\n",
+ "\n",
+ "\n",
+ "y(0.04)=0.960596\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.6:pg-308"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.6\n",
+ "#error estimates in euler's \n",
+ "#page 308\n",
+ "import math\n",
+ "from __future__ import division\n",
+ "def f(y):\n",
+ " return -1*y\n",
+ "y=[0,0,0,0,0]\n",
+ "L=[0,0,0,0,0]\n",
+ "e=[0,0,0,0,0]\n",
+ "y[0]=1 #value at 0\n",
+ "h=0.01\n",
+ "c=0.01;\n",
+ "for i in range(0,4):\n",
+ " y[i+1]=y[i]+h*f(y[i])\n",
+ " print \"\\ny(%g)=%g\\n\" %(c,y[i+1])\n",
+ " c=c+0.01\n",
+ "for i in range(0,4):\n",
+ " L[i]=abs(-(1/2)*(h**2)*y[i+1])\n",
+ " print \"L(%d) =%f\\n\\n\" %(i,L[i])\n",
+ "e[0]=0\n",
+ "for i in range(0,4):\n",
+ " e[i+1]=abs(y[1]*e[i]+L[0])\n",
+ " print \"e(%d)=%f\\n\\n\" %(i,e[i])\n",
+ "Actual_value=math.exp(-0.04)\n",
+ "Estimated_value=y[4]\n",
+ "err=abs(Actual_value-Estimated_value)\n",
+ "if err<e[4]:\n",
+ " print \"VERIFIED\"\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "y(0.01)=0.99\n",
+ "\n",
+ "\n",
+ "y(0.02)=0.9801\n",
+ "\n",
+ "\n",
+ "y(0.03)=0.970299\n",
+ "\n",
+ "\n",
+ "y(0.04)=0.960596\n",
+ "\n",
+ "L(0) =0.000050\n",
+ "\n",
+ "\n",
+ "L(1) =0.000049\n",
+ "\n",
+ "\n",
+ "L(2) =0.000049\n",
+ "\n",
+ "\n",
+ "L(3) =0.000048\n",
+ "\n",
+ "\n",
+ "e(0)=0.000000\n",
+ "\n",
+ "\n",
+ "e(1)=0.000050\n",
+ "\n",
+ "\n",
+ "e(2)=0.000099\n",
+ "\n",
+ "\n",
+ "e(3)=0.000147\n",
+ "\n",
+ "\n",
+ "VERIFIED\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.7:pg-310"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.7\n",
+ "#modified euler's method\n",
+ "#page 310\n",
+ "h=0.05\n",
+ "f=1\n",
+ "def f1(x,y):\n",
+ " return x**2+y\n",
+ "x=[0,0.05,0.1]\n",
+ "y1=[0,0,0,0]\n",
+ "y2=[0,0,0,0]\n",
+ "y1[0]=f+h*f1(x[0],f);\n",
+ "y1[1]=f+h*(f1(x[0],f)+f1(x[1],y1[0]))/2\n",
+ "y1[2]=f+h*(f1(x[0],f)+f1(x[2],y1[1]))/2\n",
+ "y2[0]=y1[1]+h*f1(x[1],y1[1])\n",
+ "y2[1]=y1[1]+h*(f1(x[1],y1[1])+f1(x[2],y2[0]))/2\n",
+ "y2[2]=y1[1]+h*(f1(x[1],y1[1])+f1(x[2],y2[1]))/2\n",
+ "print \"y1(0)\\t y1(1)\\t y1(2)\\t y2(0)\\t y2(1)\\t y3(2)\\n\\n\"\n",
+ "print \" %f\\t %f\\t %f\\t %f\\t %f\\t %f\\n\" %(y1[0],y1[1],y1[2],y2[0],y2[1],y2[2])\n",
+ "print \"\\n\\n the value of y at %0.2f is : %0.4f\" %(x[2],y2[2])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "y1(0)\t y1(1)\t y1(2)\t y2(0)\t y2(1)\t y3(2)\n",
+ "\n",
+ "\n",
+ " 1.050000\t 1.051313\t 1.051533\t 1.104003\t 1.105508\t 1.105546\n",
+ "\n",
+ "\n",
+ "\n",
+ " the value of y at 0.10 is : 1.1055\n"
+ ]
+ }
+ ],
+ "prompt_number": 25
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.8:pg-313"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.8\n",
+ "#runge-kutta formula\n",
+ "#page 313\n",
+ "from __future__ import division\n",
+ "def f(x,y):\n",
+ " return y-x\n",
+ "y=2\n",
+ "x=0\n",
+ "h=0.1\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h,y+K1)\n",
+ "y1=y+( K1+K2)/2\n",
+ "print \"\\n y(0.1) by second order runge kutta method:%0.4f\" %(y1)\n",
+ "y=y1\n",
+ "x=0.1\n",
+ "h=0.1\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h,y+K1)\n",
+ "y1=y+( K1+K2)/2\n",
+ "print \"\\n y(0.2) by second order runge kutta method:%0.4f\" %(y1)\n",
+ "y=2\n",
+ "x=0\n",
+ "h=0.1\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "print \"\\n y(0.1) by fourth order runge kutta method:%0.4f\" %(y1)\n",
+ "y=y1\n",
+ "x=0.1\n",
+ "h=0.1\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "print \"\\n y(0.1) by fourth order runge kutta method:%0.4f \" %(y1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " y(0.1) by second order runge kutta method:2.2050\n",
+ "\n",
+ " y(0.2) by second order runge kutta method:2.4210\n",
+ "\n",
+ " y(0.1) by fourth order runge kutta method:2.2052\n",
+ "\n",
+ " y(0.1) by fourth order runge kutta method:2.4214 \n"
+ ]
+ }
+ ],
+ "prompt_number": 29
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.9:pg-315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.9\n",
+ "#runge kutta method\n",
+ "#page 315\n",
+ "from __future__ import division\n",
+ "def f(x,y):\n",
+ " return 1+y**2\n",
+ "y=0\n",
+ "x=0\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "print \"\\n y(0.2) by fourth order runge kutta method:%0.4f\" %(y1)\n",
+ "y=y1\n",
+ "x=0.2\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "print \"\\n y(0.4) by fourth order runge kutta method:%0.4f\" %(y1)\n",
+ "y=2\n",
+ "x=0\n",
+ "h=0.1\n",
+ "y=y1\n",
+ "x=0.4\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "print \"\\n y(0.6) by fourth order runge kutta method:%0.4f\" %(y1)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " y(0.2) by fourth order runge kutta method:0.2027\n",
+ "\n",
+ " y(0.4) by fourth order runge kutta method:0.4228\n",
+ "\n",
+ " y(0.6) by fourth order runge kutta method:0.6841\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.10:pg-315"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.10\n",
+ "#initial value problems\n",
+ "#page 315\n",
+ "from __future__ import division\n",
+ "def f1(x,y):\n",
+ " return 3*x+y/2\n",
+ "y=[1,0,0]\n",
+ "h=0.1\n",
+ "c=0\n",
+ "for i in range(0,2):\n",
+ " y[i+1]=y[i]+h*f1(c,y[i])\n",
+ " print \"\\ny(%g)=%g\\n\" %(c,y[i])\n",
+ " c=c+0.1\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "y(0)=1\n",
+ "\n",
+ "\n",
+ "y(0.1)=1.05\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 35
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.11:pg-316"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.11\n",
+ "#adam's moulton method\n",
+ "#page 316\n",
+ "def f(x,y):\n",
+ " return 1+y**2\n",
+ "y=0\n",
+ "x=0\n",
+ "h=0.2\n",
+ "f1=[0,0,0]\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "f1[0]=y1\n",
+ "print \"\\n y(0.2) by fourth order runge kutta method:%0.4f\" %(y1)\n",
+ "y=y1\n",
+ "x=0.2\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "f1[1]=y1\n",
+ "print \"\\n y(0.4) by fourth order runge kutta method:%0.4f\" %(y1)\n",
+ "y=2\n",
+ "x=0\n",
+ "h=0.1\n",
+ "y=y1\n",
+ "x=0.4\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "f1[2]=y1\n",
+ "print \"\\n y(0.6) by fourth order runge kutta method:%0.4f\" %(y1)\n",
+ "y_p=y1+h*(55*(1+f1[2]**2)-59*(1+f1[1]**2)+37*(1+f1[0]**2)-9)/24\n",
+ "y_c=y1+h*(9*(1+(y_p-1)**2)+19*(1+f1[2]**2)-5*(1+f1[1]**2)+(1+f1[0]**2))/24\n",
+ "print \"\\nthe predicted value is:%0.4f:\\n\" %(y_p)\n",
+ "print \" the computed value is:%0.4f:\" %(y_c)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " y(0.2) by fourth order runge kutta method:0.2027\n",
+ "\n",
+ " y(0.4) by fourth order runge kutta method:0.4228\n",
+ "\n",
+ " y(0.6) by fourth order runge kutta method:0.6841\n",
+ "\n",
+ "the predicted value is:1.0234:\n",
+ "\n",
+ " the computed value is:0.9512:\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.12:pg-320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.12\n",
+ "#milne's method\n",
+ "#page 320\n",
+ "def f(x,y):\n",
+ " return 1+y**2\n",
+ "y=0\n",
+ "f1=[0,0,0]\n",
+ "Y1=[0,0,0,0]\n",
+ "x=0\n",
+ "h=0.2\n",
+ "f1[0]=0\n",
+ "print \"x y y1=1+y^2\\n\\n\"\n",
+ "Y1[0]=1+y**2\n",
+ "print \"%0.4f %0.4f %0.4f\\n\" %(x,y,(1+y**2))\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "f1[0]=y1\n",
+ "Y1[1]=1+y1**2\n",
+ "print \"%0.4f %0.4f %0.4f\\n\" %(x+h,y1,(1+y1**2))\n",
+ "y=y1\n",
+ "x=0.2\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "f1[1]=y1\n",
+ "Y1[2]=1+y1**2\n",
+ "print \"%0.4f %0.4f %0.4f\\n\" %(x+h,y1,(1+y1**2))\n",
+ "y=y1\n",
+ "x=0.4\n",
+ "h=0.2\n",
+ "K1=h*f(x,y)\n",
+ "K2=h*f(x+h/2,y+K1/2)\n",
+ "K3=h*f(x+h/2,y+K2/2)\n",
+ "K4=h*f(x+h,y+K3)\n",
+ "y1=y+(K1+2*K2+2*K3+K4)/6\n",
+ "f1[2]=y1\n",
+ "Y1[3]=1+y1**2;\n",
+ "print \"%0.4f %0.4f %0.4f\\n\" %(x+h,y1,(1+y1**2))\n",
+ "Y_4=4*h*(2*Y1[1]-Y1[2]+2*Y1[3])/3\n",
+ "print \"y(0.8)=%f\\n\" %(Y_4)\n",
+ "Y=1+Y_4**2\n",
+ "Y_4=f1[1]+h*(Y1[2]+4*Y1[3]+Y)/3 #more correct value\n",
+ "print \"y(0.8)=%f\\n\" %(Y_4)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "x y y1=1+y^2\n",
+ "\n",
+ "\n",
+ "0.0000 0.0000 1.0000\n",
+ "\n",
+ "0.2000 0.2027 1.0411\n",
+ "\n",
+ "0.4000 0.4228 1.1788\n",
+ "\n",
+ "0.6000 0.6841 1.4680\n",
+ "\n",
+ "y(0.8)=1.023869\n",
+ "\n",
+ "y(0.8)=1.029403\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.13:pg-320"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.13\n",
+ "#milne's method\n",
+ "#page 320\n",
+ "def f1(x,y):\n",
+ " return x**2+y**2-2\n",
+ "x=[-0.1, 0, 0.1, 0.2]\n",
+ "y=[1.0900, 1.0, 0.8900, 0.7605]\n",
+ "Y1=[0,0,0,0]\n",
+ "h=0.1\n",
+ "for i in range(0,4):\n",
+ " Y1[i]=f1(x[i],y[i])\n",
+ "print \" x y y1=x^2+y^2-2 \\n\\n\"\n",
+ "for i in range(0,4):\n",
+ " print \" %0.2f %f %f \\n\" %(x[i],y[i],Y1[i])\n",
+ "Y_3=y[0]+(4*h/3)*(2*Y1[1]-Y1[2]+2*Y1[3])\n",
+ "print \"y(0.3)=%f\\n\" %(Y_3)\n",
+ "Y1_3=f1(0.3,Y_3)\n",
+ "Y_3=y[2]+h*(Y1[2]+4*Y1[3]+Y1_3)/3 #corrected value\n",
+ "print \"corrected y(0.3)=%f\" %(Y_3)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " x y y1=x^2+y^2-2 \n",
+ "\n",
+ "\n",
+ " -0.10 1.090000 -0.801900 \n",
+ "\n",
+ " 0.00 1.000000 -1.000000 \n",
+ "\n",
+ " 0.10 0.890000 -1.197900 \n",
+ "\n",
+ " 0.20 0.760500 -1.381640 \n",
+ "\n",
+ "y(0.3)=0.614616\n",
+ "\n",
+ "corrected y(0.3)=0.614776\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.14:pg322"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#example 8.14\n",
+ "#initial-value problem\n",
+ "#page 322\n",
+ "from __future__ import division\n",
+ "import math\n",
+ "def f(x):\n",
+ " return 13*math.exp(x/2)-6*x-12\n",
+ "s1=1.691358\n",
+ "s3=3.430879\n",
+ "print \"the erorr in the computed values are %0.7g %0.7g\" %(abs(f(0.5)-s1),abs(f(1)-s3))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the erorr in the computed values are 0.0009724169 0.002497519\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.15:pg-328"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#boundary value problem using finite difference method\n",
+ "#example 8.15\n",
+ "#page 328\n",
+ "import math\n",
+ "from numpy import matrix\n",
+ "def f(x):\n",
+ " return math.cos(x)+((1-math.cos(1))/math.sin(1))*math.sin(x)-1\n",
+ "h1=1/2\n",
+ "Y=f(0.5)\n",
+ "y0=0\n",
+ "y2=0\n",
+ "y1=4*(1/4+y0+y2)/7\n",
+ "print \"computed value with h=%f of y(0.5) is %f\\n\" %(h1,y1)\n",
+ "print \"error in the result with actual value %f\\n\" %(abs(Y-y1))\n",
+ "h2=1/4\n",
+ "y0=0\n",
+ "y4=0\n",
+ "#solving the approximated diffrential equation\n",
+ "A=matrix([[-31/16, 1, 0],[1, -31/16, 1],[0, 1, -31/16]])\n",
+ "X=matrix([[-1/16],[-1/16],[-1/16]])\n",
+ "C=A.I*X\n",
+ "print \"computed value with h=%f of y(0.5) is %f\\n\" %(h2,C[1][0])\n",
+ "print \"error in the result with actual value %f\\n\" %(abs(Y-C[1][0]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "computed value with h=0.500000 of y(0.5) is 0.142857\n",
+ "\n",
+ "error in the result with actual value 0.003363\n",
+ "\n",
+ "computed value with h=0.250000 of y(0.5) is 0.140312\n",
+ "\n",
+ "error in the result with actual value 0.000818\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.16:pg-329"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#boundary value problem using finite difference method\n",
+ "#example 8.16\n",
+ "#page 329\\\n",
+ "from numpy import matrix\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.sinh(x)\n",
+ "y0=0 #y(0)=0\n",
+ "y4=3.62686 #y(2)=3.62686\n",
+ "h1=0.5\n",
+ "Y=f(0.5)\n",
+ "#arranging and calculating the values\n",
+ "A=matrix([[-9, 4, 0],[4, -9, 4],[0, 4, -9]])\n",
+ "C=matrix([[0],[0],[-14.50744]])\n",
+ "X=A.I*C\n",
+ "print \"computed value with h=%f of y(0.5) is %f\\n\" %(h1,X[0][0])\n",
+ "print \"error in the result with actual value %f\\n\" %(abs(Y-X[0][0]))\n",
+ "h2=1.0\n",
+ "y0=0 #y(0)=0\n",
+ "y2=3.62686 #y(2)=3.62686\n",
+ "y1=(y0+y2)/3\n",
+ "Y=(4*X[1][0]-y1)/3\n",
+ "print \"with better approximation error is reduced to %f\" %(abs(Y-f(1.0)))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "computed value with h=0.500000 of y(0.5) is 0.526347\n",
+ "\n",
+ "error in the result with actual value 0.005252\n",
+ "\n",
+ "with better approximation error is reduced to 0.000855\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.17:pg-330"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic spline method\n",
+ "#example 8.17\n",
+ "#page 330\n",
+ "import math\n",
+ "def f(x):\n",
+ " return math.cos(x)+((1-math.cos(1))/math.sin(1))*math.sin(x)-1\n",
+ "y=[f(0), f(0.5), f(1)]\n",
+ "h=1/2\n",
+ "Y=f(0.5)\n",
+ "y0=0\n",
+ "y2=0\n",
+ "M0=-1\n",
+ "M1=-22/25\n",
+ "M2=-1\n",
+ "s1_0=47/88\n",
+ "s1_1=-47/88\n",
+ "s1_05=0\n",
+ "print \"the cubic spline value is %f\" %(Y)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the cubic spline value is 0.139494\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.18:pg-331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic spline method\n",
+ "#example 8.18\n",
+ "#page 331\n",
+ "from numpy import matrix\n",
+ "from __future__ import division\n",
+ "import math\n",
+ "#after arranging and forming equation \n",
+ "A=matrix([[10, -1, 0, 24],[0, 16, -1, -32],[1, 20, 0, 16],[0, 1, 26, -24]])\n",
+ "C=matrix([[36],[-12],[24],[-9]])\n",
+ "X=A.I*C;\n",
+ "print \" Y1=%f\\n\\n\" %(X[3][0])\n",
+ "print \" the error in the solution is :%f\" %(abs((2/3)-X[3][0]))"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Y1=0.653890\n",
+ "\n",
+ "\n",
+ " the error in the solution is :0.012777\n"
+ ]
+ }
+ ],
+ "prompt_number": 17
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex8.19:pg-331"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#boundary value problem by cubisc spline nethod\n",
+ "#example 8.18\n",
+ "#page 331\n",
+ "from numpy import matrix\n",
+ "h=1/2\n",
+ "#arranging in two subintervals we get\n",
+ "A=matrix([[10, -1, 0,24],[0, 16, -1, -32],[1, 20, 0, 16],[0, 1, 26, -24]])\n",
+ "C=matrix([[36],[-12],[24],[-9]])\n",
+ "X=A.I*C\n",
+ "print \"the computed value of y(1.5) is %f \"%(X[3][0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the computed value of y(1.5) is 0.653890 \n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter_5_10.ipynb b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter_5_10.ipynb new file mode 100644 index 00000000..697b9cb3 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/chapter_5_10.ipynb @@ -0,0 +1,359 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:f2fd61e2bc794cbd536a64a99cc1e32ed50fce093e2901b8c1e8c55a86c80516"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter05:Spline Functions"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.1:pg-182"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#linear splines\n",
+ "#example 5.1\n",
+ "#page 182\n",
+ "from numpy import matrix\n",
+ "X=matrix([[1],[2], [3]])\n",
+ "y=matrix([[-8],[-1],[18]])\n",
+ "m1=(y[1][0]-y[0][0])/(X[1][0]-X[0][0])\n",
+ "m2=(y[2][0]-y[1][0])/(X[2][0]-X[1][0])\n",
+ "def s1(x):\n",
+ " return y[0][0]+(x-X[0][0])*m1\n",
+ "def s2(x):\n",
+ " return y[1][0]+(x-X[1][0])*m2\n",
+ "print \"the value of function at 2.5 is %0.2f: \" %(s2(2.5))\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the value of function at 2.5 is 8.50: \n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.3:pg-188"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic splines\n",
+ "#example 5.3\n",
+ "#page 188\n",
+ "from numpy import matrix\n",
+ "import math\n",
+ "X=matrix([[1],[2],[3]])\n",
+ "y=matrix([[-8],[-1],[18]])\n",
+ "M1=0\n",
+ "M2=8\n",
+ "M3=0\n",
+ "h=1\n",
+ "#deff('y=s1(x)','y=3*(x-1)^3-8*(2-x)-4*(x-1)')\n",
+ "def s1(x):\n",
+ " return 3*math.pow(x-1,3)-8*(2-x)-4*(x-1)\n",
+ "#deff('y=s2(x)','y=3*(3-x)^3+22*x-48');\n",
+ "def s2(x):\n",
+ " return 3*math.pow(3-x,3)+22*x-48\n",
+ "h=0.0001\n",
+ "n=2.0\n",
+ "D=(s2(n+h)-s2(n))/h;\n",
+ "print \" y(2.5)=%f\" %(s2(2.5))\n",
+ "print \"y1(2.0)=%f\" %(D)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " y(2.5)=7.375000\n",
+ "y1(2.0)=13.000900\n"
+ ]
+ }
+ ],
+ "prompt_number": 18
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.4:pg-189"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic spline\n",
+ "#example 5.4\n",
+ "#page 189\n",
+ "from numpy import matrix\n",
+ "import math\n",
+ "x=matrix([[0],[math.pi/2],[math.pi]])\n",
+ "y=matrix([[0],[1],[0]])\n",
+ "h=x[1][0]-x[0][0]\n",
+ "M0=0\n",
+ "M2=0\n",
+ "M1=((6*(y[0][0]-2*y[1][0]+y[2][0])/math.pow(h,2))-M0-M2)/4\n",
+ "X=math.pi/6.0\n",
+ "s1=(math.pow(x[1][0]-X,3)*(M0/6)+math.pow(X-x[0][0],3)*M1/6+(y[0][0]-math.pow(h,2)*M0/6)*(x[1][0]-X)+(y[1][0]-math.pow(h,2)*M1/6)*(X-x[0][0]))/h;\n",
+ "x=matrix([[0],[math.pi/4], [math.pi/2], [3*math.pi/4], [math.pi]])\n",
+ "y=matrix([[0], [1.414], [1] ,[1.414]])\n",
+ "M0=0\n",
+ "M4=0\n",
+ "A=matrix([[4, 1, 0],[1, 4, 1],[0 ,1 ,4]]) #calculating value of M1 M2 M3 by matrix method\n",
+ "C=matrix([[-4.029],[-5.699],[-4.029]])\n",
+ "B=A.I*C\n",
+ "print \"M0=%f\\t M1=%f\\t M2=%f\\t M3=%f\\t M4=%f\\t\\n\\n\" %(M0,B[0][0],B[1][0],B[2][0],M4)\n",
+ "h=math.pi/4;\n",
+ "X=math.pi/6;\n",
+ "s1=(-0.12408*math.pow(X,3)+0.7836*X)/h;\n",
+ "print \"the value of sin(pi/6) is:%f\" %(s1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "M0=0.000000\t M1=-0.744071\t M2=-1.052714\t M3=-0.744071\t M4=0.000000\t\n",
+ "\n",
+ "\n",
+ "the value of sin(pi/6) is:0.499722\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.5:pg-191"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic spline\n",
+ "#example 5.5\n",
+ "#page 191\n",
+ "import math\n",
+ "from numpy import matrix\n",
+ "x=[1,2,3]\n",
+ "y=[6,18,42]\n",
+ "m0=40\n",
+ "s1=0\n",
+ "m1=(3*(y[2]-y[0])-m0)/4\n",
+ "X=0\n",
+ "s1=m0*((x[1]-X)**2)*(X-x[0])-m1*((X-x[0])**2)*(x[1]-X)+y[0]*((x[1]-X)**2)*(2*(X-x[0])+1)+y[1]*((X-x[0])**2)*(2*(x[1]-X)+1)\n",
+ "print \"s1= %f+261*x-160X^2+33X^3\" %(s1)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s1= -128.000000+261*x-160X^2+33X^3\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.7:pg-195"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#surface fitting by cubic spline\n",
+ "#example 5.7\n",
+ "#page 195\n",
+ "import math\n",
+ "from numpy import matrix\n",
+ "def L0(y):\n",
+ " return math.pow(y,3)/4-5*y/4+1\n",
+ "def L1(y):\n",
+ " return (math.pow(y,3)/2)*-1+3*y/2\n",
+ "def L2(y):\n",
+ " return math.pow(y,3)/4-y/4\n",
+ "A=[ [1,2,9], [2,3,10], [9,10,17] ]\n",
+ "x=0.5\n",
+ "y=0.5\n",
+ "S=0.0\n",
+ "S=S+L0(x)*(L0(x)*A[0][0]+L1(x)*A[0][1]+L2(x)*A[0][2])\n",
+ "S=S+L1(x)*(L0(x)*A[1][0]+L1(x)*A[1][1]+L2(x)*A[1][2])\n",
+ "S=S+L2(x)*(L0(x)*A[2][0]+L1(x)*A[2][1]+L2(x)*A[2][2])\n",
+ "print \"approximated value of z(0.5 0.5)=%f\\n\\n\" %(S)\n",
+ "print \" error in the approximated value : %f\" %((abs(1.25-S)/1.25)*100)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "approximated value of z(0.5 0.5)=0.875000\n",
+ "\n",
+ "\n",
+ " error in the approximated value : 30.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 30
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.8:pg-200"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic B-splines\n",
+ "#example 5.8\n",
+ "#page 200\n",
+ "import math\n",
+ "k=[0.0, 1, 2, 3, 4]\n",
+ "pi=[0.0, 0, 4, -6, 24]\n",
+ "x=1\n",
+ "S=0\n",
+ "for i in range(2,5):\n",
+ " S=S+math.pow(k[i]-x,3)/(pi[i])\n",
+ "print \"the cubic splines for x=1 is %f\\n\\n\" %(S)\n",
+ "S=0\n",
+ "x=2\n",
+ "for i in range(2,5):\n",
+ " S=S+math.pow(k[i]-x,3)/(pi[i])\n",
+ "print \"the cubic splines for x=2 is %f\\n\\n\" %(S)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "the cubic splines for x=1 is 0.041667\n",
+ "\n",
+ "\n",
+ "the cubic splines for x=2 is 0.166667\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 39
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Ex5.9:pg-201"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#cubic B-spline\n",
+ "#example 5.9\n",
+ "#page 201\n",
+ "k=[0, 1, 2, 3, 4];\n",
+ "x=1 #for x=1\n",
+ "s11=0\n",
+ "s13=0\n",
+ "s14=0\n",
+ "s24=0 \n",
+ "s12=1/(k[2]-k[1])\n",
+ "s22=((x-k[0])*s11+(k[2]-x)*s12)/2.0 #k[2]-k[0]=2\n",
+ "s23=((x-k[1])*s11+(k[3]-x)*s13)/(k[3]-k[1])\n",
+ "s33=((x-k[0])*s22+(k[3]-x)*s23)/(k[3]-k[0])\n",
+ "s34=((x-k[1])*s23+(k[4]-x)*s24)/(k[4]-k[1])\n",
+ "s44=((x-k[0])*s33+(k[4]-x)*s34)/(k[4]-k[0])\n",
+ "print \"s11=%f\\t s22=%f\\t s23=%f\\t s33=%f\\t s34=%f\\t s44=%f\\n\\n\" %(s11,s22,s23,s33,s34,s44)\n",
+ "x=2 #for x=2\n",
+ "s11=0\n",
+ "s12=0\n",
+ "s14=0\n",
+ "s22=0\n",
+ "s13=1/(k[3]-k[2])\n",
+ "s23=((x-k[1])*s12+(k[3]-x)*s13)/2.0 # k[3]-k[1]=2\n",
+ "s24=((x-k[2])*s13+(k[4]-x)*s14)/(k[2]-k[0])\n",
+ "s33=((x-k[0])*s22+(k[3]-x)*s23)/(k[3]-k[0])\n",
+ "s34=((x-k[1])*s23+(k[4]-x)*s24)/(k[4]-k[1])\n",
+ "s44=((x-k[0])*s33+(k[4]-x)*s34)/(k[4]-k[0])\n",
+ "print \"s13=%f\\t s23=%f\\t s24=%f\\t s33=%f\\t s34=%f\\t s44=%f\\n\\n\" %(s13,s23,s24,s33,s34,s44)"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "s11=0.000000\t s22=0.500000\t s23=0.000000\t s33=0.166667\t s34=0.000000\t s44=0.041667\n",
+ "\n",
+ "\n",
+ "s13=1.000000\t s23=0.500000\t s24=0.000000\t s33=0.166667\t s34=0.166667\t s44=0.166667\n",
+ "\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 51
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex1.2_5.png b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex1.2_5.png Binary files differnew file mode 100644 index 00000000..9dd9ad02 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex1.2_5.png diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex3.7_2.png b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex3.7_2.png Binary files differnew file mode 100644 index 00000000..81986fc3 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex3.7_2.png diff --git a/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex6.5_2.png b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex6.5_2.png Binary files differnew file mode 100644 index 00000000..1628bc09 --- /dev/null +++ b/Introductory_Methods_Of_Numerical_Analysis__by_S._S._Sastry/screenshots/ex6.5_2.png diff --git a/Linear_Integrated_Circuits_by_T._R._Ganesh_Babu/README.txt b/Linear_Integrated_Circuits_by_T._R._Ganesh_Babu/README.txt new file mode 100644 index 00000000..652e7137 --- /dev/null +++ b/Linear_Integrated_Circuits_by_T._R._Ganesh_Babu/README.txt @@ -0,0 +1,10 @@ +Contributed By: S PRASHANTH S PRASHANTH +Course: be +College/Institute/Organization: Bannari Amman Institute of Technology +Department/Designation: Electrical Electronics +Book Title: Linear Integrated Circuits +Author: T. R. Ganesh Babu +Publisher: scitech chennai +Year of publication: 2004 +Isbn: 8188429430 +Edition: third
\ No newline at end of file diff --git a/Power_Plant_Engineering_by_P._K._Nag/README.txt b/Power_Plant_Engineering_by_P._K._Nag/README.txt new file mode 100644 index 00000000..81002f0e --- /dev/null +++ b/Power_Plant_Engineering_by_P._K._Nag/README.txt @@ -0,0 +1,10 @@ +Contributed By: Babita . +Course: btech +College/Institute/Organization: UTU +Department/Designation: EN +Book Title: Power Plant Engineering +Author: P. K. Nag +Publisher: Tata McGraw, New Delhi +Year of publication: 2001 +Isbn: 0070435995 +Edition: 2
\ No newline at end of file diff --git a/sample_notebooks/MaheshkumarEaga/Chapter_2.ipynb b/sample_notebooks/MaheshkumarEaga/Chapter_2.ipynb new file mode 100644 index 00000000..cf246c3c --- /dev/null +++ b/sample_notebooks/MaheshkumarEaga/Chapter_2.ipynb @@ -0,0 +1,442 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 2 : Finite Sample Spaces\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.1 , Page number : 21" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Probability of p1 is : 4/7\n", + "Probability of p2 is : 2/7\n", + "Probability of p3 is : 1/7\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "# p1,p2 and p3 be the probabilities of events a1,a2 and a3\n", + "# Probalitity of p1+p2+p3=1 and p1=2*p2 , p2=2*p3\n", + " \n", + "\n", + "#calculation\n", + "p2= 1.0/(2.0+1.0+1.0/2.0) #p1+p2+p3=1 hence 2p2+p2+p3/3=1 \n", + " #p2(2+1+1/3)=1\n", + "p1=2.0*p2\n", + "p3=1.0/2*p2\n", + "\n", + "#converstion of floating point value into Fraction and Result\n", + "print \"Probability of p1 is :\",Fraction(p1).limit_denominator(1000)\n", + "print \"Probability of p2 is :\",Fraction(p2).limit_denominator(1000)\n", + "print \"Probability of p3 is :\",Fraction(p3).limit_denominator(1000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.2 , Page number : 22" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Probability of number greater than 4 in single throw of die : 1/3\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "S = {1,2,3,4,5,6} #Sample space for single throw of die\n", + "A = { } #Event occurance of number >4 initially empty\n", + "\n", + "count=0\n", + "\n", + "for i in S: #counting the number of elements greater than 4\n", + " if i>4:\n", + " count=count+1\n", + "\n", + "x= float (count)/len(S) # Probability of A\n", + "\n", + "#Result\n", + "print \"Probability of number greater than 4 in single throw of die : \",Fraction(x).limit_denominator(1000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.3 , Page number : 22" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Probability of number of Heads are 1 in single throw of two coins : 1/2\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "mylist=[0,0,0] #Initially posiions of list represents number of occurances of H in event\n", + "count=0 #to count total number of possible events\n", + "for i in range(0,2): #method to generate the 2 elemets unordered pairs H and T and 0 represents Head and 1 represents TAIL\n", + " for j in range(0,2):\n", + " count=count+1 #counting the total number of order pairs\n", + " if i+j==0:\n", + " mylist[0]=mylist[0]+1\n", + " if i+j==1:\n", + " mylist[1]=mylist[1]+1\n", + " if i+j==2:\n", + " mylist[2]=mylist[2]+1\n", + "\n", + "x= float(mylist[1])/count #probability of number of heads are 1\n", + "\n", + "#Result\n", + "print \"Probability of number of Heads are 1 in single throw of two coins : \",Fraction(x).limit_denominator(1000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.4 , Page number : 24" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of ways to select 5 items from 20 items : 15504.0\n", + "number of ways to select 5 items from 80 items : 24040016.0\n", + "number of ways to select 10 items from 100 items : 1.73103094564e+13\n", + "Required probability is : 1/719598\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "#lot has 20 defective and 80 non defective items\n", + "#ten items choosen withour replacement such half 5 are defective and 5 are non defective\n", + "\n", + "def factorial(value): #Function to calculate factorial\n", + " result=1\n", + " for i in range(1,value+1):\n", + " result=result*i\n", + " return result\n", + " \n", + "x=factorial(20);\n", + "y=factorial(15);\n", + "z=factorial(5);\n", + "\n", + "slection_from_20=float(x)/(y*z) #calculating 20!/(15!*5!)\n", + " \n", + "x=factorial(80);\n", + "y=factorial(75);\n", + "z=factorial(5);\n", + "\n", + "slection_from_80=float(x)/(y*z) #calculating 80!/(75!*5!)\n", + "\n", + "x=factorial(100);\n", + "y=factorial(90);\n", + "z=factorial(10);\n", + "\n", + "slection_from_100=float(x)/(y*z) # calculating 100!/(90!*10!)\n", + "print \"number of ways to select 5 items from 20 items : \",slection_from_20\n", + "print \"number of ways to select 5 items from 80 items : \",slection_from_80\n", + "print \"number of ways to select 10 items from 100 items : \",slection_from_100\n", + "\n", + "probability= (slection_from_20+slection_from_80)/slection_from_100\n", + "\n", + "#Result\n", + "print \"Required probability is : \",Fraction(probability).limit_denominator(1000000)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.5 , Page number : 24" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "number of ways to select 5 items from 20 items : 15504.0\n", + "number of ways to select 5 items from 80 items : 24040016.0\n", + "number of ways to select 10 items from 100 items : 1.73103094564e+13\n", + "Required probability is : 1/719598\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "#lot has 20 defective and 80 non defective items\n", + "#ten items choosen withour replacement such half 5 are defective and 5 are non defective\n", + "\n", + "def factorial(value): #Function to calculate factorial\n", + " result=1\n", + " for i in range(1,value+1):\n", + " result=result*i\n", + " return result\n", + " \n", + "x=factorial(20);\n", + "y=factorial(15);\n", + "z=factorial(5);\n", + "\n", + "selection_from_20=float(x)/(y*z) # calculating 20!/(15!*5!)\n", + " \n", + "x=factorial(80);\n", + "y=factorial(75);\n", + "z=factorial(5);\n", + "\n", + "selection_from_80=float(x)/(y*z) # calculating 80!/(75!*5!)\n", + "\n", + "x=factorial(100);\n", + "y=factorial(90);\n", + "z=factorial(10);\n", + "\n", + "selection_from_100=float(x)/(y*z) # calculating 100!/(90!*10!)\n", + "probability= (selection_from_20+selection_from_80)/selection_from_100\n", + "\n", + "#Result\n", + "print \"number of ways to select 5 items from 20 items : \",selection_from_20\n", + "print \"number of ways to select 5 items from 80 items : \",selection_from_80\n", + "print \"number of ways to select 10 items from 100 items : \",selection_from_100\n", + "print \"Required probability is : \",Fraction(probability).limit_denominator(1000000)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.7 , Page number : 28" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Subproblem 1 : Number of ways of forming committee of 3 members is : 56\n", + "Subproblem 2 : Numberof signals made up of 3 flags are : 336\n", + "Subproblem 3 : Total number of committes formed are : 30\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "def factorial(value):\t\t\t#Function to calculate factorial\n", + " result=1\n", + " for i in range(1,value+1):\n", + " result=result*i\n", + " return result\n", + " \n", + "#subproblem a Committee selection problem\n", + "\n", + "x=factorial(8);\t\n", + "y=factorial(5);\t\n", + "z=factorial(3);\n", + "selecting_3_from_8 = x/(y*z)\n", + "#Result\n", + "print \"Subproblem 1 : Number of ways of forming committee of 3 members is : \",selecting_3_from_8\n", + "\n", + "\n", + "\n", + "#subproblem b flag problem\n", + "\n", + "x=factorial(8);\t\n", + "y=factorial(5);\t\n", + "\n", + "number_of_ways = x/y\n", + "#Result\n", + "print \"Subproblem 2 : Numberof signals made up of 3 flags are : \",number_of_ways\n", + "\n", + "\n", + "#Sub problem 3 : committee\n", + "x=factorial(5);\t\n", + "y=factorial(3);\t\n", + "z=factorial(2);\n", + "selecting_2_men_from_5 = x/(y*z)\n", + "\n", + "x=factorial(3);\t\n", + "y=factorial(1);\t\n", + "z=factorial(2);\n", + "selecting_1_women_from_3 = x/(y*z)\n", + "\n", + "total_committes=selecting_2_men_from_5*selecting_1_women_from_3\n", + "\n", + "#Result\n", + "print \"Subproblem 3 : Total number of committes formed are : \",total_committes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Example 2.9, Page number : 29" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listing the number of ways of selecting 2 objects from 4 objects without repetition or ordered \n", + "a b\n", + "a c\n", + "a d\n", + "b c\n", + "b d\n", + "c d\n", + "Probability of object c is choosen without repetition is : 1/2\n", + "Listing the number of ways of selecting 2 objects from 4 objects with repetition OR unordered\n", + "a a\n", + "a b\n", + "a c\n", + "a d\n", + "b a\n", + "b b\n", + "b c\n", + "b d\n", + "c a\n", + "c b\n", + "c c\n", + "c d\n", + "d a\n", + "d b\n", + "d c\n", + "d d\n", + "Probability of object c is choosen without repetition is : 7/16\n" + ] + } + ], + "source": [ + "from fractions import Fraction\n", + "\n", + "mylist=['a','b','c','d'] #Objects in sample space\n", + "c_count_with_repeat=0\n", + "c_count_without_repeat=0\n", + "totalways=0\n", + "\n", + "print \"Listing the number of ways of selecting 2 objects from 4 objects without repetition or ordered \"\n", + "for i in range(0,4):\n", + " for j in range (i+1,4):\n", + " totalways=totalways+1 #counting number of ways of orderd listing\n", + " print mylist[i],mylist[j] #Listing ordered pairs\n", + " if(mylist[i]=='c' or mylist[j]=='c'): #checking the object c selected or not while selection atleast once\n", + " c_count_without_repeat=c_count_without_repeat+1\n", + "\n", + "probability_c_without_repeat=float( c_count_without_repeat)/totalways #calculating probability of object c selected without repetition \n", + "\n", + "#Result\n", + "print \"Probability of object c is choosen without repetition is : \",Fraction(probability_c_without_repeat).limit_denominator(1000)\n", + "\n", + "\n", + "totalways=0\n", + "print \"Listing the number of ways of selecting 2 objects from 4 objects with repetition OR unordered\"\n", + "for i in range(0,4):\n", + " for j in range (0,4):\n", + " totalways=totalways+1 #counting number of ways of unorderd listing\n", + " print mylist[i],mylist[j] #Listing unordered pairs\n", + " if(mylist[i]=='c' or mylist[j]=='c'): #checking the object c selected or not while selection atleast once\n", + " c_count_with_repeat=c_count_with_repeat+1\n", + "\n", + "probability_c_with_repeat=float( c_count_with_repeat)/totalways #calculating probability of object c selected with repetition\n", + "\n", + "#Result\n", + "print \"Probability of object c is choosen without repetition is : \",Fraction(probability_c_with_repeat).limit_denominator(1000)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.11" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} |