diff options
author | Trupti Kini | 2017-03-28 23:30:22 +0600 |
---|---|---|
committer | Trupti Kini | 2017-03-28 23:30:22 +0600 |
commit | 5bb207dcfc7ffcad774c729d5cf83a944501411c (patch) | |
tree | 8f366f4cae6fc5ad7415b840490e3a92bb9dec94 | |
parent | 26aa9704628ed4f79be6dd102f2c12d13b3fa85d (diff) | |
download | Python-Textbook-Companions-5bb207dcfc7ffcad774c729d5cf83a944501411c.tar.gz Python-Textbook-Companions-5bb207dcfc7ffcad774c729d5cf83a944501411c.tar.bz2 Python-Textbook-Companions-5bb207dcfc7ffcad774c729d5cf83a944501411c.zip |
Added(A)/Deleted(D) following books
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter1.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter10.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter2.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter3.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter4.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter5.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter6_.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter7.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter8.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter9.ipynb
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/gauss_elimination_method.png
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/solution_by_tdma_method.png
A Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/valueofx123.png
13 files changed, 5632 insertions, 0 deletions
diff --git a/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter1.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter1.ipynb new file mode 100644 index 00000000..6864d1a1 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter1.ipynb @@ -0,0 +1,389 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 1 - Linear Algebraic Equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa1.1 Page 3" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution of ex 1.1 by TDMA method is\n", + "317.5\n", + "395.0\n", + "432.5\n", + "430.0\n", + "387.5\n", + "305.0\n", + "182.5\n" + ] + } + ], + "source": [ + "from numpy import zeros\n", + "from __future__ import division\n", + "a=[0];b=[];c=[]\n", + "for i in range(1,7):\n", + " a.append(1) #sub diagonal assignment\n", + "\n", + "for j in range(0,7):\n", + " b.append(-2) #main diagonal assignment\n", + "\n", + "for k in range(0,6):\n", + " c.append(1) #super diagonal assignment\n", + "\n", + "d=[-240] #given values assignment\n", + "for l in range(1,6):\n", + " d.append(-40) \n", + "\n", + "d.append(-60)\n", + "i=1#\n", + "n=7#\n", + "beta1=[b[i-1]]# #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]]# #since c7=0\n", + "m=i+1\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-1-1]/beta1[j-1-1])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-1-1])/beta1[j-1])\n", + "\n", + "#x(n)=gamma1(n)# #since c7=0\n", + "x=zeros(n-1)\n", + "#x[n-1]=gamma1[n-1]\n", + "x=list(x)\n", + "x.append(gamma1[-1])\n", + "n1=n-i# \n", + "\n", + "for k in range(0,n1):\n", + " j=n-k-1\n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j+1-1]/beta1[j-1]\n", + "\n", + "\n", + "print \"the solution of ex 1.1 by TDMA method is\"\n", + "for i in range(0,7):\n", + " print x[i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa1.2 Page 6" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution using gauss elimination method is 3, 4 and 5\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "a1=10; a2=1; a3=2; #1st row\n", + "b1=2; b2=10; b3=1; #2nd row\n", + "c1=1; c2=2; c3=10; #3rd row \n", + "d1=44; d2=51; d3=61; #given values\n", + "\n", + "b3=b3-(b1/a1)*a3 # for making b1=0\n", + "b2=b2-(b1/a1)*a2\n", + "d2=d2-(b1/a1)*d1\n", + "b1=b1-(b1/a1)*a1\n", + "\n", + "c3=c3-(c1/a1)*a3 # for making c1=0\n", + "c2=c2-(c1/a1)*a2\n", + "d3=d3-(c1/a1)*d1\n", + "c1=c1-(c1/a1)*a1\n", + "\n", + "c3=c3-(c2/b2)*b3 # for making c2=0\n", + "d3=d3-(c2/b2)*d2\n", + "c2=c2-(c2/b2)*b2\n", + "\n", + "x3=d3/c3# # final values of x\n", + "x2=(d2-(b3*x3))/b2#\n", + "x1=(d1-(x3*a3)-(x2*a2))/a1#\n", + "print \"the solution using gauss elimination method is %d, %d and %d\"%(x1,x2,x3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa1.3 Page 7" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution using gauss elimination method is 3, -2 and 0\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "a1=3; a2=1; a3=-2; #1st row\n", + "b1=-1; b2=4; b3=-3; #2nd row\n", + "c1=1; c2=-1; c3=4; #3rd row \n", + "d1=9; d2=-8; d3=1; #given values\n", + "\n", + "b3=b3-(b1/a1)*a3 # for making b1=0\n", + "b2=b2-(b1/a1)*a2\n", + "d2=d2-(b1/a1)*d1\n", + "b1=b1-(b1/a1)*a1\n", + "\n", + "c3=c3-(c1/a1)*a3 # for making c1=0\n", + "c2=c2-(c1/a1)*a2\n", + "d3=d3-(c1/a1)*d1\n", + "c1=c1-(c1/a1)*a1\n", + "\n", + "c3=c3-(c2/b2)*b3 # for making c2=0\n", + "d3=d3-(c2/b2)*d2\n", + "c2=c2-(c2/b2)*b2\n", + "\n", + "x3=d3/c3# # final values of x\n", + "x2=(d2-(b3*x3))/b2#\n", + "x1=(d1-(x3*a3)-(x2*a2))/a1#\n", + "print \"the solution using gauss elimination method is %d, %d and %d\"%(x1,x2,x3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa1.4 Page 8" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of MOLAR FLOW RATES of D1, B1, D2, B2 respectively are : 26, 18, 9 and 17\n", + "the composition of stream B is 0.077, 0.247, 0.467 & 0.210\n", + "the composition of stream D is 0.274 0.492 0.12 0.114\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "a1=.35; a2=.16; a3=.21; a4=.01 #1st row \n", + "b1=.54; b2=.42; b3=.54; b4=.1 #2nd row\n", + "c1=.04; c2=.24; c3=.1; c4=.65 #3rd row\n", + "d1=.07; d2=.18; d3=.15; d4=.24 #4th row \n", + "r1=14; r2=28; r3=17.5; r4=10.5 #given values\n", + "\n", + "b4=b4-(b1/a1)*a4 # for making b1=0\n", + "b3=b3-(b1/a1)*a3\n", + "b2=b2-(b1/a1)*a2\n", + "r2=r2-(b1/a1)*r1\n", + "b1=b1-(b1/a1)*a1\n", + "\n", + "c4=c4-(c1/a1)*a4 # for making c1=0\n", + "c3=c3-(c1/a1)*a3\n", + "c2=c2-(c1/a1)*a2\n", + "r3=r3-(c1/a1)*r1\n", + "c1=c1-(c1/a1)*a1\n", + "\n", + "d4=d4-(d1/a1)*a4 # for making d1=0\n", + "d3=d3-(d1/a1)*a3\n", + "d2=d2-(d1/a1)*a2\n", + "r4=r4-(d1/a1)*r1\n", + "d1=d1-(d1/a1)*a1\n", + "\n", + "c4=c4-(c2/b2)*b4 # for making c2=0\n", + "c3=c3-(c2/b2)*b3\n", + "r3=r3-(c2/b2)*r2\n", + "c2=c2-(c2/b2)*b2\n", + "\n", + "d4=d4-(d2/b2)*b4 # for making d2=0\n", + "d3=d3-(d2/b2)*b3\n", + "r4=r4-(d2/b2)*r2\n", + "d2=d2-(d2/b2)*b2\n", + "\n", + "d4=d4-(d3/c3)*c4 #for making d3=0\n", + "r4=r4-(d3/c3)*r3\n", + "d3=d3-(d3/c3)*c3\n", + "\n", + "B2=r4/d4#\n", + "D2=(r3-(c4*B2))/c3#\n", + "B1=(r2-(D2*b3)-(B2*b4))/b2#\n", + "D1=(r1-(B2*a4)-(D2*a3)-(B1*a2))/a1#\n", + "print \"the values of MOLAR FLOW RATES of D1, B1, D2, B2 respectively are : %.f, %.f, %.f and %.f\"%(D1,B1,D2,B2)\n", + "\n", + "B=D2+B2#\n", + "x1B=(.21*D2 + .01*B2)/B#\n", + "x2B=(.54*D2 + .1*B2)/B#\n", + "x3B=(.1*D2 + .65*B2)/B#\n", + "x4B=(.15*D2 + .24*B2)/B#\n", + "print \"the composition of stream B is %.3f, %.3f, %.3f & %.3f\"%(x1B,x2B,x3B,x4B)\n", + "\n", + "D=D1+B1#\n", + "x1D=(.35*D1 + .16*B1)/D#\n", + "x2D=(.54*D1 + .42*B1)/D#\n", + "x3D=(.04*D1 + .24*B1)/D#\n", + "x4D=(.07*D1 + .18*B1)/D#\n", + "print \"the composition of stream D is\",x1D,x2D,x3D,x4D" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa1.5 Page 11" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of x1,x2,x3 respectively are\n", + "3\n", + "4\n", + "5\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "xnew=[];e=[]\n", + "for i in range(0,3):\n", + " xnew.append(2)\n", + " e.append(1)\n", + "\n", + "x=1e-6\n", + "while e[0]>x and e[1]>x and e[2]>x:\n", + " xold=[]\n", + " for i in range(0,3):\n", + " xold.append(xnew[i])\n", + " \n", + " xnew[0]=(44-xold[1]-2*xold[2])/10\n", + " xnew[1]=(-2*xnew[0]+51-xold[2])/10\n", + " xnew[2]=(-2*xnew[1]-xnew[0]+61)/10\n", + " e=[]\n", + " for i in range(0,3):\n", + " e.append(abs(xnew[i]-xold[i]))\n", + " \n", + "print \"the values of x1,x2,x3 respectively are\"\n", + "for i in range(0,3):\n", + " print '%.f'%xnew[i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa1.6 Page 11" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of x1,x2,x3 respectively : \n", + "3\n", + "-2\n", + "-1\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "xnew=[];e=[];\n", + "for i in range(0,3):\n", + " xnew.append(2)\n", + " e.append(1)\n", + "\n", + "x=1e-6\n", + "while e[0]>x and e[1]>x and e[2]>x:\n", + " xold=[]\n", + " for i in range(0,3):\n", + " xold.append(xnew[i])\n", + " \n", + " xnew[0]=(9-xold[1]+2*xold[2])/3\n", + " xnew[1]=(xnew[0]-8+3*xold[2])/4\n", + " xnew[2]=(xnew[1]-xnew[0]+1)/4\n", + " e=[]\n", + " for i in range(0,3):\n", + " e.append(abs(xnew[i]-xold[i]))\n", + " \n", + "print \"the values of x1,x2,x3 respectively : \"\n", + "for i in range(0,3):\n", + " print '%.f'%xnew[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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter10.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter10.ipynb new file mode 100644 index 00000000..0a942254 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter10.ipynb @@ -0,0 +1,567 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 10 - Two-Dimensional Steady & Transient Heat Conduction" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa10.1 Page 195" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of T from 1st element to last is:\n", + "\n", + "47.142854591 \t91.2499974482 \t182.857141581 \t57.3214260196 \t114.999997448 \t220.178570153 \t47.1428558669 \t91.2499987241 \t182.857142219 \t" + ] + } + ], + "source": [ + "from __future__ import division\n", + "tnew=[]\n", + "e=[]\n", + "for i in range(1,10):\n", + " tnew.append(101)\n", + " e.append(1) #assumed values\n", + "\n", + "t=1e-6\n", + "#since all the nodes are interior nodes so discretized eqn used is eqn 10.10\n", + "while e[0]>t and e[1]>t and e[2]>t and e[3]>t and e[4]>t and e[5]>t and e[6]>t and e[7]>t and e[8]>t:\n", + " told=[]\n", + " for i in range(1,10):\n", + " told.append(tnew[i-1])\n", + " tnew[0]=(told[1]+40+told[3])/4 #on solving eqns for various nodes we get,\n", + " tnew[1]=(tnew[0]+told[2]+told[4]+20)/4\n", + " tnew[2]=(tnew[1]+told[5]+420)/4\n", + " tnew[3]=(told[4]+tnew[0]+told[6]+20)/4\n", + " tnew[4]=(tnew[1]+told[7]+told[5]+tnew[3])/4\n", + " tnew[5]=(tnew[2]+tnew[4]+told[8]+400)/4\n", + " tnew[6]=(tnew[3]+told[7]+40)/4\n", + " tnew[7]=(tnew[4]+tnew[6]+told[8]+20)/4\n", + " tnew[8]=(tnew[5]+420+tnew[7])/4\n", + " e=[]\n", + " for i in range(1,10):\n", + " e.append(abs(tnew[i-1]-told[i-1]))\n", + " \n", + "\n", + "print \"the values of T from 1st element to last is:\\n\"\n", + "for i in range(1,10):\n", + " print tnew[i-1],'\\t'," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa10.2 Page 198" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of T from 1st element to last is:\n", + "\n", + "145.833332213 \t141.666666106 \t120.833333053 \t141.666666527 \t145.833333263 \t" + ] + } + ], + "source": [ + "from __future__ import division\n", + "tnew=[]\n", + "e=[]\n", + "for i in range(1,6):\n", + " tnew.append(101)\n", + " e.append(1)\n", + "\n", + "t=1e-6\n", + "#since there is no source term so we get the following eqns.\n", + "while e[0]>t and e[1]>t and e[2]>t and e[3]>t and e[4]>t:\n", + " told=[]\n", + " for i in range(1,6):\n", + " told.append(tnew[i-1])\n", + " \n", + " tnew[0]=(told[1]*2+300)/4\n", + " tnew[1]=(tnew[0]+told[2]+300)/4\n", + " tnew[2]=(tnew[1]+told[3]+200)/4\n", + " tnew[3]=(told[4]+tnew[2]+300)/4\n", + " tnew[4]=(2*tnew[3]+300)/4\n", + " \n", + " for i in range(1,6):\n", + " e[i-1]=(abs(tnew[0]-told[i-1]))\n", + " \n", + "\n", + "print \"the values of T from 1st element to last is:\\n\"\n", + "for i in range(1,6):\n", + " print tnew[i-1],'\\t'," + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa10.3 Page 201" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of RED points respectively : 47.1429, 47.1429, 115.0000, 91.2500 & 47.1429\n", + "the value of BLUE points respectively : 91.2500, 220.1786, 57.3214 & 91.2500\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "tn=zeros([5,5])\n", + "for j in range(1,6):\n", + " tn[j-1,0]=400 #defining conditions\n", + "\n", + "for j in range(2,5):\n", + " tn[0,j-1]=20\n", + " tn[4,j-1]=20\n", + " tn[j-1,4]=20\n", + "\n", + "e=[] \n", + "for i in range(1,10):\n", + " e.append(1)\n", + "\n", + "for i in range(2,5):\n", + " tn[i-1,1:4]=60\n", + "\n", + "\n", + "t1=1e-6\n", + "t=zeros([4,4])\n", + "while e[0]>t1 and e[1]>t1 and e[2]>t1 and e[3]>t1 and e[4]>t1 and e[5]>t1 and e[6]>t1 and e[7]>t1 and e[8]>t1:\n", + " for i in range(1,4):\n", + " for j in range(1,4):\n", + " t[i,j]=tn[i,j]\n", + " \n", + " #using red-black gauss-seidel method\n", + " for i in range(1,4):\n", + " for j in range(1,4):\n", + " tn[i,j]=(tn[i+1,j]+tn[i-1,j]+tn[i,j+1]+tn[i,j-1])/4\n", + " #now getting the absolute difference of the 9 variables\n", + " e[0]=abs(t[1,1]-tn[1,1])\n", + " e[1]=abs(t[1,2]-tn[1,2])\n", + " e[2]=abs(t[1,3]-tn[1,3])\n", + " e[3]=abs(t[2,1]-tn[2,1])\n", + " e[4]=abs(t[2,2]-tn[2,2])\n", + " e[5]=abs(t[2,3]-tn[2,3])\n", + " e[6]=abs(t[3,1]-tn[3,1])\n", + " e[7]=abs(t[3,2]-tn[3,2])\n", + " e[8]=abs(t[3,3]-tn[3,3])\n", + "\n", + "#now defining positions of the various nodes according to red black combination\n", + "R1=t[1,3]\n", + "R2=t[3,3]\n", + "R3=t[2,2]\n", + "R4=t[1,2]\n", + "R5=t[1,3]\n", + "B1=t[3,2]\n", + "B2=t[2,1]\n", + "B3=t[2,3]\n", + "B4=t[1,2]\n", + "print \"the value of RED points respectively : %.4f, %.4f, %.4f, %.4f & %.4f\"%(R1,R2,R3,R4,R5)\n", + "\n", + "print \"the value of BLUE points respectively : %.4f, %.4f, %.4f & %.4f\"%(B1, B2, B3, B4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa10.8 Page 202" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of T from 1st element to last is\n", + "157.831321254\n", + "192.469876146\n", + "280.72288988\n", + "184.939753978\n", + "231.325296989\n", + "330.421684639\n", + "175.903610664\n", + "217.469876356\n", + "309.638552636\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "tnew=[0];told=[0];e=[0];\n", + "for i in range(1,10):\n", + " tnew.append(101)\n", + " told.append(0)\n", + " e.append(1) #assumed values\n", + "\n", + "t=1e-6\n", + "while e[(1)]>t and e[(2)]>t and e[(3)]>t and e[(4)]>t and e[(5)]>t and e[(6)]>t and e[(7)]>t and e[(8)]>t and e[(9)]>t:\n", + " for i in range(1,10):\n", + " told[i]=tnew[(i)]\n", + " #using eqn 10.10 for the interior nodes and convective boundary conditions for corner nodes\n", + " tnew[(1)]=(told[(2)]+50+.5*told[(4)]+100/3)*3/7\n", + " tnew[(2)]=(tnew[(1)]+told[(3)]+told[(5)]+100)/4\n", + " tnew[(3)]=(tnew[(2)]+told[(6)]+600)/4\n", + " tnew[(4)]=(told[(5)]+.5*tnew[(1)]+.5*told[(7)]+100/3)*3/7\n", + " tnew[(5)]=(tnew[(2)]+told[(8)]+told[(6)]+tnew[(4)])/4\n", + " tnew[(6)]=(tnew[(3)]+tnew[(5)]+told[(9)]+500)/4\n", + " tnew[(7)]=(.5*tnew[(4)]+.5*told[(8)]+100/3)*3/4\n", + " tnew[(8)]=(tnew[(5)]+.5*tnew[(7)]+.5*told[(9)]+100/3)*3/7\n", + " tnew[(9)]=(tnew[(6)]+100/3+.5*tnew[(8)]+250)*3/7\n", + " for i in range(1,10):\n", + " e[i]=abs(tnew[i]-told[i])\n", + " \n", + "\n", + "print \"the values of T from 1st element to last is\"\n", + "for i in range(1,10):\n", + " print tnew[i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa10.9 Page 211" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of T from 1st element to last is\n", + "83.6250164077\n", + "83.3426002934\n", + "81.8505046198\n", + "86.8385228347\n", + "86.864496399\n", + "86.0434332286\n", + "86.7854379748\n", + "87.2768602399\n", + "88.5496879219\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "tnew=[0];told=[0];e=[0];\n", + "for i in range(1,10):\n", + " tnew.append(101)\n", + " told.append(0)\n", + " e.append(1) #assumed values\n", + "\n", + "t=1e-6\n", + "while e[(1)]>t and e[(2)]>t and e[(3)]>t and e[(4)]>t and e[(5)]>t and e[(6)]>t and e[(7)]>t and e[(8)]>t and e[(9)]>t:\n", + " for i in range(1,10):\n", + " told[(i)]=tnew[(i)]\n", + " #using the basic discretization eqn. for all the nodes since the boundary conditions vary for each point\n", + " tnew[(1)]=(told[(2)]+1.25+told[(4)])/2.05\n", + " tnew[(2)]=(.5*tnew[(1)]+.5*told[(3)]+told[(5)]+1.25)/2.05\n", + " tnew[(3)]=(.5*tnew[(2)]+.5*told[(6)]+1.25)/1.05\n", + " tnew[(4)]=(told[(5)]+.5*tnew[(1)]+45)/2\n", + " tnew[(5)]=(tnew[(2)]+told[(8)]+90+tnew[(4)])/4\n", + " tnew[(6)]=(.5*tnew[(3)]+tnew[(5)]+.5*told[(7)]+91.25)/3.05\n", + " tnew[(7)]=(.5*tnew[(6)]+.5*told[(8)]+91.25)/2.05\n", + " tnew[(8)]=(91.25+.5*tnew[(7)]+.5*told[(9)])/2.05\n", + " tnew[(9)]=(47.125+.5*tnew[(8)])/1.025\n", + " for i in range(1,10):\n", + " e[i]=abs(tnew[i]-told[i])\n", + " \n", + "\n", + "print \"the values of T from 1st element to last is\"\n", + "for i in range(1,10):\n", + " print told[i]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa10.10 Page 213" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the soln of eg 10.10-->Alternating Direction Implicit Method\n", + "the soln by ADI method is\n", + "20.0 20.0 20.0\n", + "--------------\n", + "20.0 20.0 20.0\n", + "--------------\n", + "48.1904761905 43.6666666667 105.0\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "print \"the soln of eg 10.10-->Alternating Direction Implicit Method\"\n", + "nmax=25\n", + "a=[0,1,1] #defining variables\n", + "b=[-4,-4,-4]\n", + "c=[1,1]\n", + "t=zeros([6,6])\n", + "tstar=zeros([6,6])\n", + "t[1,2]=20 ; t[1,3]=20 ; t[1,4]=20; t[2,1]=20; t[3,1]=20 ; t[4,1]=20 ; t[5,2]=20 ; t[5,3]=20 ; t[5,4]=20 ; t[2,5]=400; t[3,5]=400; t[4,5]=400\n", + "tstar[1,2]=20 ; tstar[1,3]=20; tstar[1,4]=20 ; tstar[2,1]=20 ; tstar[3,1]=20 ; tstar[4,1]=20 ; tstar[5,2]=20 ; tstar[5,3]=20 ; tstar[5,4]=20 ; tstar[2,5]=400 ; tstar[3,5]=400 ; tstar[4,5]=400\n", + "for i in range(2,5):\n", + " for j in range(2,5):\n", + " t[i,j]=20\n", + " \n", + "\n", + "#solving by TDMA Method\n", + "d=zeros(4)\n", + "for nn in range(1,nmax+1):\n", + " for jj in range(2,5):\n", + " d[(1)]=-t[1,jj]-t[2,jj+1]-tstar[2,jj-1]\n", + " d[(2)]=-t[3,jj+1]-tstar[3,jj-1]\n", + " d[(3)]=-t[5,jj]-t[4,jj+1]-tstar[4,jj-1]\n", + " i=1 ; n=3\n", + " Beta=[0,b[i]]\n", + " Gamma=[0,d[i]/Beta[i]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[(j-1)]-a[(j-1)]*c[(j-2)]/Beta[(j-1)])\n", + " Gamma.append((d[(j)]-a[(j-1)]*Gamma[(j-1)])/Beta[(j)])\n", + " #end \n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[(j)]-c[(j-1)]*x[j-1]/Beta[j]\n", + " #end\n", + " tstar[2,jj]=x[0]\n", + " tstar[3,jj]=x[1]\n", + " tstar[4,jj]=x[2]\n", + "#end\n", + " for ii in range(2,5):\n", + " d[(1)]=-t[ii,1]-tstar[ii+1,2]-tstar[ii-1,2]\n", + " d[(2)]=-tstar[ii+1,3]-tstar[ii-1,3]\n", + " d[(3)]=-t[ii,5]-tstar[ii+1,4]-tstar[ii-1,4]\n", + " i=1 ; n=3\n", + " Beta[(i)]=b[i]\n", + " Gamma[i]=d[(i)]/Beta[(i)]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta[(j)]=b[(j-1)]-a[(j-1)]*c[j-2]/Beta[(j-1)]\n", + " Gamma[(j)]=(d[(j)]-a[(j-1)]*Gamma[(j-1)])/Beta[(j)]\n", + " #end \n", + " \n", + " x[-1]=Gamma[(n)]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j]=Gamma[(j)]-c[(j-1)]*x[(j)]/Beta[(j)]\n", + " #end\n", + " t[ii,2]=x[0]\n", + " t[ii,3]=x[1]\n", + " t[ii,4]=x[2]\n", + "\n", + "\n", + "print \"the soln by ADI method is\"\n", + "print t[2,4],t[2,3],t[2,2]\n", + "print \"--------------\"\n", + "print t[3,4],t[3,3],t[3,2]\n", + "print \"--------------\"\n", + "print t[4,4],t[4,3],t[4,2]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 10.11 Page 215" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the soln by ADI is\n", + "1.58563151796\n", + "1.90275782155\n", + "2.98098725376\n", + "5.25161158747\n", + "9.62288055617\n", + "17.8433017473\n", + "33.2010436374\n", + "61.8392029825\n", + "945.175268307\n", + "-467.149084346\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,zeros\n", + "a=[0,0];b=[0,0];c=[0,0]\n", + "for k in range(2,11):\n", + " a.append(-1)\n", + " b.append(2.4)\n", + " c.append(-1)\n", + "\n", + "alpha=1 ; delta_t=.05 ; delta_x=.1\n", + "m=alpha*delta_t/delta_x**2\n", + "b[1]=2.4\n", + "c[1]=-2\n", + "t=zeros([12,12])\n", + "tstar=zeros([12,12])\n", + "\n", + "for k in range(1,12):\n", + " t[11,k]=400 ; tstar[11,k]=400 ; t[k,11]=400 ; tstar[k,11]=400\n", + "\n", + "\n", + "for i in range(1,11):\n", + " for j in range(1,11):\n", + " t[i,j]=0\n", + " tstar[i,j]=0\n", + " \n", + "d=zeros(11)\n", + "for tm in arange(.05,5+.05,.05):\n", + " for jj in range(1,11):\n", + " if jj==1:\n", + " for ii in range(1,11):\n", + " d[(ii)]=2*t[ii,2]-1.6*t[ii,1]\n", + " d[(10)]=d[(10)]+400\n", + " else:\n", + " for ii in range(1,11):\n", + " d[(ii)]=t[ii,jj+1]+t[ii,jj-1]-1.6*t[ii,jj]\n", + " d[(10)]=d[(10)]+400\n", + " i=1 ; n=10\n", + " Beta=[0,b[i]]\n", + " Gamma=[0,d[i]/Beta[i]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[(j)]-a[(j)]*c[(j-1)]/Beta[(j-1)])\n", + " Gamma.append((d[(j)]-a[(j)]*Gamma[(j-1)])/Beta[(j)])\n", + " \n", + " x=zeros(n+1)\n", + " x[(n)]=Gamma[(n)] \n", + " x[(j)]=Gamma[(j)]-c[(j)]*x[(j)]/Beta[(j)]\n", + " for count in range(1,11):\n", + " tstar[count,jj]=x[(count)]\n", + " \n", + " for ii in range(1,11):\n", + " if ii==1:\n", + " for jj in range(1,11):\n", + " d[(jj)]=2*tstar[ii+1,1]-1.6*tstar[ii,1]\n", + " d[(10)]=d[(10)]+400\n", + " else:\n", + " for jj in range(1,11):\n", + " d[(jj)]=tstar[ii-1,jj]+tstar[ii+1,jj]-1.6*tstar[ii,jj]\n", + " d[(10)]=d[(10)]+400\n", + " \n", + " i=1 ; n=10\n", + " Beta[(i)]=b[i]\n", + " Gamma[(i)]=d[(i)]/Beta[(i)]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta[(j)]=b[(j)]-a[(j)]*c[(j-1)]/Beta[(j-1)]\n", + " Gamma[(j)]=(d[(j)]-a[(j)]*Gamma[(j-1)])/Beta[(j)]\n", + " \n", + " x[(n)]=Gamma[(n)]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j =n-k\n", + " x[(j)]=Gamma[(j)]-c[(j)]*x[(j+1)]/Beta[(j)]\n", + " \n", + " for count in range(1,11):\n", + " t[ii,count]=x[count]\n", + " \n", + "\n", + "print \"the soln by ADI is\"\n", + "for i in range(1,11):\n", + " print t[i,i]\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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter2.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter2.ipynb new file mode 100644 index 00000000..5c7b4ceb --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter2.ipynb @@ -0,0 +1,343 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 2 - Nonlinear Algebraic Equations" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 2.1 Page 20" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the root of the eqn is 0.20165449273\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "\n", + "x=.5 #initial value\n", + "xnew=0\n", + "e=1\n", + "while e>10**-4:\n", + " x=xnew\n", + " def Fa(x):\n", + " y=x**3-5*x+1# #defining fn \n", + " return y\n", + "\n", + " der=derivative(Fa,x) #differentiating the fn\n", + " xnew=x-Fa(x)/der\n", + " e=abs(xnew-x)\n", + " \n", + "print \"the root of the eqn is\",xnew" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 2.2 Page 20" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the Reynolds no. is 13743.0167598\n", + "the fanning friction factor is 0.0290420879897407\n", + "the pressure drop in pascals is 11163.0525710566\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "from sympy import symbols, sqrt,log\n", + "ff=symbols('ff')\n", + "meu=1.79*10**-5\n", + "rough=.0000015 #roughness\n", + "dia=.004\n", + "e_by_D=rough/dia\n", + "rho=1.23\n", + "v=50 #velocity of air\n", + "l=1\n", + "Re=(rho*v*dia)/meu #Reynold's number\n", + "ffnew=0.01\n", + "e=1\n", + "t1=e_by_D/3.7 #term 1 of eqn.\n", + "t2=2.51/Re #term 2 of eqn.\n", + "print \"the Reynolds no. is\",Re\n", + "\n", + "\n", + "while e>1e-6:\n", + " fff=ffnew\n", + " ff=symbols('ff')\n", + " t3=sqrt(ff)\n", + " y=1/t3+2*log(t1+t2/t3)/2.3\n", + "\n", + " fdash=y.diff().subs(ff,fff)# #f'(ff)\n", + " ffnew=fff-y.subs(ff,fff)/fdash#\n", + " e=abs(fff-ffnew)\n", + "\n", + "print \"the fanning friction factor is\",fff\n", + "delta_p=(fff*l*v**2*rho)/(2*dia) #pressure drop\n", + "print \"the pressure drop in pascals is\",delta_p" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 2.3 Page 23" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the minimum fluidisation velocity in m/s is 0.00502529644298\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "from math import log,sqrt\n", + "\n", + "P=2*101325 #given data\n", + "T=298.15\n", + "M=28.97*10**-3\n", + "R=8.314\n", + "rho=(P*M)/(R*T)\n", + "rho_p=1000\n", + "dia=1.2*10**-4\n", + "ep=.42 #void fraction\n", + "sph=.88\n", + "meu=1.845*10**-5\n", + "t1=1.75*rho*(1-ep)/(sph*dia*ep**3) #these are the terms of the function.\n", + "t2=150*meu*(1-ep)**2/(sph**2*dia**2*ep**3)\n", + "t3=(1-ep)*(rho_p-rho)*9.8\n", + "vnew=0.1\n", + "e1=1\n", + "while e1>1e-6:\n", + " v=vnew\n", + " def Fb(v):\n", + " y=t1*v**2+t2*v-t3 #defining fn \n", + " return y\n", + " vdash=derivative(Fb,v) #differentiating the fn\n", + " vnew=v-Fb(v)/vdash\n", + " e1=abs(vnew-v)\n", + "\n", + "print \"the minimum fluidisation velocity in m/s is\",v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 2.4 Page 25" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the terminal velocity in m/s is 6.52652883498\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "from math import log,sqrt\n", + "\n", + "dia=2*10**-3\n", + "P=101325 #given data\n", + "T=298.15\n", + "M=28.89*10**-3\n", + "R=8.314\n", + "rho=(P*M)/(R*T)\n", + "rho_oil=900\n", + "meu=1.85*10**-5\n", + "Re_oil_by_v=rho*dia/meu\n", + "vnew=0.1\n", + "e=1\n", + "while e>1e-6:\n", + " v=vnew\n", + " Re_oil=Re_oil_by_v*v \n", + " Cd=24*(1+.15*Re_oil**.687)/Re_oil\n", + " vnew=sqrt(4*(rho_oil-rho)*9.81*dia/(3*Cd*rho))\n", + " e=abs(vnew-v)\n", + "\n", + "print \"the terminal velocity in m/s is\",v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 2.5 Page 27" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of x and y respectively are -3.2443635355e-08 0.999999956342\n", + "such small value of x can be considered as zero.\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "from math import log,sqrt,exp,sin,cos\n", + "\n", + "xnew=0.1\n", + "ynew=0.5\n", + "e1=1\n", + "e2=1\n", + "while e1>1e-6 and e2>1e-6:\n", + " x=xnew\n", + " y=ynew\n", + " y1=exp(x)+x*y-1\n", + " d_fx=exp(x)+y\n", + " d_fy=x\n", + " y2=sin(x*y)+x+y-1\n", + " d_gx=y*cos(x*y)+1\n", + " d_gy=x*cos(x*y)+1\n", + " t1=(y2*d_fy)\n", + " t2=(y1*d_gy)\n", + " D1=d_fx*d_gy-d_fy*d_gx\n", + " delta_x=(t1-t2)/D1\n", + " t3=(y1*d_gx)\n", + " t4=(y2*d_fx)\n", + " delta_y=(t3-t4)/D1\n", + " xnew=x+delta_x\n", + " ynew=y+delta_y\n", + " e1=abs(x-xnew)\n", + " e2=abs(y-ynew)\n", + "\n", + "print \"the values of x and y respectively are\",x,y\n", + "print \"such small value of x can be considered as zero.\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 2.6 Page 28" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of x and y are respectively 3.0 4.00000000002\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy.misc import derivative\n", + "from math import log,sqrt\n", + "\n", + "xnew=0.1\n", + "ynew=0.5\n", + "e1=1\n", + "e2=1\n", + "while e1>10**-6 and e2>10**-6:\n", + " x=xnew\n", + " y=ynew\n", + " y1=3*x**3+4*y**2-145\n", + " d_fx=9*x**2\n", + " d_fy=8*y\n", + " y2=4*x**2-y**3+28\n", + " d_gx=8*x\n", + " d_gy=-3*y**2\n", + " D2=d_fx*d_gy-d_gx*d_fy\n", + " delta_x=(y2*d_fy-y1*d_gy)/D2\n", + " delta_y=(y1*d_gx-y2*d_fx)/D2\n", + " xnew=x+delta_x\n", + " ynew=y+delta_y\n", + " e1=abs(xnew-x)\n", + " e2=abs(ynew-y)\n", + "\n", + "print \"the values of x and y are respectively\",x,y" + ] + } + ], + "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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter3.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter3.ipynb new file mode 100644 index 00000000..ab7a3ef0 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter3.ipynb @@ -0,0 +1,810 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 3 - Chemical Engineering Thermodynamics" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.1 Page 32" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "all values in m3/mol\n", + "the soln by virial gas eqn. of volume in m3/mol by Z(T,P) is vold\n", + "the soln by virial gas eqn. of volume in m3/mol by Z(T,V) is 0.0302510618121734\n", + "the volume of saturated liq. and saturated vapour by peng-robinson method respectively is\n", + "0.0306180024673 2.2509412835e-05\n", + "the vol of saturated liq. and vapour by redlich kwong method respectively are\n", + "2.62463386857767e-5 2.64047733063277e-5\n", + "the vol of saturated liq. and vapour by vander waal method respectively are\n", + "0.0304707748423797 3.90181676996140e-5\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from sympy import symbols\n", + "vold=symbols('vold')\n", + "#from scipy.misc import derivative\n", + "print \"all values in m3/mol\"\n", + "T=373.15\n", + "P=101325\n", + "Tc=647.1\n", + "Pc=220.55*10**5\n", + "w=.345\n", + "R=8.314\n", + "Tr=T/Tc # reduced temperature\n", + "Pr=P/Pc #reduced pressure \n", + "b0=.083-.422*Tr**-1.6\n", + "b1=.139-.172*Tr**-4.2\n", + "B=(b0+w*b1)*R*Tc/Pc\n", + "vnew=1\n", + "e1=1\n", + "vold_=R*T/P+B\n", + "print \"the soln by virial gas eqn. of volume in m3/mol by Z(T,P) is\",vold\n", + "while e1>1e-6:\n", + " vold_=vnew\n", + " #def Fh(vold):\n", + " y=P*vold/(R*T)-1-B/vold\n", + " # return y\n", + " #ydash=derivative(Fh,vold)#\n", + " ydash=y.diff().subs(vold,vold_)\n", + " #vnew=vold-Fh(vold)/ydash#\n", + " vnew=vold_-y.subs(vold,vold_)/ydash\n", + " e1=abs(vold_-vnew)\n", + "\n", + "print \"the soln by virial gas eqn. of volume in m3/mol by Z(T,V) is\",vold_\n", + "#by peng robinson method\n", + "k=.37464+1.54226*w-.26992*w**2\n", + "s=1+k*(1-Tr**.5)\n", + "lpha=s**2\n", + "a=.45724*R**2*Tc**2*lpha/Pc\n", + "b=.0778*R*Tc/Pc\n", + "vnew=b\n", + "e2=1 \n", + "vol=b\n", + "fe=0\n", + "fd=0\n", + "print \"the volume of saturated liq. and saturated vapour by peng-robinson method respectively is\"\n", + "for i in range(0,3):\n", + " vol=vnew\n", + " y2=vol**3*P+vol**2*(P*b-R*T)-vol*(3*P*b**2+2*b*R*T-a)+P*b**3+b**2*R*T-a*b\n", + " ydash2=3*P*vol**2+(P*b-R*T)*2*vol-(3*P*b**2+2*b*R*T-a)\n", + " vnew=vol-y2/ydash2\n", + " e2=abs(vol-vnew)\n", + " if i==1 and e2<1e-6:\n", + " fd=vnew\n", + " vnew=R*T/P\n", + "\n", + "\n", + "print vol,fd\n", + "\n", + "#by redlich-kwong method\n", + "i=0\n", + "a=.42748*R**2*Tc**2.5/Pc\n", + "b=.08664*R*Tc/Pc\n", + "Vnew=b ; e3=1\n", + "print \"the vol of saturated liq. and vapour by redlich kwong method respectively are\"\n", + "\n", + "from math import sqrt\n", + "VV=symbols('VV')\n", + "for i in range(0,3):\n", + " V=Vnew\n", + " y3=VV**3*P-R*T*VV**2-VV*(P*b**2+b*R*T-a/sqrt(T))-a*b/sqrt(T)\n", + " deriv=y3.diff().subs(VV,V)\n", + " Vnew=V-y3.subs(VV,V)/deriv\n", + " e3=abs(Vnew-V)\n", + " if i==1 and e3<1e-6:\n", + " de=Vnew\n", + " Vnew=R*T/P #for saturated liq.\n", + " \n", + " print V,de\n", + "#vander waals method\n", + "i=0\n", + "a=27*R**2*Tc**2/(64*Pc)\n", + "b=R*Tc/(8*Pc)\n", + "vnew=b; v=b ; e=1\n", + "vv=symbols('vv')\n", + "for i in range(0,3):\n", + " v=vnew\n", + " v3=vv**3*P-vv**2*(P*b+R*T)+a*vv-a*b\n", + " deriva=v3.diff().subs(vv,v)\n", + " vnew=v-v3.subs(vv,v)/deriva\n", + " e4=abs(v-vnew)\n", + " if i==1 and e4<10**-6:\n", + " sol=vnew\n", + " vnew=R*T/P\n", + " \n", + "\n", + "print \"the vol of saturated liq. and vapour by vander waal method respectively are\"\n", + "print vnew,sol" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.2 Page 33" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the bubble point temp. in Celsius is 71.8054048538555\n", + "the dew point temp. in Celsius is 87.0799975600241\n" + ] + } + ], + "source": [ + "from sympy import symbols,log,exp\n", + "z1=.5 ; P=101.325 #given data\n", + "a1=14.3916 ; b1=2795.32 ;c1=230.002\n", + "a2=16.262 ; b2=3799.887 ;c2=226.346\n", + "x1=z1 ; x2=1-z1\n", + "T1sat=b1/(a1-log(P))-c1\n", + "T2sat=b2/(a2-log(P))-c2\n", + "Told_=273 ; e=1\n", + "Tnew=x1*T1sat+x2*T2sat\n", + "Told = symbols('Told')\n", + "while e>1e-6:\n", + " Told_=Tnew\n", + " \n", + " P1sat=exp(a1-b1/(Told+c1))\n", + " P2sat=exp(a2-b2/(Told+c2))\n", + " y1=P-x1*P1sat-x2*P2sat\n", + " \n", + " ydashd=y1.diff().subs(Told,Told_)\n", + " Tnew=Told_-y1.subs(Told,Told_)/ydashd\n", + " e=abs(Told_-Tnew)\n", + " \n", + "print \"the bubble point temp. in Celsius is\",Tnew\n", + "\n", + " #calc of dew point\n", + "y1=z1 ; y2=1-z1 ; e=1\n", + "Tnew=y1*T1sat+y2*T2sat\n", + "Told = symbols('Told')\n", + "while e>1e-6:\n", + " Told_=Tnew\n", + " P1sat=exp(a1-b1/(Told+c1))\n", + " P2sat=exp(a2-b2/(Told+c2))\n", + " y11=1/P-y1/P1sat-y2/P2sat\n", + " \n", + " ydashd=y11.diff().subs(Told,Told_)\n", + " Tnew=Told_-y11.subs(Told,Told_)/ydashd\n", + " e=abs(Told_-Tnew)\n", + " \n", + "print \"the dew point temp. in Celsius is\",Tnew" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.3 Page 33" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the bubble point pressure and dew point pressure respectively are 108.205 79.6944627367\n", + "mol frctn of acetone in liq. phase is 0.226211512882\n", + "mol frctn of acetone in vapour phase is 0.442809036467\n", + "mol frctn of acetonitrile in liq. phase is 0.30222391249\n", + "mol frctn of acetonitrile in vapour. phase is 0.29569587598\n", + "mol frctn of nitromethane in liq. phase is 0.481489923277\n", + "mol frctn of nitromethane in vapour phase is 0.242285729393\n" + ] + } + ], + "source": [ + "from sympy import symbols,log,exp\n", + "from numpy import zeros\n", + "psat=[0,195.75,97.84,50.32] #given data\n", + "z=[0,.3,.3,.4]\n", + "bpp=z[(1)]*psat[(1)]+z[(2)]*psat[(2)]+z[(3)]*psat[(3)] #Bubble point pressure\n", + "dpp=1/(z[(1)]/psat[(1)]+z[(2)]/psat[(2)]+z[(3)]/psat[(3)]) #dew point pressure\n", + "print \"the bubble point pressure and dew point pressure respectively are\",bpp,dpp\n", + "P=100 ; v=1 ; vnew=1 ; e=1 ; y2=0 ; der=0 #given pressure is between BPP & DPP\n", + "k=zeros(5)\n", + "for i in range(1,4): \n", + " k[(i)]=psat[(i)]/P\n", + "\n", + "while e>1e-6:\n", + " v=vnew\n", + " for i in range(1,4):\n", + " t1=(1-v+v*k[(i)])\n", + " y2=y2+z[(i)]*(k[(i)]-1)/t1\n", + " der=der-z[(i)]*(k[(i)]-1)**2/t1**2\n", + " \n", + " vnew=v-y2/der\n", + " e=abs(vnew-v)\n", + "x=zeros(5)\n", + "y=zeros(5)\n", + "for i in range(1,4):\n", + " x[(i)]=z[(i)]/(1-v+v*k[(i)])\n", + " y[i]=x[i]*k[i] \n", + " \n", + "print \"mol frctn of acetone in liq. phase is\",x[(1)]\n", + "print \"mol frctn of acetone in vapour phase is\",y[(1)]\n", + "print \"mol frctn of acetonitrile in liq. phase is\",x[(2)]\n", + "print \"mol frctn of acetonitrile in vapour. phase is\",y[(2)]\n", + "print \"mol frctn of nitromethane in liq. phase is\",x[(3)]\n", + "print \"mol frctn of nitromethane in vapour phase is\",y[(3)]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.4 Page 35" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "boiling point pressure in kPa is 204.264012744\n", + "boiling point temperature in Celsius is 81.4675225814\n", + "dew point pressure in kPa is 184.104082046\n", + "dew point temperature in Celsius is 84.0803584712\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import exp,log\n", + "a12=437.98*4.186\n", + "a21=1238*4.186\n", + "v1=76.92\n", + "v2=18.07 #calc of BPP\n", + "t=100\n", + "x1=.5 ; R=8.314\n", + "a1=16.678 ; b1=3640.2 ; c1=219.61\n", + "a2=16.2887 ; b2=3816.44 ; c2=227.02\n", + "x2=1-x1\n", + "p1sat=exp(a1-b1/(c1+t))\n", + "p2sat=exp(a2-b2/(c2+t))\n", + "h12=v2*exp(-a12/(R*(t+273.15)))/v1\n", + "h21=v1*exp(-a21/(R*(t+273.15)))/v2\n", + "m=h12/(x1+x2*h12)-h21/(x2+x1*h21)\n", + "g1=exp(-log(x1+x2*h12)+x2*m)\n", + "g2=exp(-log(x2+x1*h21)-x1*m)\n", + "p=x1*g1*p1sat+x2*g2*p2sat\n", + "print \"boiling point pressure in kPa is\",p\n", + " #calc of BPT\n", + "p=101.325 ; x1=.5 ; e=1\n", + "x2=1-x1\n", + "t1sat=b1/(a1-log(p))-c1\n", + "t2sat=b2/(a2-log(p))-c2\n", + "tnew=x1*t1sat+x2*t2sat\n", + "while e>10**-4:\n", + " told=tnew\n", + " p1sat=exp(a1-b1/(c1+told))\n", + " p2sat=exp(a2-b2/(c2+told))\n", + " p1sat=p/(g1*x1+g2*x2*(p2sat/p1sat))\n", + " tnew=b1/(a1-log(p1sat))-c1\n", + " e=abs(tnew-told)\n", + "\n", + "print \"boiling point temperature in Celsius is\",tnew\n", + " #calc of dpp\n", + "e1=1 ; e2=1 ; e3=1 ; pold=1\n", + "t=100 ; y1=.5\n", + "y2=1-y1\n", + "p1sat=exp(a1-b1/(c1+t))\n", + "p2sat=exp(a2-b2/(c2+t))\n", + "g1=1 ; g2=1 ; g11=1 ; g22=1\n", + "pnew=1/(y1/(g1*p1sat)+y2/(g2*p2sat))\n", + "while e1>.0001:\n", + " pold=pnew\n", + " while e2>.0001 and e3>.0001:\n", + " g1=g11 ; g2=g22\n", + " x1=y1*pold/(g1*p1sat)\n", + " x2=y2*pold/(g2*p2sat)\n", + " x1=x1/(x1+x2)\n", + " x2=1-x1\n", + " h12=v2*exp(-a12/(R*(t+273.15)))/v1\n", + " h21=v1*exp(-a21/(R*(t+273.15)))/v2\n", + " m=h12/(x1+x2*h12)-h21/(x2+x1*h21)\n", + " g11=exp(-log(x1+x2*h12)+x2*m)\n", + " g22=exp(-log(x2+x1*h21)-x1*m)\n", + " e2=abs(g11-g1) ; e3=abs(g22-g2)\n", + " \n", + " pnew=1/(y1/(g1*p1sat)+y2/(g2*p2sat))\n", + " e1=abs(pnew-pold)\n", + "\n", + "print \"dew point pressure in kPa is\",pnew\n", + " #calc dpt\n", + "p=101.325 ; y1=.5 ; e4=1 ; e5=1 ; e6=1\n", + "y2=1-y1\n", + "t1sat=b1/(a1-log(p))-c1\n", + "t2sat=b2/(a2-log(p))-c2\n", + "tnew=y1*t1sat+y2*t2sat\n", + "g11=1 ; g22=1\n", + "while e4>.0001:\n", + " told=tnew\n", + " p1sat=exp(a1-b1/(c1+told))\n", + " p2sat=exp(a2-b2/(c2+told))\n", + " while e5>.0001 and e6>.0001:\n", + " g1=g11\n", + " g2=g22\n", + " x1=y1*p/(g1*p1sat)\n", + " x2=y2*p/(g2*p2sat)\n", + " x1=x1/(x1+x2)\n", + " x2=1-x1\n", + " h12=v2*exp(-a12/(R*(t+273.15)))/v1\n", + " h21=v1*exp(-a21/(R*(t+273.15)))/v2\n", + " m=h12/(x1+x2*h12)-h21/(x2+x1*h21)\n", + " g11=exp(-log(x1+x2*h12)+x2*m)\n", + " g22=exp(-log(x2+x1*h21)-x1*m)\n", + " e5=abs(g11-g1)\n", + " e6=abs(g22-g2)\n", + " \n", + " p1sat=p*(y1/g1+y2*p1sat/(g2*p2sat))\n", + " tnew=b1/(a1-log(p1sat))-c1\n", + " e4=abs(tnew-told)\n", + "\n", + "print \"dew point temperature in Celsius is\",tnew" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.5 Page 36" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the bubble point pressure is 310.299302687235\n", + "the dew point pressure is 143.432965325576\n", + "the no. of moles in vapour phase is 0.540556419677788\n", + "x1 and y1 respectively are 0.0283277058050475 1.88246875380055\n" + ] + } + ], + "source": [ + "from sympy import symbols,log,exp\n", + "from numpy import zeros\n", + "a12=292.66*4.18\n", + "a21=1445.26*4.18\n", + "v1=74.05*10**-6\n", + "v2=18.07*10**-6\n", + "R=8.314\n", + "t=100\n", + "z1=.3\n", + "z2=1-z1\n", + "a1=14.39155 ; a2=16.262 ; b1=2795.82 ; b2=3799.89 ; c1=230.002 ; c2=226.35\n", + "e1=1 ;e2=1 ;e3=1 ;e4=1 ;e5=1 ;e6=1 ;vnew=0\n", + " #calc of BPP\n", + "x1=z1; x2=z2\n", + "p1sat=exp(a1-(b1/(t+c1)))\n", + "p2sat=exp(a2-(b2/(t+c2)))\n", + "h12=v2*exp(-a12/(R*(t+273.15)))/v1\n", + "h21=v1*exp(-a21/(R*(t+273.15)))/v2\n", + "m=(h12/(x1+x2*h12))-(h21/(x2+x1*h21))\n", + "g1=exp(-log(x1+x2*h12)+x2*m)\n", + "g2=exp(-log(x2+x1*h21)-x1*m)\n", + "p=x1*g1*p1sat+x2*g2*p2sat\n", + "print\"the bubble point pressure is\",p\n", + "bpp=p ; gb1=g1 ; gb2=g2 #g1 & g2 are activity co-efficients\n", + " #calc of DPP\n", + "y1=z1 ; y2=z2\n", + "g1=1 ; g2=1\n", + "pnew=1/(y1/(g1*p1sat)+y2/(g2*p2sat))\n", + "g1n=g1 ; g2n=g2\n", + "while e1>.0001:\n", + " pold=pnew\n", + " while e2>.0001 and e3>.0001:\n", + " g1=g1n ; g2=g2n\n", + " x1=y1*pold/(g1*p1sat)\n", + " x2=y2*pold/(g2*p2sat)\n", + " x1=x1/(x1+x2)\n", + " x2=1-x1\n", + " g1n=exp(-log(x1+x2*h12)+x2*m)\n", + " g2n=exp(-log(x2+x1*h21)-x1*m)\n", + " e2=abs(g1n-g1) ; e3=abs(g2n-g2)\n", + "\n", + " pnew=1/(y1/(g1n*p1sat)+y2/(g2n*p2sat))\n", + " e1=abs(pnew-pold)\n", + "\n", + "print \"the dew point pressure is\",pnew\n", + "dpp=pnew ; gd1=g1n ; gd2=g2n\n", + "p=200\n", + "v=(bpp-p)/(bpp-dpp)\n", + "g1=((p-dpp)*(gb1-gd1))/(bpp-dpp)+gd1\n", + "g2=((p-dpp)*(gb2-gd2))/(bpp-dpp)+gd2\n", + "\n", + "#calc of distribution co-efficients\n", + "from sympy import symbols, exp as exp_, log as log_\n", + "\n", + "v=symbols('v')\n", + "while e4>.0001 and e5>.0001:\n", + " g1n=g1 ; g2n=g2\n", + " k1=g1n*p1sat/p\n", + " k2=g2n*p2sat/p\n", + " while e6>.00001:\n", + " vv=vnew\n", + " y1=(k1*z1)/(1-v+v*k1)\n", + " y2=(k2*z2)/(1-v+v*k2)\n", + " x1_=y1/k1\n", + " x2_=y2/k2 \n", + " f=y1-x1_+y2-x2_\n", + " derv=f.diff().subs(v,vv)\n", + " vnew=vv-f.subs(v,vv)/derv\n", + " e6=abs(vnew-vv)\n", + " \n", + " h12=v2*exp(-a12/(R*(t+273.15)))/v1\n", + " h21=v1*exp(-a21/(R*(t+273.15)))/v2\n", + " m=(h12/(x1+x2*h12))-(h21/(x2+x1*h21))\n", + " g1=exp_(-log_(x1+x2*h12)+x2*m)\n", + " g2=exp_(-log_(x2+x1*h21)-x1*m)\n", + " e4=abs(g1-g1n)\n", + " e5=abs(g2-g2n)\n", + "\n", + "print \"the no. of moles in vapour phase is\",vv\n", + "print \"x1 and y1 respectively are\",x1.subs(v,v1),y1.subs(v,v1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.6 Page 37" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the vapour pressure of water in Pa is 154846.968055\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/asif/.local/lib/python2.7/site-packages/ipykernel/__main__.py:42: RuntimeWarning: overflow encountered in exp\n", + "/home/asif/.local/lib/python2.7/site-packages/ipykernel/__main__.py:44: RuntimeWarning: invalid value encountered in double_scalars\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy import sqrt,log,exp\n", + "t=373.15 ; tc=647.1 ; pc=220.55*10**5 ; w=.345 ; R=8.314 #given\n", + "f1=1 ; e1=1 ; e2=1 ; vnew=1 ; pnew=1 #assumed values\n", + "k=.37464+1.54226*w-.26992*w*2\n", + "s=(1+k*(1-(t/tc)**.5))**2\n", + "a=.45724*R*R*tc*tc*s/pc\n", + "b=.0778*R*tc/pc\n", + "#calc of vol. of liq.\n", + "while f1>10**-4:\n", + " p=pnew ; vnew=b ; \n", + " t1=(p*b-R*t) #co-efficients of vol. in the eqn.\n", + " t2=3*p*b**2+2*b*R*t-a\n", + " t3=p*b**3+b**2*R*t-a*b\n", + " while e1>1e-6 and vnew>0:\n", + " vold=vnew\n", + " y1=vold**3*p+vold**2*t1-vold*t2+t3\n", + " der=3*vold**2*p+2*vold*t1-t2\n", + " vnew=vold-y1/der\n", + " e1=abs(vnew-vold)\n", + " \n", + " vliq=vold\n", + " #fugacity of liq.\n", + " zliq=p*vliq/(R*t)\n", + " c=(a/(2*1.414*b*R*t))*(log((vliq+(1+sqrt(2))*b)/(vliq+(1-sqrt(2))*b)))\n", + " t5=zliq-p*b/(R*t)\n", + " fl2=p*exp(zliq-1-log(t5)-c)\n", + " vvnew=R*t/p #assumed value close to the ideal value\n", + " #calc of vol. of vapour\n", + " while e2>1e-6:\n", + " vvold=vvnew\n", + " x2=vvold**3*p+vvold**2*t1-vvold*t2+t3\n", + " der1=3*vvold**2*p+2*vvold*t1-t2\n", + " vvnew=vvold-x2/der1\n", + " e2=abs(vvnew-vvold)\n", + " \n", + " #fugacity of vapour\n", + " vvap=vvold\n", + " zvap=p*vvap/(R*t)\n", + " d=(a/(2*sqrt(2)*b*R*t))*(log((zvap+(1+sqrt(2))*b*p/(R*t))/(zvap+(1-sqrt(2))*p*b/(R*t))))\n", + " t6=zvap-p*b/(R*t)\n", + " fv2=p*exp(zvap-1-log(t6)-d)\n", + " pnew=p*fl2/fv2 #updating the value of P\n", + " f1=abs((fl2-fv2)/fv2)\n", + "\n", + "print \"the vapour pressure of water in Pa is\",p\n", + "# Note value of fv2 is infinite & it is the reason for warning" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.7 Page 39" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the amt. of methanol in vapour phase and system pressure in Pa respectively are 0.981547559133 344637.196487\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy import sqrt,log,exp\n", + "et=1 ; er=1 ; sold=0 ; snew=0 #assumed values\n", + "R=8.314 ; t=100 ; x1=.958 ; a12=107.38*4.18 ; a21=469.55*4.18\n", + "tc1=512.6 ; tc2=647.1 ; pc1=80.97*10**5 ; pc2=220.55*10**5 ; w1=.564 ; w2=.345 ; zc1=.224 ; zc2=.229 ; v1=40.73*10**-6 ; v2=18.07*10**-6 #given data\n", + "x2=1-x1\n", + "a1=16.5938 ; a2=16.262 ; b1=3644.3 ; b2=3799.89 ; c1=239.76 ; c2=226.35\n", + "p1sat=exp(a1-b1/(c1+t))*1000 #Saturation Pressure\n", + "p2sat=exp(a2-b2/(c2+t))*1000\n", + "t=t+273.15 #Temp in Kelvin req.\n", + "h12=(v2/v1)*exp(-a12/(R*t))\n", + "h21=(v1/v2)*exp(-a21/(R*t))\n", + "z=h12/(x1+x2*h12)-h21/(x2+x1*h21)\n", + "g1=exp(-log(x1+x2*h12)+x2*z) #Activity Co-efficients\n", + "g2=exp(-log(x2+x1*h21)-x1*z)\n", + "tr1=t/tc1 #Reduced Temp.\n", + "b0=.083-.422*tr1**-1.6\n", + "b1=.139-.172*tr1**-4.2\n", + "b11=(R*tc1/pc1)*(b0+b1*w1)\n", + "tr2=t/tc2\n", + "b0=.083-.422*tr2**-1.6\n", + "b1=.139-.172*tr2**-4.2\n", + "b22=(R*tc2/pc2)*(b0+b1*w2)\n", + "w12=(w1+w2)**.5\n", + "tc12=(tc1*tc2)**.5\n", + "zc12=(zc1+zc2)**.5\n", + "vc1=zc1*R*tc1/pc1 ; vc2=zc2*R*tc2/pc2\n", + "vc12=((vc1**.33+vc2**.33)/2)**3\n", + "pc12=zc12*R*tc12/vc12\n", + "tr12=t/tc12\n", + "b0=.083-.422*tr12**-1.6\n", + "b1=.139-.172*tr12**-4.2\n", + "b12=(R*tc12/pc12)*(b0+b1*w12)\n", + "d12=2*b12-b11-b22\n", + "p=x1*g1*p1sat+x2*p2sat*g2\n", + "y1=x1*g1*p1sat/p ; y2=x2*g2*p2sat/p\n", + "pnew=p\n", + "#calc of Pressure\n", + "while et>1e-6:\n", + " p=pnew\n", + " f1=p1sat*(exp(b11*p1sat/(R*t)))*(exp((v1*(p-p1sat)/(R*t))))\n", + " f2=p2sat*(exp(b22*p2sat/(R*t)))*(exp((v2*(p-p2sat)/(R*t))))\n", + " while er>1e-6:\n", + " sold=snew\n", + " fc1=exp((p/(R*t))*(b11+y2**2*d12))\n", + " fc2=exp((p/(R*t))*(b22+y1**2*d12))\n", + " k1=g1*f1/(fc1*p)\n", + " k2=g2*f2/(fc2*p)\n", + " snew=x1*k1+x2*k2\n", + " y1=x1*k1/snew\n", + " y2=x2*k2/snew\n", + " er=abs(snew-sold)\n", + "\n", + " pnew=(x1*g1*f1/fc1)+(x2*g2*f2/fc2)\n", + " y1=x1*g1*f1/(fc1*pnew)\n", + " y2=x2*g2*f2/(fc2*pnew)\n", + " et=abs(pnew-p)\n", + "\n", + "print \"the amt. of methanol in vapour phase and system pressure in Pa respectively are\",y1,p" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.9 Page 41" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of X1 and X2 respectively is 0.912056278984 0.632839210308\n", + "the moles at eqm of CH4,H2O,CO,H2,CO2 are 0.0879437210164 3.45510451071 0.279217068676 3.36900804726 0.632839210308\n", + "total number of moles at eqm. is 7.82411255797\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy import sqrt,log,exp\n", + "#let x1 and x2 be the reaction co-ordinate for 1st and 2nd reactions\n", + "x1new=.9 ; x2new=.6 ; r1=1 ; r2=1 #assumed values\n", + "Kp=1 #since P=1 atm\n", + "K1=.574 ; K2=2.21 #given\n", + "Kye1=K1 ; Kye2=K2 #at eqm.\n", + "while r1>1e-6 and r2>1e-6:\n", + " x1=x1new ; x2=x2new\n", + " m_CH4=1-x1\n", + " m_H2O=5-x1-x2\n", + " m_CO=x1-x2\n", + " m_H2=3*x1+x2\n", + " m_CO2=x2 #moles of reactants and products at eqm.\n", + " total=m_CO2+m_H2+m_CO+m_H2O+m_CH4\n", + " Ky1=m_CO*m_H2**3/(m_CH4*m_H2O*total**2)\n", + " Ky2=m_CO2*m_H2/(m_CO*m_H2O)\n", + " f1=Ky1-.574 #1st function in x1 and x2\n", + " f2=Ky2-2.21 #2nd function in x1 and x2\n", + " d3=((3*x1+x2)**2*(12*x1-8*x2))/((1-x1)*(5-x1-x2)*(6+2*x1)**2)\n", + " d4=(3*x1+x2)**3*(x1-x2)*(8*x1**2+6*x1*x2-24*x1+2*x2-16)\n", + " d5=((1-x1)**2)*((5-x1-x2)**2)*((6+2*x1)**3)\n", + " df1_dx1=d3-(d4/d5) #df1/dx1- partial derivative of f1 wrt to x1\n", + " d6=3*(x1-x2)*((3*x1+x2)**2)-(3*x1+x2)**3\n", + " d7=(1-x1)*(5-x1-x2)*((6+x1*2)**2)\n", + " d8=((x1-x2)*(3*x1+x2)**3)/((1-x1)*((5-x1-x2)**2)*(6+2*x1)**2)\n", + " df1_dx2=(d6/d7)+d8 #df1/dx2- partial derivative of f1 wrt to x2 \n", + " d9=(x1-x2)*(5-x1-x2)\n", + " df2_dx1=3*x2/d9-(x2*(3*x1+x2)*(5-2*x1))/(d9**2) #df1/dx2- partial derivative of f1 wrt to x2\n", + " d10=(3*x1+2*x2)/d9\n", + " d11=x2*(3*x1+x2)*(2*x2-5)/(d9**2)\n", + " df2_dx2=d10-d11 #df1/dx2- partial derivative of f1 wrt to x2\n", + " dm=df1_dx1*df2_dx2-df1_dx2*df2_dx1\n", + " delta_x1=(f2*df1_dx2-f1*df2_dx2)/dm\n", + " delta_x2=(f1*df2_dx1-f2*df1_dx1)/dm\n", + " x1new=x1+delta_x1 #updating the values of x1 & x2\n", + " x2new=x2+delta_x2\n", + " r1=abs(x1-x1new)\n", + " r2=abs(x2new-x2)\n", + "\n", + "print \"the value of X1 and X2 respectively is\",x1,x2\n", + "m_CH4=1-x1 ; m_H2O=5-x1-x2 ; m_CO=x1-x2 ; m_H2=3*x1+x2 ; m_CO2=x2 #moles of reactants and products at eqm.\n", + "total=m_CO2+m_H2+m_CO+m_H2O+m_CH4\n", + "print \"the moles at eqm of CH4,H2O,CO,H2,CO2 are\",m_CH4,m_H2O,m_CO,m_H2,m_CO2\n", + "print \"total number of moles at eqm. is\",total" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 3.10 Page 45" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the adiabatic flame temp in K is 2090.37132921579\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from scipy import sqrt,log,exp\n", + "from sympy.abc import t\n", + "\n", + "u1=1 ; u2=3.5 ; u3=2 ; u4=3 #moles given 1-C2H6, 2-O2, 3-CO2, 4-H2O\n", + "a1=1.648 ; a2=6.085 ; a3=5.316 ; a4=7.7\n", + "b1=4.124e-2 ; b2=.3631e-2 ; b3=1.4285e-2 ; b4=.04594e-2\n", + "c1=-1.53e-5 ; c2=-.1709e-5 ; c3=-.8362e-5 ; c4=.2521e-5\n", + "d1=1.74e-9 ; d2=.3133e-9 ; d3=1.784e-9 ; d4=-.8587e-9\n", + "n1=1 ; n2=4 ; n3=10 ; n4=0 ; t0=298.15 ; t1=25 ; e1=1\n", + "t1=t1+273.15\n", + "#calc. of sum of co-efficients of heat capacity of the rxn.\n", + "sa=n1*a1+n2*a2+n3*a3+n4*a4\n", + "sb=n1*b1+n2*b2+n3*b3+n4*b4\n", + "sc=n1*c1+n2*c2+n3*c3+n4*c4\n", + "sd=n1*d1+n2*d2+n3*d3+n4*d4\n", + "da=u4*a4+u3*a3-u2*a2-u1*a1\n", + "db=u4*b4+u3*b3-u2*b2-u1*b1\n", + "dc=u4*c4+u3*c3-u2*c2-u1*c1\n", + "dd=u4*d4+u3*d3-u2*d2-u1*d1\n", + "h0=(u4*(-57.798)+u3*(-94.05)-u2*0-u1*(-20.236))*1000 #enthalpy of the rxn.\n", + "tnew=1000\n", + "\n", + "while e1>1e-6:\n", + " tt=tnew\n", + " ft=sa*(t-t1)+(sb/2)*(t**2-t1**2)+(sc/3)*(t**3-t1**3)+(sd/4)*(t**4-t1**4)+h0+da*(t-t0)+(db/2)*(t**2-t0**2)+(dc/3)*(t**3-t0**3)+(dd/4)*(t**4-t0**4)\n", + " dr=ft.diff().subs(t,tt)\n", + " tnew=tt-ft.subs(t,tt)/dr\n", + " e1=abs((tnew-tt)/tnew)\n", + "\n", + "print \"the adiabatic flame temp in K is\",tnew" + ] + } + ], + "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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter4.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter4.ipynb new file mode 100644 index 00000000..b312c767 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter4.ipynb @@ -0,0 +1,1473 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 4 - Initial Value Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.1 Page 55" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of y at x=.2 using Runge Kutta method is 0.0214025708507\n", + "the value of y at x=0.2 from analytical eqn is 0.0214027581602\n" + ] + } + ], + "source": [ + "from numpy import arange,exp\n", + "from __future__ import division\n", + "# in this problem dy/dx=x+y\n", + "x_0=0 ; y_0=0 #initial values given\n", + "\n", + "\n", + "def fs(x,y):\n", + " ydash=x+y\n", + " return ydash\n", + "\n", + "for x_0 in arange(0,0.3,0.1):\n", + " h=0.1 #step increment of 0.1\n", + " f_0=fs(x_0,y_0)\n", + " k1=h*f_0\n", + " k2=h*fs(x_0+h/2,y_0+k1/2)\n", + " k3=h*fs(x_0+h/2,y_0+k2/2)\n", + " k4=h*fs(x_0+h,y_0+k3)\n", + " y_0=y_0+(k1+2*k2+2*k3+k4)/6\n", + "\n", + "y_0=y_0-(k1+2*k2+2*k3+k4)/6 #to get value at x=0.2\n", + "print \"the value of y at x=.2 using Runge Kutta method is\",y_0\n", + "ae=exp(x_0)-x_0-1 #analytical eqn given\n", + "print \"the value of y at x=0.2 from analytical eqn is\",ae" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.2 Page 57" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of y at x=2.5 using Runge Kutta method is 0.571428571429\n" + ] + } + ], + "source": [ + "from numpy import arange,exp\n", + "from __future__ import division\n", + "# in this problem dy/dx=-y/(1+x)\n", + "x_0=0; y_0=2 #initial values given\n", + "\n", + "def fr(x,y):\n", + " ydash=-y/(1+x)\n", + " return ydash\n", + "for x_0 in arange(0,2.5+0.01,0.01):\n", + " h=0.01 #step increment of 0.01\n", + " f_0=fr(x_0,y_0)\n", + " k1=h*f_0\n", + " k2=h*fr(x_0+h/2,y_0+k1/2)\n", + " k3=h*fr(x_0+h/2,y_0+k2/2)\n", + " k4=h*fr(x_0+h,y_0+k3)\n", + " y_0=y_0+(k1+2*k2+2*k3+k4)/6\n", + "\n", + "y_0=y_0-(k1+2*k2+2*k3+k4)/6 #final value at x=2.5\n", + "print \"the value of y at x=2.5 using Runge Kutta method is\",y_0" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.3 Page 58" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of T in deg Celsius at z=5 m using Runge Kutta method is 28.9818069623\n", + "the value of T in deg Celsius at z=10 m using Runge Kutta method is 37.5959411201\n" + ] + } + ], + "source": [ + "from numpy import arange,exp,pi\n", + "from __future__ import division\n", + "rho=1000; v=1; dia=2.4*10**-2; Cp=4184 #given data \n", + "mdot=rho*v*pi*dia**2/4\n", + "t1=mdot*Cp\n", + "U=200\n", + "Ts=250\n", + "z=0 #initial values given\n", + "# dT/dz=U*pi*dia*(Ts-T)/(mdot*Cp)\n", + "def fr(z,T):\n", + " Tgrad=U*pi*dia*(Ts-T)/(mdot*Cp)\n", + " return Tgrad\n", + "T=20\n", + "for z in arange(0,10+0.01,0.01):\n", + " h=0.01 #step increment of 0.01\n", + " k1=h*fr(z,T)\n", + " k2=h*fr(z+h/2,T+k1/2)\n", + " k3=h*fr(z+h/2,T+k2/2)\n", + " k4=h*fr(z+h,T+k3)\n", + " T=T+(k1+2*k2+2*k3+k4)/6\n", + " if z==5 :\n", + " T=T-(k1+2*k2+2*k3+k4)/6\n", + " print \"the value of T in deg Celsius at z=5 m using Runge Kutta method is\",T\n", + " \n", + "T=T-(k1+2*k2+2*k3+k4)/6 #final value at z=10 m\n", + "print \"the value of T in deg Celsius at z=10 m using Runge Kutta method is\",T" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.4 Page 59" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the time at which exit temp. in sec. is 28 C is 686\n", + "the value of steady Temp in Celsius is 30.4924053747\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange\n", + "vol=.5*.5*2 #given data\n", + "rho=1000\n", + "m=vol*rho\n", + "vol_rate=.001\n", + "mdot=vol_rate*rho\n", + "out_A=1\n", + "U=200\n", + "Cp=4184\n", + "T1=20; Ts=250; T_exit=28 #temp in Celsius\n", + "t1=(mdot*Cp*T1+U*out_A*Ts)/(m*Cp) #terms of the function\n", + "t2=(mdot*Cp+U*out_A)/(m*Cp)\n", + "#dt/dt=(mdot*Cp(T1-T)+Q_dot)/m*Cp\n", + "def fv(tm,T):\n", + " tgrad=t1-t2*T\n", + " return tgrad\n", + "T=20 #initial value\n", + "\n", + "for tm in arange(0,5001,1):\n", + " h=1 #step increment of 1 sec\n", + " k1=h*fv(tm,T)\n", + " k2=h*fv(tm+h/2,T+k1/2)\n", + " k3=h*fv(tm+h/2,T+k2/2)\n", + " k4=h*fv(tm+h,T+k3)\n", + " e1=abs(T-T_exit)\n", + " if e1<1e-3 :\n", + " print \"the time at which exit temp. in sec. is 28 C is\",tm\n", + " \n", + " T=T+(k1+2*k2+2*k3+k4)/6\n", + " \n", + "T=T-(k1+2*k2+2*k3+k4)/6 #final steady state temp.\n", + "print \"the value of steady Temp in Celsius is\",T" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.5 Page 62" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of T in deg C after 50 mins is 49.7501698463\n", + "the steady state temp in deg C is 61.7647058824\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange\n", + "m=760 #given data\n", + "mdot=12/60\n", + "U_into_A=11.5/60\n", + "Cp=2.3\n", + "T1=25; Ts=150\n", + "t1=(mdot*Cp*T1+U_into_A*Ts)/(m*Cp)\n", + "t2=(mdot*Cp+U_into_A)/(m*Cp)\n", + "#using energy balance we know accumulation=input-output\n", + "#T is the temp. of fluid in stirred tank\n", + "def fg(t,T):\n", + " tgrade=(t1-t2*T)\n", + " return tgrade\n", + "T=25\n", + "for t in arange(0,3001,1):\n", + " h=1 #step increment of 1 sec\n", + " k1=h*fg(t,T)\n", + " k2=h*fg(t+h/2,T+k1/2)\n", + " k3=h*fg(t+h/2,T+k2/2)\n", + " k4=h*fg(t+h,T+k3)\n", + " T=T+(k1+2*k2+2*k3+k4)/6\n", + " \n", + "T=T-(k1+2*k2+2*k3+k4)/6 #to get value at x=0.2\n", + "print \"the value of T in deg C after 50 mins is\",T\n", + "T_steady=(mdot*Cp*T1+U_into_A*Ts)/(mdot*Cp+U_into_A)\n", + "print \"the steady state temp in deg C is\",T_steady" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.6 Page 64" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of v at the end of the pneumatic conveyor is 10.9043471355\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,sqrt,pi\n", + "\n", + "dia=3*10**-4 #given data\n", + "v_sprfcl=12\n", + "rho_p=900\n", + "meu=1.8*10**-5\n", + "P=101325\n", + "T=298.15\n", + "R=8.314\n", + "M=28.84*10**-3\n", + "rho_air=P*M/(R*T)\n", + "proj_A=pi*(dia**2)/4\n", + "volm=pi*(dia**3)/6\n", + "t1=rho_air*proj_A/(volm*rho_p) #terms of the function\n", + "t2=((rho_air/rho_p)-1)*9.81*2\n", + "y=0\n", + "for z in arange(.01,10.01,0.01):\n", + " h=.01\n", + " vn1=sqrt(y)\n", + " Re=rho_air*(12-vn1)*dia/meu\n", + " Cd=24*(1+.15*Re**.687)/Re\n", + " def fy(z,y):\n", + " dy_by_dz=t1*Cd*(12-sqrt(y))**2+t2\n", + " return dy_by_dz\n", + "\n", + " kk1=h*fy(z,y)\n", + " kk2=h*fy(z+h/2,y+kk1/2)\n", + " kk3=h*fy(z+h/2,y+kk2/2)\n", + " kk4=h*fy(z+h,y+kk3)\n", + " y=y+(kk1+2*kk2+2*kk3+kk4)/6\n", + " \n", + "v=sqrt(y) #final value of velocity\n", + "print \"the value of v at the end of the pneumatic conveyor is\",v" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.7 Page 65" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of x and y repectively are 10.5385351539 11.7141482239\n", + "the analytical values of x and y are respectively 10.5396252201 11.7157840648\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "def fw(t,x,y):\n", + " dx_dt=x+2*y\n", + " return dx_dt\n", + "def fq(t,x,y):\n", + " dy_dt=3*x+2*y\n", + " return dy_dt\n", + "y=4;x=6 #initial values\n", + "#solving by Runge-Kutta method\n", + "for t in arange(0,.3,.1):\n", + " h=.1 #step increment of 0.1\n", + " k1=h*fw(t,x,y)\n", + " l1=h*fq(t,x,y)\n", + " k2=h*fw(t+h/2,x+k1/2,y+l1/2)\n", + " l2=h*fq(t+h/2,x+k1/2,y+l1/2)\n", + " k3=h*fw(t+h/2,x+k2/2,y+l2/2)\n", + " l3=h*fq(t+h/2,x+k2/2,y+l2/2)\n", + " k4=h*fw(t+h,x+k3,y+l3)\n", + " l4=h*fq(t+h,x+k3,y+l3)\n", + " x=x+(k1+2*k2+2*k3+k4)/6\n", + " y=y+(l1+2*l2+2*l3+l4)/6\n", + " \n", + "x=x-(k1+2*k2+2*k3+k4)/6\n", + "y=y-(l1+2*l2+2*l3+l4)/6\n", + "print \"the values of x and y repectively are\",x,y\n", + "t_an=.2\n", + "x_an=4*exp(4*t)+2*exp(-t)\n", + "y_an=6*exp(4*t)-2*exp(-t)\n", + "print \"the analytical values of x and y are respectively\",x_an,y_an" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.8 Page 66" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of y and z respectively are -1.83886143329 -1.27223682875\n", + "the analytical values of y and z are -1.83886498514 -1.27223251272\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "from math import atan,exp,sin,cos\n", + "def fw(x,y,z):\n", + " dy_dx=z\n", + " return dy_dx\n", + " \n", + "def fq(x,y,z):\n", + " dz_dx=-y\n", + " return dz_dx\n", + "y=2; z=1 #initial values\n", + "for x in arange(0,3.1,0.1):\n", + " h=.1 #step increment of 0.1\n", + " k1=h*fw(x,y,z)\n", + " l1=h*fq(x,y,z)\n", + " k2=h*fw(x+h/2,y+k1/2,z+l1/2)\n", + " l2=h*fq(x+h/2,y+k1/2,z+l1/2)\n", + " k3=h*fw(x+h/2,y+k2/2,z+l2/2)\n", + " l3=h*fq(x+h/2,y+k2/2,z+l2/2)\n", + " k4=h*fw(x+h,y+k3,z+l3)\n", + " l4=h*fq(x+h,y+k3,z+l3)\n", + " y=y+(k1+2*k2+2*k3+k4)/6\n", + " z=z+(l1+2*l2+2*l3+l4)/6\n", + " \n", + "y=y-(k1+2*k2+2*k3+k4)/6\n", + "z=z-(l1+2*l2+2*l3+l4)/6\n", + "print \"the values of y and z respectively are\",y,z\n", + "# for the given analytical eqns the values of A and alpha can be determined using initial values of y and z\n", + "alpha=atan(2)\n", + "A=2/sin(alpha)\n", + "y_an=A*sin(alpha+x)\n", + "z_an=A*cos(alpha+x)\n", + "print \"the analytical values of y and z are\",y_an,z_an" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.9 Page 67" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of y and z repectively are -1.90009675418 -1.14870918402\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "def fw(x,y,z): #let us have dy/dx=z, therefore d2y/dx2=dz/dx\n", + " dy_dx=z\n", + " return dy_dx\n", + "def fq(x,y,z):\n", + " dz_dx=-y*x\n", + " return dz_dx\n", + "y=2 ; z=1\n", + "for x in arange(0,3.1,0.1):\n", + " h=0.1 #step increment of 0.1\n", + " k1=h*fw(x,y,z)\n", + " l1=h*fq(x,y,z)\n", + " k2=h*fw(x+h/2,y+k1/2,z+l1/2)\n", + " l2=h*fq(x+h/2,y+k1/2,z+l1/2)\n", + " k3=h*fw(x+h/2,y+k2/2,z+l2/2)\n", + " l3=h*fq(x+h/2,y+k2/2,z+l2/2)\n", + " k4=h*fw(x+h,y+k3,z+l3)\n", + " l4=h*fq(x+h,y+k3,z+l3)\n", + " y=y+(k1+2*k2+2*k3+k4)/6\n", + " z=z+(l1+2*l2+2*l3+l4)/6\n", + " \n", + "y=y-(k1+2*k2+2*k3+k4)/6\n", + "z=z-(l1+2*l2+2*l3+l4)/6\n", + "print \"the values of y and z repectively are\",y,z" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.10 Page 67" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the steady state temperature of tank 1 is 30.9523809524\n", + "the steady state temperature of tank 2 is 41.3832199546\n", + "the steady state temperature of tank 3 is 51.3173523378\n", + "the approx. time when Temperature in 3rd tank is 99% of steady value is 3150\n", + "the approx. time when Temperature in 3rd tank is 99% of steady value is 3151\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "\n", + "Cp=2000 ; A=1 ; U=200 ; m=1000 ; mdot=2; Ts=250 #given data\n", + "T0=20; T1=0; T2=0 ; T3=0\n", + "\n", + "#from energy balances for the tanks we have accumulation=inlet-outlet\n", + "T1_steady=(mdot*Cp*(T0)+U*A*(Ts))/(mdot*Cp+U*A)\n", + "print \"the steady state temperature of tank 1 is\",T1_steady\n", + "T2_steady=(mdot*Cp*(T1_steady)+U*A*(Ts))/(mdot*Cp+U*A)\n", + "print \"the steady state temperature of tank 2 is\",T2_steady\n", + "T3_steady=(mdot*Cp*(T2_steady)+U*A*(Ts))/(mdot*Cp+U*A)\n", + "print \"the steady state temperature of tank 3 is\",T3_steady\n", + "final_T3=.99*T3_steady\n", + "def f1(t,T1,T2,T3):\n", + " dT1_by_dt=(mdot*Cp*(T0-T1)+U*A*(Ts-T1))/(m*Cp)\n", + " return dT1_by_dt\n", + "def f2(t,T1,T2,T3):\n", + " dT2_by_dt=(mdot*Cp*(T1-T2)+U*A*(Ts-T2))/(m*Cp)\n", + " return dT2_by_dt\n", + "def f3(t,T1,T2,T3):\n", + " dT3_by_dt=(mdot*Cp*(T2-T3)+U*A*(Ts-T3))/(m*Cp)\n", + " return dT3_by_dt\n", + "T1=20 ; T2=20 ; T3=20\n", + "#solving by Newton's Method\n", + "for t in arange(0,10001,1):\n", + " h=1 #step increment of 1\n", + " k1=h*f1(t,T1,T2,T3)\n", + " l1=h*f2(t,T1,T2,T3)\n", + " m1=h*f3(t,T1,T2,T3)\n", + " k2=h*f1(t+h/2,T1+k1/2,T2+l1/2,T3+m1/2)\n", + " l2=h*f2(t+h/2,T1+k1/2,T2+l1/2,T3+m1/2)\n", + " m2=h*f3(t+h/2,T1+k1/2,T2+l1/2,T3+m1/2)\n", + " k3=h*f1(t+h/2,T1+k2/2,T2+l2/2,T3+m2/2)\n", + " l3=h*f2(t+h/2,T1+k2/2,T2+l2/2,T3+m2/2)\n", + " m3=h*f3(t+h/2,T1+k2/2,T2+l2/2,T3+m2/2)\n", + " k4=h*f1(t+h,T1+k3,T2+l3,T3+m3)\n", + " l4=h*f2(t+h,T1+k3,T2+l3,T3+m3)\n", + " m4=h*f3(t+h,T1+k3,T2+l3,T3+m3)\n", + " T1=T1+(k1+2*k2+2*k3+k4)/6\n", + " T2=T2+(l1+2*l2+2*l3+l4)/6\n", + " e1=abs(T3-final_T3)\n", + " if e1<1e-3:\n", + " print \"the approx. time when Temperature in 3rd tank is 99% of steady value is\",t\n", + " T3=T3+(m1+2*m2+2*m3+m4)/6" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.11 Page 68" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of conc. at t=3 using Runge Kutta method is 0.0497872036658\n", + "the analytical soln. is 0.0497870683679\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "#rxn given A--> B\n", + "rate_const_k=1\n", + "def fs1(t,Ca):\n", + " dCa_by_dt=-rate_const_k*Ca\n", + " return dCa_by_dt\n", + "Ca=1\n", + "for t in arange(0.1,3.1,0.1):\n", + " h=0.1 #step increment of 0.1\n", + " k1=h*fs1(t,Ca)\n", + " k2=h*fs1(t+h/2,Ca+k1/2)\n", + " k3=h*fs1(t+h/2,Ca+k2/2)\n", + " k4=h*fs1(t+h,Ca+k3)\n", + " Ca=Ca+(k1+2*k2+2*k3+k4)/6\n", + "\n", + "print \"the value of conc. at t=3 using Runge Kutta method is\",Ca\n", + "Ca_anl=exp(-t) #analytical solution\n", + "print \"the analytical soln. is\",Ca_anl" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.12 Page 69" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of Ca at t=10 s using Runge Kutta method is 0.0909090909091\n", + "the steady state value of conc. is 0.0909090909091\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "#rxn A-->B\n", + "#input=FCa0, output=FCa\n", + "#applying mass balance of component A we get d(V*Ca)/dt=F*Ca0-F*Ca-k*Ca*V\n", + "rate_const_k=1\n", + "Ca0=1 ; F=1 ; V=10\n", + "\n", + "def fr(t,Ca1):\n", + " dVCa_by_dt=F*Ca0-F*Ca1-rate_const_k*Ca1*V\n", + " return dVCa_by_dt\n", + "Ca1=1\n", + "for t in arange(0.1,10.1,0.1):\n", + " h=0.1 #step increment of 0.1\n", + " k1=h*fr(t,Ca1)\n", + " k2=h*fr(t+h/2,Ca1+k1/2)\n", + " k3=h*fr(t+h/2,Ca1+k2/2)\n", + " k4=h*fr(t+h,Ca1+k3)\n", + " Ca1=Ca1+(k1+2*k2+2*k3+k4)/6\n", + " #final value\n", + "print \"the value of Ca at t=10 s using Runge Kutta method is\",Ca1\n", + "Ca_steady=F*Ca0/(F+rate_const_k*V)\n", + "print \"the steady state value of conc. is\",Ca_steady" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.13 Page 70" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the conc. of A,B,C after 0.5 secs is 0.606530934423 0.303264070711 0.0902049948655\n", + "the conc. of A,B,C after 1.0 secs is 0.367879774412 0.367878080371 0.264242145217\n", + "the conc. of A,B,C after 2.0 secs is 0.135335528422 0.270669810436 0.593994661142\n", + "the conc. of A,B,C after 5.0 secs is 0.00673797751675 0.0336897324459 0.959572290037\n", + "the conc. of A,B,C after 10 secs respectively is 4.54003410163e-05 0.000454001319532 0.999500598339\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "\n", + "#given rxn A-->B-->C\n", + "k1=1; k2=1 #given data\n", + "def f1a(t,A,B,C): #functions defined\n", + " dA_by_dt=-A\n", + " return dA_by_dt\n", + "def f2a(t,A,B,C):\n", + " dB_by_dt=A-B\n", + " return dB_by_dt\n", + "def f3a(t,A,B,C):\n", + " dC_by_dt=B\n", + " return dC_by_dt\n", + "A=1 ;B=0 ;C=0 #initial values\n", + "for t in arange(0.1,10.1,0.1):\n", + " h=.1 #step increment of 0.1\n", + " k1=h*f1a(t,A,B,C)\n", + " l1=h*f2a(t,A,B,C)\n", + " m1=h*f3a(t,A,B,C)\n", + " k2=h*f1a(t+h/2,A+k1/2,B+l1/2,C+m1/2)\n", + " l2=h*f2a(t+h/2,A+k1/2,B+l1/2,C+m1/2)\n", + " m2=h*f3a(t+h/2,A+k1/2,B+l1/2,C+m1/2)\n", + " k3=h*f1a(t+h/2,A+k2/2,B+l2/2,C+m2/2)\n", + " l3=h*f2a(t+h/2,A+k2/2,B+l2/2,C+m2/2)\n", + " m3=h*f3a(t+h/2,A+k2/2,B+l2/2,C+m2/2)\n", + " k4=h*f1a(t+h,A+k3,B+l3,C+m3)\n", + " l4=h*f2a(t+h,A+k3,B+l3,C+m3)\n", + " m4=h*f3a(t+h,A+k3,B+l3,C+m3)\n", + " A=A+(k1+2*k2+2*k3+k4)/6\n", + " B=B+(l1+2*l2+2*l3+l4)/6\n", + " C=C+(m1+2*m2+2*m3+m4)/6\n", + " if t==.5 or t==1 or t==2 or t==5 :\n", + " print \"the conc. of A,B,C after\",t,\"secs is\",A,B,C\n", + " \n", + "print \"the conc. of A,B,C after 10 secs respectively is\",A,B,C" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.14 Page 71" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the conc. of A,B,C,D after 10 secs respectively is 0.909221602698 0.904970552714 0.0865273473177 0.00425104998406\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.834171033289 0.819591322892 0.151249256314 0.0145797103969\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.771526698493 0.743175149135 0.20012175215 0.0283515493576\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.718763584219 0.67487940149 0.237352233053 0.0438841827281\n", + "the conc. of A,B,C,D after 0.5 secs is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.635587969272 0.55922762747 0.288051688925 0.0763603418024\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.602518712698 0.510295639479 0.305258214083 0.0922230732191\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.573825046136 0.466370377686 0.318720285414 0.10745466845\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.548779962461 0.426859807297 0.329299882375 0.121920155164\n", + "the conc. of A,B,C,D after 1.0 secs is 0.52680094957 0.391245989895 0.337644090755 0.135554959675\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.52680094957 0.391245989895 0.337644090755 0.135554959675\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.507417223315 0.359077536366 0.344243089736 0.148339686949\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.490245152639 0.329961657439 0.349471352161 0.1602834952\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.474969674462 0.303556564616 0.353617215693 0.171413109846\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.461330119618 0.27956455757 0.356904318334 0.181765562048\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.449109312513 0.257725910909 0.359507285883 0.191383401604\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.438125119864 0.23781355818 0.361563318452 0.200311561684\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.428223846389 0.219628516078 0.363180823301 0.208595330311\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.419275034438 0.202995969535 0.364445900659 0.216279064903\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.411167339142 0.187761933365 0.36542725508 0.223405405777\n", + "the conc. of A,B,C,D after 2.0 secs is 0.403805233709 0.173790409818 0.366179942399 0.230014823891\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.403805233709 0.173790409818 0.366179942399 0.230014823891\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.397106360172 0.160960968915 0.366748248571 0.236145391257\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.390999385517 0.149166687328 0.367167916295 0.241832698188\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.385422256195 0.138312390419 0.36746787803 0.247109865775\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.380320768708 0.128313150237 0.367671612821 0.252007618471\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.375647392533 0.119092999585 0.36779821452 0.256554392948\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.37136029568 0.11058382858 0.36786323722 0.2607764671\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.367422533931 0.102724435507 0.367879367645 0.264698098424\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.363801372979 0.0954597083513 0.367856962394 0.268341664627\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.360467719057 0.0887399171885 0.367804479075 0.271727801868\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.357395638584 0.0825201008309 0.367728823663 0.274875537753\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.354561951166 0.0767595337823 0.367635631451 0.277802417384\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.351945883361 0.0714212617803 0.367529495058 0.280524621581\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.349528772976 0.0664716960569 0.367414150106 0.283057076919\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.347293815565 0.0618802579883 0.367292626859 0.285413557576\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.345225846335 0.0576190670956 0.367167374425 0.287606779239\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.343311151848 0.0536626664309 0.367040362736 0.289648485417\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.341537306905 0.0499877802859 0.366913166476 0.291549526619\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.339893032801 0.0465730999121 0.36678703431 0.293319932889\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.338368073749 0.0433990935763 0.366662946079 0.294968980172\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.336953088837 0.0404478378093 0.366541660135 0.296505251028\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.335639557286 0.0377028671538 0.366423752583 0.297936690132\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.334419695135 0.0351490400977 0.366309649828 0.299270655037\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.333286381788 0.0327724192024 0.366199655626 0.300513962586\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.332233095079 0.0305601637072 0.366093973549 0.301672931372\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.331253853723 0.0285004331231 0.365992725677 0.3027534206\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.330343166195 0.0265823005295 0.365895968139 0.303760865666\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.329495985212 0.0247956744548 0.365803704032 0.304700310757\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.328707667101 0.0231312283662 0.365715894165 0.305576438734\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32797393547 0.0215803369203 0.365632465979 0.30639359855\n", + "the conc. of A,B,C,D after 5.0 secs is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.326654770412 0.0187878815118 0.365478340688 0.3078668889\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.326062343718 0.0175320794959 0.365407392061 0.308530264222\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.325510466935 0.0163612651761 0.365340331307 0.309149201758\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32499627244 0.0152695523777 0.365277007498 0.309726720062\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.324517107234 0.0142514797992 0.365217265332 0.310265627434\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.324070515374 0.0133019781679 0.36516094742 0.310768537206\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.323654222036 0.0124163402028 0.36510789613 0.311237881834\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.323266119025 0.0115901931149 0.365057955064 0.31167592591\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.322904251582 0.0108194734013 0.365010970238 0.31208477818\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32256680636 0.010100403717 0.364966790997 0.312466402643\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.322252100453 0.00942947163274 0.364925270727 0.31282262882\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32195857136 0.00880341010523 0.364886267385 0.313155161255\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.321684767811 0.00821917950607 0.364849643884 0.313465588305\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.321429341352 0.0076739510701 0.364815268365 0.313755390282\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.321191038641 0.0071650916388 0.364783014357 0.314025947002\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320968694361 0.00669014958624 0.364752760865 0.314278544774\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320761224716 0.00624684182645 0.364724392395 0.314514382889\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320567621448 0.00583304181063 0.364697798914 0.314734579638\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320386946326 0.00544676843143 0.36467287578 0.314940177894\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320218326064 0.00508617575939 0.364649523631 0.315132150305\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320060947646 0.00474954354349 0.364627648251 0.315311404103\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319914053998 0.00443526841398 0.364607160417 0.315478785584\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319776940002 0.00414185573132 0.364587975728 0.31563508427\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319648948802 0.00386791202995 0.364570014426 0.315781036772\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319529468398 0.00361213801035 0.364553201214 0.315917330388\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319417928488 0.00337332203659 0.364537465062 0.316044606451\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319313797541 0.00315033410046 0.364522739018 0.316163463441\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319216580097 0.0029421202165 0.364508960022 0.316274459881\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319125814253 0.00274769721536 0.364496068709 0.316378117038\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319041069335 0.00256614790527 0.364484009235 0.31647492143\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318961943743 0.00239661657445 0.364472729088 0.316565327169\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318888062945 0.00223830480885 0.364462178919 0.316649758136\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318819077617 0.00209046760225 0.364452312369 0.316728610015\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318754661915 0.00195240973716 0.364443085908 0.316802252177\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318694511869 0.00182348241684 0.364434458678 0.316871029453\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318638343895 0.00170308013039 0.36442639234 0.316935263765\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.3185858934 0.0015906377339 0.364418850933 0.316995255667\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318536913498 0.00148562773249 0.364411800736 0.317051285766\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318491173806 0.00138755774864 0.364405210136 0.317103616058\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318448459329 0.00129596816386 0.364399049506 0.317152491165\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318408569419 0.00121042992125 0.364393291084 0.317198139497\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318371316807 0.0011305424778 0.364387908864 0.317240774329\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318336526703 0.0010559318958 0.364382878489 0.317280594807\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318304035957 0.000986249063808 0.364378177149 0.317317786893\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318273692274 0.000921168038026 0.36437378349 0.317352524236\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318245353488 0.000860384495848 0.36436967752 0.317384968992\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318218886882 0.000803614293751 0.364365840529 0.317415272588\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318194168558 0.000750592122388 0.364362255007 0.317443576435\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318171082842 0.000701070252194 0.364358904569 0.317470012589\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318149521739 0.000654817363294 0.364355773886 0.317494704375\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "\n", + "#given rxn A+B--k1-->C\n", + "# B+C--k2-->D\n", + "k1=1; k2=1 #given rate constants\n", + "def f1a(t,A,B,C,D):\n", + " dA_by_dt=-A*B\n", + " return dA_by_dt\n", + "def f2a(t,A,B,C,D):\n", + " dB_by_dt=-A*B-B*C\n", + " return dB_by_dt\n", + "def f3a(t,A,B,C,D):\n", + " dC_by_dt=A*B-B*C\n", + " return dC_by_dt\n", + "def f4a(t,A,B,C,D):\n", + " dD_by_dt=B*C\n", + " return dD_by_dt\n", + "A=1; B=1 ; C=0 ; D=0 #initial values\n", + "for t in arange(.1,10.1,0.1):\n", + " h=.1 #step increment of 0.1\n", + " k1=h*f1a(t,A,B,C,D)\n", + " l1=h*f2a(t,A,B,C,D)\n", + " m1=h*f3a(t,A,B,C,D)\n", + " n1=h*f4a(t,A,B,C,D)\n", + " k2=h*f1a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " l2=h*f2a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " m2=h*f3a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " n2=h*f4a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " k3=h*f1a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " l3=h*f2a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " m3=h*f3a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " n3=h*f4a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " k4=h*f1a(t+h,A+k3,B+l3,C+m3,D+n3)\n", + " l4=h*f2a(t+h,A+k3,B+l3,C+m3,D+n3)\n", + " m4=h*f3a(t+h,A+k3,B+l3,C+m3,D+n3)\n", + " n4=h*f4a(t+h,A+k3,B+l3,C+m3,D+n3)\n", + " A=A+(k1+2*k2+2*k3+k4)/6\n", + " B=B+(l1+2*l2+2*l3+l4)/6\n", + " C=C+(m1+2*m2+2*m3+m4)/6\n", + " D=D+(n1+2*n2+2*n3+n4)/6\n", + " if t==.5 or t==1 or t==2 or t==5:\n", + " print \"the conc. of A,B,C,D after\",t,\"secs is\",A,B,C,D\n", + " \n", + " print \"the conc. of A,B,C,D after 10 secs respectively is\",A,B,C,D" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.15 Page 72" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.9048375\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.818730901406\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.740818422001\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.670320288917\n", + "length is 0.5 the value of conc. at 0.5 length is 0.606530934423\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.606530934423\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.548811934376\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.496585618671\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.449329289734\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.4065699912\n", + "length is 1.0 the value of conc. at 1.0 length is 0.367879774412\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.367879774412\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.33287141538\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.301194539314\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.272532113966\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.246597276671\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.22313046333\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.201896810613\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.182683805373\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.165299157744\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.149568876646\n", + "length is 2.0 the value of conc. at 2.0 length is 0.135335528422\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.135335528422\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.122456661198\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.110803379177\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.100259052606\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0907181505125\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0820851845144\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.074273753143\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0672056771095\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0608102168616\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0550233645995\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0497872036658\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.045049328897\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0407623221358\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0368832776556\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0333733727457\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0301974791617\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.027323811551\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0247236093343\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.022370848861\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0202419829563\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0183157052532\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.016572736952\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0149956338718\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0135686118635\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0122773888371\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0111090418218\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0100518776295\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00909531582456\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00822978283241\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00744661612362\n", + "length is 5.0 the value of conc. at 5.0 length is 0.00673797751675\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00673797751675\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00609677473132\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00551659040595\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00499161787144\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00451660303575\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00408679179936\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00369788247475\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00334598273375\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00302757065185\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00273945945969\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00247876564886\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0022428801128\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00202944203407\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0018363152565\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0016615669059\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00150344804522\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00136037617062\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00123091937328\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00111378200842\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00100779172804\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000911887747724\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000825110229931\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000746590677676\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000675543242311\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000611256858515\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000553088127716\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000500454878763\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000452830341362\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000409737874002\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000370746193568\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000335465058922\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000303541365253\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000274655610082\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000248518695587\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000224869035219\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000203469935655\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000184107227903\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000166587123828\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000150734276656\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000136390026054\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0001234108102\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000111666728974\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000101040243878\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 9.142500167e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 8.27247699485e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 7.48524740283e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 6.77293254686e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 6.12840335337e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 5.54520916925e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 5.01751320168e-05\n", + "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 4.54003410163e-05\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp\n", + "\n", + "rc_k1=1 #given rate constant\n", + "u=1 #mean axial velocity\n", + "def fm(x,Ca):\n", + " dCa_by_dx=-Ca\n", + " return dCa_by_dx\n", + "Ca=1\n", + "for x in arange(.1,10.1,0.1):\n", + " h=0.1 #step increment of 0.1\n", + " k1=h*fm(x,Ca)\n", + " k2=h*fm(x+h/2,Ca+k1/2)\n", + " k3=h*fm(x+h/2,Ca+k2/2)\n", + " k4=h*fm(x+h,Ca+k3)\n", + " Ca=Ca+(k1+2*k2+2*k3+k4)/6\n", + " if x==.5 or x==1 or x==2 or x==5:\n", + " print \"length is\",x,\"the value of conc. at\",x,\"length is\",Ca\n", + " print \"the value of Ca at x=10 using Runge Kutta method in plug flow reactor is\",Ca" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.16 Page 73" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the conc. of A,B,C at a distance of 10 mtr is 0.9048375 0.0904833333333 0.00467916666667\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.818730901406 0.16374542625 0.0175236723438\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.740818422001 0.222244503187 0.0369370748121\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.670320288917 0.26812688087 0.0615528302129\n", + "the conc. of A,B,C at a distance of 0.5 mtr is 0.606530934423 0.303264070711 0.0902049948655\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.606530934423 0.303264070711 0.0902049948655\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.548811934376 0.329285644298 0.121902421325\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.496585618671 0.347608332368 0.15580604896\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.449329289734 0.359461776502 0.191208933763\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.4065699912 0.365911307095 0.227518701705\n", + "the conc. of A,B,C at a distance of 1.0 mtr is 0.367879774412 0.367878080371 0.264242145217\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.367879774412 0.367878080371 0.264242145217\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.33287141538 0.366156870802 0.300971713818\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.301194539314 0.36143178282 0.337373677867\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.272532113966 0.354290116686 0.373177769348\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.246597276671 0.345234597569 0.40816812576\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.22313046333 0.334694153762 0.442175382908\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.201896810613 0.323033409445 0.475069779942\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.182683805373 0.310561039032 0.506755155595\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.165299157744 0.297537113811 0.537163728444\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.149568876646 0.284179557008 0.566251566346\n", + "the conc. of A,B,C at a distance of 2.0 mtr is 0.135335528422 0.270669810436 0.593994661142\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.135335528422 0.270669810436 0.593994661142\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.122456661198 0.257157804331 0.620385534471\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.110803379177 0.24376631167 0.645430309153\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.100259052606 0.230594759128 0.669146188265\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0907181505125 0.217722558639 0.691559290848\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0820851845144 0.205212016305 0.712702799181\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.074273753143 0.193110868916 0.732615377941\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0672056771095 0.181454492616 0.751339830274\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0608102168616 0.170267823146 0.768921959992\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0550233645995 0.159567022548 0.785409612852\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0497872036658 0.149360923205 0.800851873129\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.045049328897 0.139652276496 0.815298394607\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0407623221358 0.130438830177 0.828798847687\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0368832776556 0.121714255781 0.841402466563\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0333733727457 0.113468944822 0.853157682432\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0301974791617 0.105690690371 0.864111830467\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.027323811551 0.0983652686215 0.874310919828\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0247236093343 0.0914769332948 0.883799457371\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.022370848861 0.0850088342147 0.892620316924\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0202419829563 0.0789433700032 0.900814647041\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0183157052532 0.0732624836464 0.9084218111\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.016572736952 0.0679479086101 0.915479354438\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0149956338718 0.0629813722389 0.922022993889\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0135686118635 0.0583447623414 0.928086625795\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0122773888371 0.0540202621252 0.933702349038\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0111090418218 0.0499904579973 0.938900500181\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0100518776295 0.0462384241723 0.943709698198\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00909531582456 0.0427477875262 0.948156896649\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00822978283241 0.0395027756892 0.952267441478\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00744661612362 0.036488250981 0.956065132895\n", + "the conc. of A,B,C at a distance of 5.0 mtr is 0.00673797751675 0.0336897324459 0.959572290037\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00673797751675 0.0336897324459 0.959572290037\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00609677473132 0.0310934079477 0.962809817321\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00551659040595 0.0286861380141 0.96579727158\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00499161787144 0.0264554528939 0.968552929235\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00451660303575 0.0243895440817 0.971093852883\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00408679179936 0.022477251391 0.97343595681\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00369788247475 0.0207080465001 0.975594071025\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00334598273375 0.0190720137577 0.977582003509\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00302757065185 0.0175598289195 0.979412600429\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00273945945969 0.0161627363844 0.981097804156\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00247876564886 0.0148725254067 0.982648708944\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0022428801128 0.0136815056861 0.984075614201\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00202944203407 0.0125824826701 0.985388075296\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0018363152565 0.0115687328431 0.9865949519\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0016615669059 0.0106339792294 0.987704453865\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00150344804522 0.00977236729316 0.988724184662\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00136037617062 0.00897844138125 0.989661182448\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00123091937328 0.00824712182381 0.990521958803\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00111378200842 0.00757368278121 0.99131253521\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.00100779172804 0.00695373090227 0.99203847737\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000911887747724 0.00638318484014 0.992704927412\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000825110229931 0.00585825565583 0.993316634114\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000746590677676 0.00537542812596 0.993877981196\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000675543242311 0.00493144296007 0.994393013798\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000611256858515 0.00452327992376 0.994865463218\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000553088127716 0.0041481418561 0.995298770016\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000500454878763 0.00380343956414 0.995696105557\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000452830341362 0.00348677757223 0.996060392086\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000409737874002 0.00319594070023 0.996394321426\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000370746193568 0.00292888144198 0.996700372364\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000335465058922 0.00268370811317 0.996980826828\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000303541365253 0.0024586737366 0.997237784898\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000274655610082 0.00225216563167 0.997473178758\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000248518695587 0.00206269567487 0.99768878563\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000224869035219 0.00188889119768 0.997886239767\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000203469935655 0.00172948648895 0.998067043575\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000184107227903 0.00158331486896 0.998232577903\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000166587123828 0.00144930130341 0.998384111573\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000150734276656 0.00132645552638 0.998522810197\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000136390026054 0.00121386564215 0.998649744332\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.0001234108102 0.00111069217717 0.998765897013\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000111666728974 0.00101616255434 0.998872170717\n", + "the conc. of A,B,C at a distance of 10 mtr is 0.000101040243878 0.00092956596312 0.998969393793\n", + "the conc. of A,B,C at a distance of 10 mtr is 9.142500167e-05 0.000850248600221 0.999058326398\n", + "the conc. of A,B,C at a distance of 10 mtr is 8.27247699485e-05 0.000777609256704 0.999139665973\n", + "the conc. of A,B,C at a distance of 10 mtr is 7.48524740283e-05 0.000711095228747 0.999214052297\n", + "the conc. of A,B,C at a distance of 10 mtr is 6.77293254686e-05 0.0006501985304 0.999282072144\n", + "the conc. of A,B,C at a distance of 10 mtr is 6.12840335337e-05 0.000594452387883 0.999344263579\n", + "the conc. of A,B,C at a distance of 10 mtr is 5.54520916925e-05 0.000543427996156 0.999401119912\n", + "the conc. of A,B,C at a distance of 10 mtr is 5.01751320168e-05 0.000496731519568 0.999453093348\n", + "the conc. of A,B,C at a distance of 10 mtr is 4.54003410163e-05 0.000454001319532 0.999500598339\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange\n", + "#given rxn A-->B-->C\n", + "rc_k1=1 ; rc_k2=1 #given rate constants\n", + "u=1 #mean axial velocity\n", + "def f1e(x,A,B,C):\n", + " dA_by_dx=-A\n", + " return dA_by_dx\n", + "def f2e(x,A,B,C):\n", + " dB_by_dx=A-B\n", + " return dB_by_dx\n", + "def f3e(x,A,B,C):\n", + " dC_by_dx=B\n", + " return dC_by_dx\n", + "A=1 ; B=0 ; C=0\n", + "for x in arange(.1,10.1,0.1):\n", + " h=.1 #step increment of 0.1\n", + " k1=h*f1e(x,A,B,C)\n", + " l1=h*f2e(x,A,B,C)\n", + " m1=h*f3e(x,A,B,C)\n", + " k2=h*f1e(x+h/2,A+k1/2,B+l1/2,C+m1/2)\n", + " l2=h*f2e(x+h/2,A+k1/2,B+l1/2,C+m1/2)\n", + " m2=h*f3e(x+h/2,A+k1/2,B+l1/2,C+m1/2)\n", + " k3=h*f1e(x+h/2,A+k2/2,B+l2/2,C+m2/2)\n", + " l3=h*f2e(x+h/2,A+k2/2,B+l2/2,C+m2/2)\n", + " m3=h*f3e(x+h/2,A+k2/2,B+l2/2,C+m2/2)\n", + " k4=h*f1e(x+h,A+k3,B+l3,C+m3)\n", + " l4=h*f2e(x+h,A+k3,B+l3,C+m3)\n", + " m4=h*f3e(x+h,A+k3,B+l3,C+m3)\n", + " A=A+(k1+2*k2+2*k3+k4)/6\n", + " B=B+(l1+2*l2+2*l3+l4)/6\n", + " C=C+(m1+2*m2+2*m3+m4)/6\n", + " if x==.5 or x==1 or x==2 or x==5:\n", + " print \"the conc. of A,B,C at a distance of\",x,\"mtr is\",A,B,C\n", + " print \"the conc. of A,B,C at a distance of 10 mtr is\",A,B,C" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.17 Page 74" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the conc. of A,B,C,D after 10 secs respectively is 0.909221602698 0.904970552714 0.0865273473177 0.00425104998406\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.834171033289 0.819591322892 0.151249256314 0.0145797103969\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.771526698493 0.743175149135 0.20012175215 0.0283515493576\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.718763584219 0.67487940149 0.237352233053 0.0438841827281\n", + "the conc. of A,B,C,D after 0.5 secs is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.635587969272 0.55922762747 0.288051688925 0.0763603418024\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.602518712698 0.510295639479 0.305258214083 0.0922230732191\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.573825046136 0.466370377686 0.318720285414 0.10745466845\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.548779962461 0.426859807297 0.329299882375 0.121920155164\n", + "the conc. of A,B,C,D after 1.0 secs is 0.52680094957 0.391245989895 0.337644090755 0.135554959675\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.52680094957 0.391245989895 0.337644090755 0.135554959675\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.507417223315 0.359077536366 0.344243089736 0.148339686949\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.490245152639 0.329961657439 0.349471352161 0.1602834952\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.474969674462 0.303556564616 0.353617215693 0.171413109846\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.461330119618 0.27956455757 0.356904318334 0.181765562048\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.449109312513 0.257725910909 0.359507285883 0.191383401604\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.438125119864 0.23781355818 0.361563318452 0.200311561684\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.428223846389 0.219628516078 0.363180823301 0.208595330311\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.419275034438 0.202995969535 0.364445900659 0.216279064903\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.411167339142 0.187761933365 0.36542725508 0.223405405777\n", + "the conc. of A,B,C,D after 2.0 secs is 0.403805233709 0.173790409818 0.366179942399 0.230014823891\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.403805233709 0.173790409818 0.366179942399 0.230014823891\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.397106360172 0.160960968915 0.366748248571 0.236145391257\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.390999385517 0.149166687328 0.367167916295 0.241832698188\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.385422256195 0.138312390419 0.36746787803 0.247109865775\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.380320768708 0.128313150237 0.367671612821 0.252007618471\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.375647392533 0.119092999585 0.36779821452 0.256554392948\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.37136029568 0.11058382858 0.36786323722 0.2607764671\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.367422533931 0.102724435507 0.367879367645 0.264698098424\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.363801372979 0.0954597083513 0.367856962394 0.268341664627\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.360467719057 0.0887399171885 0.367804479075 0.271727801868\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.357395638584 0.0825201008309 0.367728823663 0.274875537753\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.354561951166 0.0767595337823 0.367635631451 0.277802417384\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.351945883361 0.0714212617803 0.367529495058 0.280524621581\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.349528772976 0.0664716960569 0.367414150106 0.283057076919\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.347293815565 0.0618802579883 0.367292626859 0.285413557576\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.345225846335 0.0576190670956 0.367167374425 0.287606779239\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.343311151848 0.0536626664309 0.367040362736 0.289648485417\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.341537306905 0.0499877802859 0.366913166476 0.291549526619\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.339893032801 0.0465730999121 0.36678703431 0.293319932889\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.338368073749 0.0433990935763 0.366662946079 0.294968980172\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.336953088837 0.0404478378093 0.366541660135 0.296505251028\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.335639557286 0.0377028671538 0.366423752583 0.297936690132\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.334419695135 0.0351490400977 0.366309649828 0.299270655037\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.333286381788 0.0327724192024 0.366199655626 0.300513962586\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.332233095079 0.0305601637072 0.366093973549 0.301672931372\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.331253853723 0.0285004331231 0.365992725677 0.3027534206\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.330343166195 0.0265823005295 0.365895968139 0.303760865666\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.329495985212 0.0247956744548 0.365803704032 0.304700310757\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.328707667101 0.0231312283662 0.365715894165 0.305576438734\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32797393547 0.0215803369203 0.365632465979 0.30639359855\n", + "the conc. of A,B,C,D after 5.0 secs is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.326654770412 0.0187878815118 0.365478340688 0.3078668889\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.326062343718 0.0175320794959 0.365407392061 0.308530264222\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.325510466935 0.0163612651761 0.365340331307 0.309149201758\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32499627244 0.0152695523777 0.365277007498 0.309726720062\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.324517107234 0.0142514797992 0.365217265332 0.310265627434\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.324070515374 0.0133019781679 0.36516094742 0.310768537206\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.323654222036 0.0124163402028 0.36510789613 0.311237881834\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.323266119025 0.0115901931149 0.365057955064 0.31167592591\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.322904251582 0.0108194734013 0.365010970238 0.31208477818\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32256680636 0.010100403717 0.364966790997 0.312466402643\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.322252100453 0.00942947163274 0.364925270727 0.31282262882\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.32195857136 0.00880341010523 0.364886267385 0.313155161255\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.321684767811 0.00821917950607 0.364849643884 0.313465588305\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.321429341352 0.0076739510701 0.364815268365 0.313755390282\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.321191038641 0.0071650916388 0.364783014357 0.314025947002\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320968694361 0.00669014958624 0.364752760865 0.314278544774\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320761224716 0.00624684182645 0.364724392395 0.314514382889\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320567621448 0.00583304181063 0.364697798914 0.314734579638\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320386946326 0.00544676843143 0.36467287578 0.314940177894\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320218326064 0.00508617575939 0.364649523631 0.315132150305\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.320060947646 0.00474954354349 0.364627648251 0.315311404103\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319914053998 0.00443526841398 0.364607160417 0.315478785584\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319776940002 0.00414185573132 0.364587975728 0.31563508427\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319648948802 0.00386791202995 0.364570014426 0.315781036772\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319529468398 0.00361213801035 0.364553201214 0.315917330388\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319417928488 0.00337332203659 0.364537465062 0.316044606451\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319313797541 0.00315033410046 0.364522739018 0.316163463441\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319216580097 0.0029421202165 0.364508960022 0.316274459881\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319125814253 0.00274769721536 0.364496068709 0.316378117038\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.319041069335 0.00256614790527 0.364484009235 0.31647492143\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318961943743 0.00239661657445 0.364472729088 0.316565327169\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318888062945 0.00223830480885 0.364462178919 0.316649758136\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318819077617 0.00209046760225 0.364452312369 0.316728610015\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318754661915 0.00195240973716 0.364443085908 0.316802252177\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318694511869 0.00182348241684 0.364434458678 0.316871029453\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318638343895 0.00170308013039 0.36442639234 0.316935263765\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.3185858934 0.0015906377339 0.364418850933 0.316995255667\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318536913498 0.00148562773249 0.364411800736 0.317051285766\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318491173806 0.00138755774864 0.364405210136 0.317103616058\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318448459329 0.00129596816386 0.364399049506 0.317152491165\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318408569419 0.00121042992125 0.364393291084 0.317198139497\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318371316807 0.0011305424778 0.364387908864 0.317240774329\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318336526703 0.0010559318958 0.364382878489 0.317280594807\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318304035957 0.000986249063808 0.364378177149 0.317317786893\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318273692274 0.000921168038026 0.36437378349 0.317352524236\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318245353488 0.000860384495848 0.36436967752 0.317384968992\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318218886882 0.000803614293751 0.364365840529 0.317415272588\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318194168558 0.000750592122388 0.364362255007 0.317443576435\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318171082842 0.000701070252194 0.364358904569 0.317470012589\n", + "the conc. of A,B,C,D after 10 secs respectively is 0.318149521739 0.000654817363294 0.364355773886 0.317494704375\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange\n", + "#given rxn A+B--k1-->C\n", + "# B+C--k2-->D\n", + "rc_k1=1 ; rc_k2=1 #rate constants\n", + "def f1a(x,A,B,C,D):\n", + " dA_by_dx=-A*B\n", + " return dA_by_dx\n", + "def f2a(x,A,B,C,D):\n", + " dB_by_dx=-A*B-B*C\n", + " return dB_by_dx\n", + "def f3a(x,A,B,C,D):\n", + " dC_by_dx=A*B-B*C\n", + " return dC_by_dx\n", + "def f4a(x,A,B,C,D):\n", + " dD_by_dx=B*C\n", + " return dD_by_dx\n", + "A=1 ; B=1 ; C=0 ;D=0\n", + "for x in arange(.1,10.1,0.1):\n", + " h=.1 #step increment of 0.1\n", + " k1=h*f1a(x,A,B,C,D)\n", + " l1=h*f2a(x,A,B,C,D)\n", + " m1=h*f3a(x,A,B,C,D)\n", + " n1=h*f4a(x,A,B,C,D)\n", + " k2=h*f1a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " l2=h*f2a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " m2=h*f3a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " n2=h*f4a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)\n", + " k3=h*f1a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " l3=h*f2a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " m3=h*f3a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " n3=h*f4a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)\n", + " k4=h*f1a(x+h,A+k3,B+l3,C+m3,D+n3)\n", + " l4=h*f2a(x+h,A+k3,B+l3,C+m3,D+n3)\n", + " m4=h*f3a(x+h,A+k3,B+l3,C+m3,D+n3)\n", + " n4=h*f4a(x+h,A+k3,B+l3,C+m3,D+n3)\n", + " A=A+(k1+2*k2+2*k3+k4)/6\n", + " B=B+(l1+2*l2+2*l3+l4)/6\n", + " C=C+(m1+2*m2+2*m3+m4)/6\n", + " D=D+(n1+2*n2+2*n3+n4)/6\n", + " if x==.5 or x==1 or x==2 or x==5:\n", + " print \"the conc. of A,B,C,D after\",x,\"secs is\",A,B,C,D\n", + " \n", + " print \"the conc. of A,B,C,D after 10 secs respectively is\",A,B,C,D" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 4.18 Page 75" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the height of the tower required for 90% conversion in mtrs is 199.2\n", + "the height of the tower required for 90% conversion in mtrs is 199.3\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,exp,pi\n", + "T=294.15\n", + "#rxn A-->B\n", + "R=8.314; rho=980.9; MW=200; U=1900; Cp=15.7; H_rxn=92900; T1=388.71; mdot=1.26; dia=2.54*10**-2; E=108847 #given data\n", + "b=E/(R*T1) ; k1=5.64*10**13*exp(-b); A=pi*dia**2/4; na0=mdot*1000/MW; Ts=388.71\n", + "k=k1*exp(b*(1-T1/T))\n", + "\n", + "#dX_by_dV=ra/na0\n", + "#dX_by_dV=k*(1-X)/F\n", + "#from energX balance\n", + "#mdot*Cp*dT_by_dz+ra*A*H_RXN-q=0\n", + "#q=U*pi*dia*(Ts-T)\n", + "#-mdot*Cp*dT_by_dV+4*U/dia*(Ts-T)-ra*H_rxn=0\n", + "F=mdot/rho\n", + "t1=A*k1/F\n", + "\n", + "s1=mdot*Cp/A\n", + "s2=4*U/dia\n", + "s3=H_rxn*t1\n", + "\n", + "def fg1(z,X,T):\n", + " dX_by_dz=t1*(1-X)*exp(b*(1-T1/T))\n", + " return dX_by_dz\n", + "def fd1(z,X,T):\n", + " ra=na0/A*(t1*(1-X)*exp(b*(1-T1/T)))\n", + " dT_by_dz=(ra*H_rxn-s2*(Ts-T))/-s1\n", + " return dT_by_dz\n", + " \n", + " \n", + "X=0 ; T=294.15\n", + "for z in arange(0,350.1,0.1):\n", + " h=.1 #szep incremenz of 0.1\n", + " k1=h*fg1(z,X,T)\n", + " l1=h*fd1(z,X,T)\n", + " k2=h*fg1(z+h/2,X+k1/2,T+l1/2)\n", + " l2=h*fd1(z+h/2,X+k1/2,T+l1/2)\n", + " k3=h*fg1(z+h/2,X+k2/2,T+l2/2)\n", + " l3=h*fd1(z+h/2,X+k2/2,T+l2/2)\n", + " k4=h*fg1(z+h,X+k3,T+l3)\n", + " l4=h*fd1(z+h,X+k3,T+l3)\n", + " X=X+(k1+2*k2+2*k3+k4)/6\n", + " T=T+(l1+2*l2+2*l3+l4)/6\n", + " #condition for height calc. for 90% conversion\n", + " if X>.9 and X<.9005 :\n", + " print \"the height of the tower required for 90% conversion in mtrs is\",z\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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter5.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter5.ipynb new file mode 100644 index 00000000..6ad157f3 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter5.ipynb @@ -0,0 +1,586 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 5 - Boundary Value Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.1 Page 87" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the value of y at x=.5 from finite difference method is -0.25\n", + "the value of y from exact soln at x=.5 is -0.25\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "\n", + "#finite difference method\n", + "#given d2y_by_dx2-2=0 hence it is dirichlet's problem\n", + "\n", + "x_1=0 ; y_1=0 #initial boundary conditions\n", + "x_3=1 ; y_3=0\n", + "\n", + "delta_x=.5 #since we have to find y_2 at x=.5 so x_2=.5 \n", + "#in the central difference method substituting i=2 we have\n", + "#(y_3-2*y_2+y_1)/(delta_x)**2=2\n", + "#since y_1 & y_3=0 as per B.C.\n", + "y_2=(y_3+y_1-2*delta_x**2)/2\n", + "print \"the value of y at x=.5 from finite difference method is\",y_2\n", + "x=.5\n", + "y_exact=x**2-x\n", + "print \"the value of y from exact soln at x=.5 is\",y_exact" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.2 Page 89" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "to solve this problem we will take delta x=.5 since we have to find the value at x=.5\n", + "the value of y at x=.5 is -0.25\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "#boundary conditions are: x=0 at y=0# dy/dx=1 at x=1\n", + "print \"to solve this problem we will take delta x=.5 since we have to find the value at x=.5\"\n", + "delta_x=.5\n", + "y_1=0\n", + "#using central difference eqn\n", + "dy_by_dx=1 #at x=1, i=3\n", + "#y_4=dy/dx*2*delta_x+y_2 sincefrom B.C. at node 3\n", + "\n", + "#y_2=delta_x**2+y_3-delta_x on substituting the value of y_4\n", + "y_3=-(2*delta_x**2+2*(delta_x**2-delta_x)-y_1) #on substituting the value of y_2\n", + "y_2=delta_x**2+y_3-delta_x\n", + "print \"the value of y at x=.5 is\",y_2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.3 Page 89" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " the solution of eg 5.3 -->Discretization in 1-D space\n", + "the value of y at x= 0.333333333333 0.666666666667 is respectively 0.111111111111 -0.222222222222\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange\n", + "print \"the solution of eg 5.3 -->Discretization in 1-D space\"\n", + "#given the source term f(x)=4x**2-2x-4\n", + "#given eqn d2y/dx2-2y=f(x)\n", + "y_1=0\n", + "y_4=-1\n", + "delta_x=1/3 #since given 3 parts and length=1\n", + "for i in range(0,4):\n", + " j=arange(0,1+delta_x,delta_x)\n", + "\n", + "#given to divide the line in 3 parts\n", + "#at node 2\n", + "#y_3-2*y_2\n", + "def fx3(x):\n", + " d=(4*x**2-2*x-4)\n", + " return d\n", + "f2=fx3(j[1])\n", + "f3=fx3(j[2])\n", + "y_3=((f2)*delta_x**2+(2+2*delta_x**2)*((f3)*delta_x**2-y_4)-y_1)/(1-(2+2*delta_x**2)**2)\n", + "y_2=(f3+2*y_3)*delta_x**2+2*y_3-y_4\n", + "print \"the value of y at x=\",j[1],j[2],\"is respectively\",y_2,y_3" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + " ## Exa 5.4 Page 90" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the exact analytical soln are\n", + "0.111111111111\n", + "-0.222222222222\n", + "-1.0\n", + "the value of f(x) at node 2 3 and 4 are -4.22222222222 -3.55555555556 -2.0\n", + "the values of y2, y3, y4 by TDMA method are\n", + "0.111111111111\n", + "-0.222222222222\n", + "-1.0\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,zeros\n", + "y_1=0\n", + "dy_by_dx=-3 #at x=1\n", + "delta_x=1/3 #since given 3 parts and length=1\n", + "for i in range(0,4):\n", + " j=arange(0,1+delta_x,delta_x)\n", + "\n", + "#given to divide the line in 3 parts\n", + "def fx3(x):\n", + " d=(4*x**2-2*x-4)\n", + " return d\n", + "\n", + "f2=fx3(j[1])\n", + "f3=fx3(j[2])\n", + "f4=fx3(j[3])\n", + "print \"the exact analytical soln are\"\n", + "y=[]\n", + "for i in range(1,4):\n", + " y.append(-2*j[i]**2+j[i])\n", + " print y[i-1]\n", + "\n", + "#using B.C.-2 at node 4 we get\n", + "#(y_5-y_3)/(2*delta_x)=-3\n", + "#eqn at node 2\n", + "#-20*y_2+9*y_3=f2\n", + "#at node 3\n", + "#9*y_2-20*y_3+9*y_4=f3\n", + "#at node 4\n", + "#18*y_3-20*y_4=16\n", + "print \"the value of f(x) at node 2 3 and 4 are\",f2,f3,f4\n", + "#now solving the equations using TDMA method \n", + "\n", + "a=[0,9,18] #sub diagonal assignment\n", + "\n", + "b=[]\n", + "for j in range(1,4):\n", + " b.append(-20) #main diagonal assignment\n", + "c=[]\n", + "for k in range(1,3):\n", + " c.append(9) #super diagonal assignment\n", + "\n", + "d=[f2,f3,16] #given values assignment\n", + "\n", + "i=1#\n", + "n=3#\n", + "beta1=[b[i-1]]# #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "x=zeros(n)\n", + "x[-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k# \n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of y2, y3, y4 by TDMA method are\"\n", + "for i in range(1,4):\n", + " print x[i-1]\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.5 Page 91" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the analytical soln are\n", + "0.648054273664\n", + "0.651297246159\n", + "0.661058620401\n", + "0.677436091507\n", + "0.70059357071\n", + "0.730762825846\n", + "0.768245800962\n", + "0.81341763827\n", + "0.8667304327\n", + "0.92871775662\n", + "the values of y from y1 to y10 by TDMA method are\n", + "0.648259699273\n", + "0.65150099777\n", + "0.661257306244\n", + "0.67762618778\n", + "0.700771331194\n", + "0.730924187921\n", + "0.768386286526\n", + "0.813532247997\n", + "0.866813531948\n", + "0.928762951218\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import cosh\n", + "from numpy import zeros\n", + "delta_x=.1\n", + "y_11=1\n", + "dy_by_dx_1=0 #dy/dx at x=0\n", + "# given eqn d2y/dx2=y\n", + "print \"the analytical soln are\"\n", + "y_an=[]\n", + "for i in range(1,11):\n", + " y_an.append(cosh((i-1)/10)/cosh(1))\n", + " print y_an[i-1]\n", + "\n", + "#using central difference method we have \n", + "#y(i-1) - (2+delat_x**2)y(i) + y(i+1)=0\n", + "#therefore the eqns can be solved using TDMA method\n", + "a=[None]\n", + "for i in range(2,11):\n", + " a.append(1) #sub diagonal assignment\n", + "b=[]\n", + "for j in range(1,11):\n", + " b.append(-2.01) #main diagonal assignment\n", + "\n", + "c=[2]\n", + "for k in range(2,10):\n", + " c.append(1) #super diagonal assignment\n", + "d=[]\n", + "for l in range(1,10):\n", + " d.append(0)\n", + " #given values assignment\n", + "d.append(-1)\n", + "i=1#\n", + "n=10#\n", + "beta1=[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "\n", + "x=zeros(10)\n", + "x[n-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of y from y1 to y10 by TDMA method are\"\n", + "for i in range(1,11):\n", + " print x[i-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.6 Page 92" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of T from T2 to T9 by TDMA method are\n", + "111.111111111\n", + "122.222222222\n", + "133.333333333\n", + "144.444444444\n", + "155.555555556\n", + "166.666666667\n", + "177.777777778\n", + "188.888888889\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "T_1=100 ; T_10=200\n", + "delta_x=(T_10-T_1)/9 #since 9 divisions are to be made\n", + "#using central difference method we get\n", + "#for node 2--> 2*T_2-T_3=100\n", + "a=[0]\n", + "for i in range(2,9):\n", + " a.append(-1) #sub diagonal assignment\n", + "b=[]\n", + "for j in range(1,9):\n", + " b.append(2) #main diagonal assignment\n", + "c=[]\n", + "for k in range(1,8):\n", + " c.append(-1) #super diagonal assignment\n", + "\n", + "d=[100]\n", + "for l in range(2,8):\n", + " d.append(0); #given values assignment\n", + "\n", + "d.append(200)\n", + "\n", + "\n", + "i=1;\n", + "n=8;\n", + "beta1=[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]]; #since c7=0\n", + "m=i+1;\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "\n", + "x=zeros(n) \n", + "x[-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i;\n", + "for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1];\n", + "\n", + "print \"the values of T from T2 to T9 by TDMA method are\"\n", + "for i in range(1,9):\n", + " print x[i-1]\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.7 Page 93" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of T from T1 to T4 in Celsius by TDMA method are\n", + "231.893171899\n", + "199.529667042\n", + "180.886766374\n", + "174.799288605\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "from numpy import zeros\n", + "dia=.02\n", + "l=.05\n", + "T_0=320\n", + "delta_x=l/4\n", + "k=50\n", + "h=100\n", + "T_surr=20\n", + "#B.C--> d(theta)/dx+h(theta)/k=0 at x=0.05\n", + "#let m=sqrt(hP/kA)\n", + "P=pi*dia\n", + "A=pi*dia**2/4\n", + "m=sqrt(h*P/(k*A))#\n", + "#using central difference method we get \n", + "#-theta(i-1)+(2+(m*delta_x**2)*theta(i)+theta(i+1))=0\n", + "theta_0=T_0-T_surr\n", + "#using B.C. at node 4 we get--> theta(5)=theta(3)-2h*theta(4)*delta_x/k\n", + "#now the eqns can be solved using TDMA method\n", + "a=[None]\n", + "for i in range(2,4):\n", + " a.append(-1 ) #sub diagonal assignment\n", + "\n", + "a.append(-2)\n", + "b=[]\n", + "for j in range(1,4):\n", + " b.append(2.0625)# #main diagonal assignment\n", + "\n", + "b.append(2.1125)\n", + "for k in range(1,4):\n", + " c.append(-1) #super diagonal assignment\n", + "d=[300]\n", + "for l in range(2,5):\n", + " d.append(0)\n", + " #given values assignment\n", + "\n", + "i=1#\n", + "n=4#\n", + "beta1=[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1-1]-a[j-1]*c[j-2-1]/beta1[j-1-1])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "\n", + "x=zeros(n) \n", + "x[n-1]=gamma1[n-1]# #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k#\n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of T from T1 to T4 in Celsius by TDMA method are\"\n", + "for i in range(1,5):\n", + " print x[i-1]-T_surr\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 5.8 Page 94" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of conc. at x=.5mm or at the 50th node is 0.730764441227\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi,sqrt\n", + "from numpy import zeros\n", + "\n", + "lnght=.001\n", + "k_const=.001\n", + "D=10**-9\n", + "delta_x=l/100\n", + "C=1 #in mol/m3\n", + "#B.C. are C=1 at x=0\n", + "# dC/dx=0 at x=10**-3 since at the end point conc. is const.\n", + "#using central difference method we get the following eqns which can be solved using TDMA method\n", + "a=[0]\n", + "for i in range(2,100):\n", + " a.append(1) #sub diagonal assignment\n", + "\n", + "a.append(2) #since C99=C100 using B.C. \n", + "\n", + "b=[]\n", + "for j in range(1,101):\n", + " b.append(-2.0001) #main diagonal assignment\n", + "\n", + "c=[]\n", + "for k in range(1,100):\n", + " c.append(1) #super diagonal assignment\n", + "\n", + "d=[-1]\n", + "for l in range(2,101):\n", + " d.append(0)\n", + " #given values assignment\n", + "i=1#\n", + "n=100#\n", + "beta1 =[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "\n", + "x=zeros(n) \n", + "x[n-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k# \n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of conc. at x=.5mm or at the 50th node is\",x[49]" + ] + } + ], + "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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter6_.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter6_.ipynb new file mode 100644 index 00000000..675b6be7 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter6_.ipynb @@ -0,0 +1,331 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 6 - Convection-Diffusion Problems" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 6.1 Page 106" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of conc. using CDS method for x=.84 to 1 are\n", + "0.000152415790276\n", + "0.000457247370828\n", + "0.00137174211248\n", + "0.00411522633745\n", + "0.0123456790123\n", + "0.037037037037\n", + "0.111111111111\n", + "0.333333333333\n", + "the values of conc. using CDS/UDS method for x=.84 to 1 are\n", + "0.00390625\n", + "0.0078125\n", + "0.015625\n", + "0.03125\n", + "0.0625\n", + "0.125\n", + "0.25\n", + "0.5\n", + "the analytical soln is\n", + "0.000335462627903\n", + "0.000911881965555\n", + "0.00247875217667\n", + "0.00673794699909\n", + "0.0183156388887\n", + "0.0497870683679\n", + "0.135335283237\n", + "0.367879441171\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros,exp\n", + "#given convective diffusive eqn--> -u*(dc/dx)+D*(d2C/dx2)=0\n", + "C_ini=0 #at x=0\n", + "C_end=1 #at x=1\n", + "\n", + "\n", + "#using central difference method for both diffusion and convective term \n", + "#-u*(C(i+1)-C(i-1))/(2*delta_x) + D*(C(i+1)+C(i-1)-2*C(i))/delta_x**2 = 0\n", + "delta_x=1/50\n", + "#on solving the given eqns and by using the given boundary eqns we have\n", + "Pe=50 #given \n", + "Pe_local=50*delta_x #u/D=50 as l=1\n", + "alpha=Pe_local-2 #co-eff of C(i+1)\n", + "Beta=Pe_local+2 #co-eff of C(i-1)\n", + "#multipling with -2*delta_x**2/D we get\n", + "#-(Pe_local+2)*C(i-1) + 4*C(i) + (Pe_local-2)*C(i+1)=0\n", + "#solving eqns using TDMA method\n", + "a=[0]\n", + "for i in range(2,50):\n", + " a.append(-Beta) #sub diagonal assignment\n", + "\n", + "b=[]\n", + "for j in range(1,50):\n", + " b.append(4) #main diagonal assignment\n", + "\n", + "c=[]\n", + "for k in range(1,49):\n", + " c.append(alpha) #super diagonal assignment\n", + "\n", + "d=zeros(49) \n", + "d[0]=Beta*C_ini\n", + "d[-1]=-alpha*C_end\n", + "for l in range(2,49):\n", + " d[l-1]=0\n", + " #given values assignment\n", + "i=1#\n", + "n=49#\n", + "beta1=[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "\n", + "x=zeros(n)\n", + "x[-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k#\n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of conc. using CDS method for x=.84 to 1 are\"\n", + "for i in range(42,50):\n", + " print x[i-1]\n", + " \n", + "#part (ii) using CDS and UDS method\n", + "#multipling with -delta_x**2/D we get\n", + "#-(Pe_local+1)*C(i-1) + (Pe_local+2)*C(i)-C(i+1)=0\n", + "BEta=Pe_local+2\n", + "Gamma=Pe_local+1\n", + "a=[0]\n", + "for i in range(2,50):\n", + " a.append(-Gamma) #sub diagonal assignment\n", + "b=[]\n", + "for j in range(1,50):\n", + " b.append(BEta) #main diagonal assignment\n", + "c=[]\n", + "for k in range(1,49):\n", + " c.append(-1) #super diagonal assignment\n", + "\n", + "d=zeros(49) \n", + "d[0]=Gamma*C_ini\n", + "d[-1]=C_end\n", + "for l in range(2,49):\n", + " d[l-1]=0 #given values assignment\n", + "i=1#\n", + "n=49#\n", + "beta1=[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1=[d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "x=zeros(n)\n", + "x[-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k# \n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of conc. using CDS/UDS method for x=.84 to 1 are\"\n", + "for i in range(42,50):\n", + " print x[i-1]\n", + "\n", + "print \"the analytical soln is\"\n", + "C_an=zeros(50)\n", + "for i in range(42,50):\n", + " C_an[i-1]=C_ini+((exp(Pe*.02*i)-1)*(C_end-C_ini)/(exp(Pe)-1))\n", + " print C_an[i-1] " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 6.2 Page 112" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of conc. using CDS method for x=.84 to 1 are\n", + "0.0390184408035\n", + "-0.0585276651261\n", + "0.0877914937683\n", + "-0.131687244573\n", + "0.197530862939\n", + "-0.296296298329\n", + "0.444444443573\n", + "-0.666666669281\n", + "the values of conc. using CDS/UDS method for x=.84 to 1 are\n", + "4.6650738021e-09\n", + "5.13158118231e-08\n", + "5.64473930054e-07\n", + "6.20921323059e-06\n", + "6.83013455365e-05\n", + "0.000751314800902\n", + "0.00826446280992\n", + "0.0909090909091\n", + "the analytical soln is\n", + "1.80485138785e-35\n", + "3.97544973591e-31\n", + "8.7565107627e-27\n", + "1.92874984796e-22\n", + "4.24835425529e-18\n", + "9.35762296884e-14\n", + "2.06115362244e-09\n", + "4.53999297625e-05\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros,exp\n", + "#given convective diffusive eqn--> -u*(dc/dx)+D*(d2C/dx2)=0\n", + "C_ini=0 #at x=0\n", + "C_end=1 #at x=1\n", + "\n", + "#using central difference method for both diffusion and convective term \n", + "#-u*(C(i+1)-C(i-1))/(2*delta_x) + D*(C(i+1)+C(i-1)-2*C(i))/delta_x**2 = 0\n", + "delta_x=1/50\n", + "#on solving the given eqns and by using the given boundary eqns we have\n", + "Pe=500 #given \n", + "Pe_local=500*delta_x #u/D=50 as l=1\n", + "alpha=Pe_local-2 #co-eff of C(i+1)\n", + "Beta=Pe_local+2 #co-eff of C(i-1)\n", + "#multipling with -2*delta_x**2/D we get\n", + "#-(Pe_local+2)*C(i-1) + 4*C(i) + (Pe_local-2)*C(i+1)=0\n", + "#solving eqns using TDMA method\n", + "a=[0]\n", + "for i in range(2,50):\n", + " a.append(-Beta) #sub diagonal assignment\n", + "b=[]\n", + "for j in range(1,50):\n", + " b.append(4) #main diagonal assignment\n", + "\n", + "c=[]\n", + "for k in range(1,49):\n", + " c.append(alpha)# #super diagonal assignment\n", + "\n", + "d=zeros(49)\n", + "d[0]=Beta*C_ini\n", + "d[-1]=-alpha*C_end\n", + "for l in range(2,49):\n", + " d[l-1]=0 #given values assignment\n", + "i=1#\n", + "n=49#\n", + "beta1=[b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1 = [d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "\n", + "x=zeros(n)\n", + "x[-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k# \n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "\n", + "print \"the values of conc. using CDS method for x=.84 to 1 are\"\n", + "for i in range(42,50):\n", + " print x[i-1]\n", + " \n", + "#part (ii) using CDS and UDS method\n", + "#multipling with -delta_x**2/D we get\n", + "#-(Pe_local+1)*C(i-1) + (Pe_local+2)*C(i)-C(i+1)=0\n", + "BEta=Pe_local+2\n", + "Gamma=Pe_local+1\n", + "a=[0]\n", + "for i in range(2,50):\n", + " a.append(-Gamma) #sub diagonal assignment\n", + "b=[]\n", + "for j in range(1,50):\n", + " b.append(BEta) #main diagonal assignment\n", + "c=[]\n", + "for k in range(1,49):\n", + " c.append(-1) #super diagonal assignment\n", + "\n", + "d=zeros(49)\n", + "d[0]=Gamma*C_ini\n", + "d[-1]=C_end\n", + "for l in range(2,49):\n", + " d[l-1]=0 #given values assignment\n", + "i=1#\n", + "n=49#\n", + "beta1 = [b[i-1]] #initial b is equal to beta since a1=0\n", + "gamma1 = [d[i-1]/beta1[i-1]] #since c7=0\n", + "m=i+1#\n", + "for j in range(m,n+1):\n", + " beta1.append(b[j-1]-a[j-1]*c[j-2]/beta1[j-2])\n", + " gamma1.append((d[j-1]-a[j-1]*gamma1[j-2])/beta1[j-1])\n", + "x=zeros(n)\n", + "x[-1]=gamma1[n-1] #since c7=0\n", + "n1=n-i#\n", + "for k in range(1,n1+1):\n", + " j=n-k# \n", + " x[j-1]=gamma1[j-1]-c[j-1]*x[j]/beta1[j-1]\n", + "print \"the values of conc. using CDS/UDS method for x=.84 to 1 are\"\n", + "for i in range(42,50):\n", + " print x[i-1]\n", + "\n", + "print \"the analytical soln is\"\n", + "C_an=zeros(50)\n", + "for i in range(42,50):\n", + " C_an[i-1]=C_ini+((exp(Pe*.02*i)-1)*(C_end-C_ini)/(exp(Pe)-1))\n", + " print C_an[i-1]\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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter7.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter7.ipynb new file mode 100644 index 00000000..61135da4 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter7.ipynb @@ -0,0 +1,278 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "# Chapter 7 - Tubular Reactor with Axial Dispersion" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 7.1 Page 122" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First Order Reaction-50 parts - \n", + "0.999699990083\n", + "3.12062838745e-11\n", + "0.000249850053626\n", + "8.66524048103e-08\n", + "0.000208139054698\n", + "7.22363767651e-08\n", + "0.000173451600052\n", + "6.01978238317e-08\n", + "0.0001445450073\n", + "5.01655498325e-08\n", + "0.000120455845492\n", + "4.18052053996e-08\n", + "0.000100381265215\n", + "3.48381549557e-08\n", + "8.36522160046e-05\n", + "2.90321989598e-08\n", + "6.97111480663e-05\n", + "2.41938351073e-08\n", + "5.80934301186e-05\n", + "2.01618092385e-08\n", + "4.84118640498e-05\n", + "1.68017410206e-08\n", + "4.03437802862e-05\n", + "1.40016452881e-08\n", + "3.36202837822e-05\n", + "1.16681997736e-08\n", + "2.80172922214e-05\n", + "9.72363484122e-09\n", + "2.33480677471e-05\n", + "8.10314156079e-09\n", + "1.94569933173e-05\n", + "6.75271174067e-09\n", + "1.62143862631e-05\n", + "5.62733792942e-09\n", + "1.35121761931e-05\n", + "4.6895133967e-09\n", + "1.12603031968e-05\n", + "3.90798209982e-09\n", + "9.38371630679e-06\n", + "3.25669697484e-09\n", + "7.81987218174e-06\n", + "2.71395183372e-09\n", + "6.51665064666e-06\n", + "2.26165793522e-09\n", + "5.43061761928e-06\n", + "1.88474111898e-09\n", + "4.52557752837e-06\n", + "1.57063941036e-09\n", + "3.77136697934e-06\n", + "1.30953827722e-09\n", + "3.14441964484e-06\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "e1=1 ; e2=1 #assumed values\n", + "u=1 ; D=10**-4 ; k=1 ; C_a_in=1 ; delta_x=10/50 #given data\n", + "cf_ca1_n1=-2*D/delta_x**2-3*u/delta_x-k-2*u**2/D #co-efficient of C-A1 at node 1\n", + "cf_ca2_n1=2*D/delta_x**2+u/delta_x\n", + "cf_da1_n1=-(2*u**2/D+2*u/delta_x)*C_a_in #right hand side co-efficient\n", + "cf_ca1_n2=D/delta_x**2+u/delta_x\n", + "cf_ca2_n2=-2*D/delta_x**2-u/delta_x-k\n", + "cf_ca3_n2=D/delta_x**2\n", + "cf_da1_n2=0\n", + "cf_ca2_n3=cf_ca1_n2\n", + "cf_ca3_n3=cf_ca2_n2\n", + "cf_ca4_n3=cf_ca3_n2\n", + "cf_da1_n3=0\n", + "cf_ca50_n51=2*D/delta_x**2+u/delta_x #co-efficient of C-A50 at node 51\n", + "cf_ca51_n51=-2*D/delta_x**2-u/delta_x-k\n", + "cf_da51_n51=0\n", + "a=[0]\n", + "for i in range(2,51):\n", + " a.append(cf_ca1_n2)\n", + " \n", + "a[49]=cf_ca2_n1\n", + "c=[cf_ca2_n1]\n", + "for i in range(2,51):\n", + " c.append(cf_ca3_n2)\n", + "\n", + "d=[cf_da1_n1]\n", + "for i in range(2,52):\n", + " d.append(cf_da1_n2)\n", + "x=[]\n", + "for i in range(1,52):\n", + " x.append(0)\n", + "\n", + "b=[cf_ca1_n1]\n", + "x1=[]\n", + "for i in range(2,52):\n", + " b.append(cf_ca2_n2)\n", + "while e1>1e-6 and e2>1e-6:\n", + " for i in range(1,52):\n", + " x1.append(x[i-1])\n", + "\n", + " i=1 ; n=51 ; Beta=[b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1,\n", + " for j in range(2,52):\n", + " Beta.append(b[j-1-1]-a[j-1-1]*c[j-2-1]/Beta[j-2-1])\n", + " Gamma.append((d[j-1]-a[j-1-1]*Gamma[j-2-1])/Beta[j-1-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k ; x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " e1=abs(x[(41)]-x1[(41)]); e2=abs(x[(17)]-x1[(17)])\n", + "\n", + "print \"First Order Reaction-50 parts - \"\n", + "for i in range(1,52):\n", + " print x[i-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 7.2 Page 131" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Second Order Reaction-20 parts\n", + "0.999899990007\n", + "-99989995.0013\n", + "-7.99620241884\n", + "-499875443627.0\n", + "-3.99760071124\n", + "-2.50037661937e+19\n", + "-3.99784153685\n", + "-1.25099285374e+31\n", + "-3.99749207478\n", + "-6.26163384772e+46\n", + "-3.99765851293\n", + "-3.13583861982e+66\n", + "-3.99757331924\n", + "-1.57118962175e+90\n", + "-3.9976154302\n", + "-7.87634360632e+117\n", + "-3.99759424268\n", + "-3.95035153098e+149\n", + "-3.99760512762\n", + "-1.98227988436e+185\n", + "-3.98527206101e-36\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "e1=1 ; e2=1\n", + "u=1 ; D=10**-4 ; k=1 ; C_a_in=1 ; delta_x=10/20\n", + "cff_ca2_n1=2*D/delta_x**2+u/delta_x #co-efficient of C-A2 at node 1\n", + "cff_da1_n1=-(2*u**2/D+2*u/delta_x)*C_a_in #right hand side co-efficient\n", + "cff_ca1_n2=D/delta_x**2+u/delta_x\n", + "cf_ca1_n2=D/delta_x**2+u/delta_x\n", + "cff_ca3_n2=D/delta_x**2 #co-efficient of C-A3 at node 2\n", + "cf_ca3_n2=D/delta_x**2\n", + "cff_da1_n2=0\n", + "cff_ca2_n3=cf_ca1_n2\n", + "cff_ca4_n3=cf_ca3_n2\n", + "cff_da1_n3=0\n", + "cff_ca20_n21=2*D/delta_x**2+u/delta_x #co-efficient of C-A20 at node 21\n", + "cff_da21_n21=0\n", + "a=[0]\n", + "\n", + "for i in range(2,21):\n", + " a.append(cff_ca1_n2)\n", + "\n", + "a.append(cff_ca2_n1) ; c=[cff_ca2_n1]\n", + "c=[0]\n", + "for i in range(2,21):\n", + " c.append(cff_ca3_n2)\n", + "\n", + "d=[cff_da1_n1]\n", + "for i in range(2,22):\n", + " d.append(cff_da1_n1)\n", + " \n", + "x=[] ; x1=[]\n", + "for i in range(1,22):\n", + " x.append(0) \n", + "\n", + "while e1>1e-6 and e2>1e-6:\n", + " for i in range(1,22):\n", + " x1.append(x[i-1])\n", + " cff_ca1_n1=-2*D/delta_x**2-3*u/delta_x-x1[0]-2*u**2/D # //main diagonal elements dependence on conc.\n", + " b=[cff_ca1_n1]\n", + " for i in range(2,22):\n", + " b.append(-2*D/delta_x**2-u/delta_x-x[i-1])\n", + "\n", + " #solving by TDMA method\n", + " i=1 ; n=21 ; Beta=[b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append((b[j-1]-a[j-1]*c[j-2])/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " e1=abs(x[0]-x1[0]) ; e2=abs(x[20]-x1[20])\n", + "\n", + "print \"Second Order Reaction-20 parts\" \n", + "for i in range(1,22):\n", + " print x[i-1]\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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter8.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter8.ipynb new file mode 100644 index 00000000..66f739dd --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter8.ipynb @@ -0,0 +1,392 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 8 - Chemical Reaction & Dissusion in a spherical Catalyst Pellet" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 8.1 Page 158" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution by TDMA of node 77 to 99 by 1st order rxn. is 1\n", + "2.11327608271e-05\n", + "-6.97708390547e-06\n", + "-6.19992402138e-05\n", + "2.04759969916e-05\n", + "0.000182009868277\n", + "-6.01295131167e-05\n", + "-0.000534648505839\n", + "0.000176680552708\n", + "0.0015714263084\n", + "-0.000519440824961\n", + "-0.00462125771268\n", + "0.00152798240852\n", + "0.0135974017665\n", + "-0.00449702200409\n", + "-0.0400286588926\n", + "0.0132417745751\n", + "0.117895160831\n", + "-0.0390097044184\n", + "-0.34739360391\n", + "0.114972976752\n", + "1.02409485606\n", + "-0.339006034307\n", + "-3.02025227398\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "x=[];x1=[]\n", + "for i in range(1,101):\n", + " x.append(0)\n", + "\n", + "Iter=0 ; e1=1 ; f=1\n", + "a=[0]\n", + "while e1>1e-6 and f>1e-6:\n", + " Iter=Iter+1\n", + " for i in range(1,101):\n", + " x1.append(x[i-1])\n", + " for i in range(2,101):\n", + " a.append(1-(1/(i-1)))\n", + " b=[-6.01]\n", + " for i in range(2,101):\n", + " b.append(-2.01)\n", + " c=[6]\n", + " for i in range(2,100):\n", + " c.append(1+(1/(i-1)))\n", + " #for i=1:99,d(i)=0, end, d(100)=-100/99,\n", + " d=zeros(100)\n", + " d[99]=-100/99\n", + " i=1 ; n=100 ; Beta = [b[i-1]]\n", + " Gamma = [d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append((b[j-1]-a[j-1]*c[j-2])/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " e1=abs(x[0]-x1[0])\n", + " f=abs(x[99]-x1[99])\n", + "\n", + "print \"the solution by TDMA of node 77 to 99 by 1st order rxn. is\",Iter\n", + "for i in range(78,101):\n", + " print x[i-1]\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 8.2 Page 162" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution by TDMA of node 77 to 99 by 2nd order rxn. is\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n", + "-0.0\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "x=zeros(100)\n", + "Iter=0 ; e1=1 ; f=1\n", + "k=.1 ; D=10**-9 ; r=.01 ; delta_r=r/10 ; t1=k*delta_r**2/D\n", + "x1=[]; a=[0] ; b=[0] ;d=[0]\n", + "while e1>1e-6 and f>1e-6:\n", + " Iter=Iter+1\n", + " for i in range(1,101):\n", + " x1.append(x[i-1])\n", + " for i in range(2,101):\n", + " a.append(1-(1/(i-1)))\n", + " b=[-6-t1*x1[0]]\n", + " for i in range(2,101):\n", + " b.append(-2-t1*x1[i-1])\n", + " c=[6]\n", + " for i in range(2,100):\n", + " c.append(1+(1/(i-1)))\n", + " for i in range(1,100):\n", + " d.append(0)\n", + " d.append(-100/99)\n", + " i=1 ; n=100 ; Beta=[b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j-1]/Beta[j-1]\n", + " e1=abs(x[0]-x1[0])\n", + " f=abs(x[99]-x1[99])\n", + "\n", + "print \"the solution by TDMA of node 77 to 99 by 2nd order rxn. is\"\n", + "for i in range(77,101):\n", + " print x[i-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 8.3 Page 163" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution by TDMA of node 77 to 100 by 1st order rxn. is\n", + "0.0604887704253\n", + "0.0678168756519\n", + "0.0760392035241\n", + "0.0852643022272\n", + "0.095613536562\n", + "0.107222479921\n", + "0.120242419314\n", + "0.134841969734\n", + "0.151208788326\n", + "0.169551370725\n", + "0.190100900502\n", + "0.213113107034\n", + "0.238870065591\n", + "0.26768184402\n", + "0.299887860369\n", + "0.335857761202\n", + "0.375991556122\n", + "0.420718642949\n", + "0.470495220437\n", + "0.525799398375\n", + "0.587123060992\n", + "0.654959197343\n", + "0.729782956961\n", + "0.812024100415\n", + "0.902027799616\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros,exp\n", + "x=zeros(100) ; x1=zeros(100); a=zeros(100) ; #initial values\n", + "\n", + "e2=1 ; f1=1 ; Iter=0 #assumed values\n", + "k=.1*10**-2 ; D=10**-9 ; r=.01 ; delta_r=r/100 ; t1=k*delta_r**2/D #given data\n", + "#now solving the eqns for all the nodes and then simplifying we get the following relations\n", + "d=[]\n", + "while e2>1e-6 and f1>1e-6:\n", + " Iter=Iter+1\n", + " for i in range(1,101):\n", + " x1[i-1]=x[i-1]\n", + " \n", + " for i in range(2,101):\n", + " a[i-1]=1-(1/(i-1))\n", + " b=[-6-t1*exp((1-x1[0])/(2-x1[0]))]\n", + " for i in range(2,101):\n", + " b.append(-2-t1*exp((1-x[i-1])/(2-x[i-1])))\n", + " c=[6]\n", + " for i in range(2,100):\n", + " c.append(1+(1/(i-1)))\n", + " for i in range(1,100):\n", + " d.append(0)\n", + " d.append(-100/99)\n", + " i=1 ; n=100 ; Beta = [b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n) \n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " e2=abs(x[0]-x1[0])\n", + " f1=abs(x[99]-x1[99])\n", + "\n", + "print \"the solution by TDMA of node 77 to 100 by 1st order rxn. is\"\n", + "for i in range(76,101):\n", + " print x[i-1]\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 8.4 Page 164" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the solution by TDMA of node 77 to 99 by 1st order rxn. is\n", + "0.0274150220283\n", + "0.0316615335985\n", + "0.0365714178414\n", + "0.0422488399165\n", + "0.0488143356681\n", + "0.0564073663768\n", + "0.0651892620654\n", + "0.0753466078611\n", + "0.087095133412\n", + "0.100684170249\n", + "0.116401745411\n", + "0.134580380148\n", + "0.155603657639\n", + "0.179913609207\n", + "0.208018937265\n", + "0.240504032341\n", + "0.278038627503\n", + "0.321387721808\n", + "0.371421006027\n", + "0.429120250921\n", + "0.495581544008\n", + "0.572005825625\n", + "0.659662934735\n", + "0.759791838019\n", + "0.873325342972\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros,exp\n", + "x=zeros(100);x=zeros(100)\n", + "Iter=0 ; e1=1 ; f1=1\n", + "while e1>1e-6 and f1>1e-6:\n", + " Iter=Iter+1\n", + " for i in range(1,101):\n", + " x1[i-1]=x[i-1]\n", + " for i in range(2,101):\n", + " a[i-1]=1-(1/(i-1))\n", + " b=[-6-.01*exp((10-10*x1[0])/(11-10*x1[0]))]\n", + " for i in range(2,101):\n", + " b.append(-2-.01*exp((10-10*x1[i-1])/(11-10*x1[i-1])))\n", + " c=[6]; d= []\n", + " for i in range(2,100):\n", + " c.append(1+(1/(i-1)))\n", + " for i in range(1,100):\n", + " d.append(0)\n", + " d.append(-100/99)\n", + " i=1 ; n=100 ; \n", + " Beta=[b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " e1=abs(x[0]-x1[0])\n", + " f1=abs(x[99]-x1[99])\n", + "\n", + "print \"the solution by TDMA of node 77 to 99 by 1st order rxn. is\"\n", + "for i in range(76,101):\n", + " print x[i-1]" + ] + } + ], + "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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter9.ipynb b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter9.ipynb new file mode 100644 index 00000000..a61b49d1 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/chapter9.ipynb @@ -0,0 +1,463 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 9 - One Dimensional Transient Heat Conduction" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 9.1 Page 174" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the values of Temp measured from centre at the gap of .2 cm are\n", + "31.914893617\n", + "37.8723404255\n", + "61.7021276596\n", + "127.234042553\n", + "-----------------\n", + "----------END---------\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import arange,zeros\n", + "print \"the values of Temp measured from centre at the gap of .2 cm are\"\n", + "alpha=10**-5 ; delta_t=.1 ; delta_x=10**-3 #given data\n", + "m=alpha*delta_t/(delta_x**2)\n", + "a=[0]\n", + "for i in range(2,5):\n", + " a.append(m) #sub-diagonal\n", + "\n", + "b=[(-2*m-1)/2]\n", + "for i in range(2,5):\n", + " b.append(-2*m-1) #diagonal\n", + "c=[]\n", + "for i in range(1,4):\n", + " c.append(m) #super-diagonal\n", + "x=[]\n", + "for i in range(1,5):\n", + " x.append(20) #initial temperature\n", + "y=[]\n", + "for t in arange(0.1,3.2,.1):\n", + " for i in range(1,5):\n", + " y.append(x[i-1])\n", + " #TDMA method\n", + " d=[-.5*y[0],\n", + " -y[1],\n", + " -y[2],\n", + " -y[3]-300]\n", + " i=1 ; n=4\n", + " Beta=[b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + "for i in range(1,5):\n", + " print x[i-1] #solution of temperature\n", + "\n", + "print \"-----------------\"\n", + "\n", + "print \"----------END---------\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 9.2 Page 175" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "time when centre temp is 425 K in secs. is\n", + "2860\n", + "the values of temp. at req. time is\n", + "415.830778173\n", + "409.161921067\n", + "407.289372709\n", + "412.10629054\n", + "424.920334418\n", + "446.302352324\n", + "475.988566837\n", + "512.861107143\n", + "555.026826929\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros\n", + "delta_t=1 ; delta_x=.05 ; alpha=10**-5\n", + "t1=alpha*delta_t/delta_x**2\n", + "a=[0]\n", + "for i in range(2,10):\n", + " a.append(-t1)\n", + "\n", + "b=[]\n", + "for i in range(1,10):\n", + " b.append(1+2*t1)\n", + "\n", + "c=[]\n", + "for i in range(1,9):\n", + " c.append(-t1)\n", + "\n", + "\n", + "t=1 ; tf=3000\n", + "x=[]\n", + "for i in range(1,10):\n", + " x.append(300)\n", + "\n", + "e1=425\n", + "print \"time when centre temp is 425 K in secs. is\"\n", + "y=zeros(10)\n", + "for t in range(1,tf+1):\n", + " for i in range(1,10):\n", + " y[i-1]=x[i-1]\n", + " d=zeros(9)\n", + " d[0]=y[0]+1.7\n", + " d[8]=y[8]+2.4\n", + " \n", + " for i in range(2,9):\n", + " d[i-1]=y[i-1]\n", + " \n", + " i=1 ; n=9\n", + " Beta=[b[i]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " \n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " if abs(x[4]-e1)>0 and abs(x[4]-e1)<.1:\n", + " print t\n", + " break\n", + " \n", + "\n", + "print \"the values of temp. at req. time is\"\n", + "for i in range(1,10):\n", + " print x[i-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 9.3 Page 176" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T1,T2,T2 & T4 at time interval of .1 sec is\n", + "145.908706385 81.3038645321 55.3676141531 48.2940913225\n", + "--------------------\n", + "203.484090902 137.507282499 102.483825782 91.6458788902\n", + "--------------------\n", + "234.561182928 180.311474047 146.967547978 135.90321416\n", + "--------------------\n", + "253.657260062 211.777427681 183.93231189 174.326492344\n", + "--------------------\n", + "266.42505656 234.835425713 212.930038344 205.209329144\n", + "--------------------\n", + "275.387525045 251.785736583 235.049836974 229.081735408\n", + "--------------------\n", + "281.845998761 264.286279996 251.687473273 247.1663257\n", + "--------------------\n", + "286.564174449 273.5252396 264.112294324 260.723100599\n", + "--------------------\n", + "290.035348701 280.36239094 273.35699646 270.830217288\n", + "--------------------\n", + "292.598329474 285.425737959 280.222548126 278.344081958\n", + "--------------------\n", + "294.494232563 289.176912624 285.316278945 283.921839548\n", + "--------------------\n", + "295.898007646 291.956531063 289.093561344 288.059216985\n", + "--------------------\n", + "296.937902328 294.016445785 291.893904508 291.126967003\n", + "--------------------\n", + "297.708431547 295.543088011 293.969705086 293.40115747\n", + "--------------------\n", + "298.279442258 296.674544089 295.50832191 295.086889022\n", + "--------------------\n", + "298.702624888 297.513124139 296.648729623 296.336361503\n", + "--------------------\n", + "299.01626097 298.134643482 297.49397346 297.262451069\n", + "--------------------\n", + "299.248712123 298.595288596 298.12044287 297.94884451\n", + "--------------------\n", + "299.420994656 298.936700895 298.584761024 298.457577721\n", + "--------------------\n", + "299.548683446 299.189742715 298.928897257 298.83463335\n", + "--------------------\n", + "299.643321393 299.377287795 299.183958571 299.114093527\n", + "--------------------\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros,arange\n", + "delta_t=.1 ; delta_r=.001 ;alpha=10**-5 #given data\n", + "t1=alpha*delta_t/delta_r**2\n", + "a=[0,\n", + ".5*t1,.75*t1,.833*t1] #sub-diagonal\n", + "b=[-4*t1-1]\n", + "for i in range(2,5):\n", + " b.append(-2*t1-1) #main diagonal\n", + "\n", + "c=[4*t1,1.5*t1,1.25*t1] #super-diagonal\n", + "x=[]\n", + "for i in range(1,5):\n", + " x.append(20)\n", + "\n", + "print \"T1,T2,T2 & T4 at time interval of .1 sec is\"\n", + "y=zeros(5)\n", + "d=zeros(5)\n", + "for t in arange(.1,2.2,.1):\n", + " for i in range(1,5):\n", + " y[i-1]=x[i-1] #TDMA Method\n", + " \n", + " d[3]=-y[3]-7*t1*300/6\n", + " for i in range(1,4):\n", + " d[i-1]=-y[i-1]\n", + " \n", + " i=1 ; n=4\n", + " Beta=[b[i-1]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " print x[3],x[2],x[1],x[0]\n", + " print \"--------------------\"\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 9.4 Page 178" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "T1,T2,T2 & T4 at time interval of .1 sec is\n", + "257.170280019 171.439218947 42.8591053357 85.7098332796\n", + "-------------------\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from numpy import zeros,arange\n", + "delta_t=.1 ; delta_r=.001 ; alpha=10**-5\n", + "t1=alpha*delta_t/delta_r**2\n", + "\n", + "a=[0,0,.5,.667]\n", + "b=[-7*t1]\n", + "for i in range(2,):\n", + " b.append(-3)\n", + "\n", + "x=[6,2,1.5]\n", + "x=[]\n", + "for i in range(1,5):\n", + " x.append(20)\n", + "\n", + "print \"T1,T2,T2 & T4 at time interval of .1 sec is\"\n", + "y=zeros(4) ; d=zeros(4)\n", + "for t in arange(.1,1.5,.1):\n", + " for i in range(1,5):\n", + " y[i-1]=x[i-1]\n", + " \n", + " d[3]=-y[3]-400\n", + " for i in range(1,4):\n", + " d[i-1]=-y[i-1]\n", + " \n", + " i=1 ; n=4\n", + " Beta=[b[i]]\n", + " Gamma=[d[i-1]/Beta[i-1]]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta.append(b[j-2]-a[j-1]*c[j-2]/Beta[j-2])\n", + " Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])\n", + " x=zeros(n)\n", + " x[-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + "print x[3],x[2],x[1],x[0]\n", + "print \"-------------------\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exa 9.5 Page 184" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the initial conc. of drug is 69.0789433935\n", + "Conc. at centre at t=3hr, 12 hr, 24 hr,48 hr is\n", + "0.0\n", + "0.0\n", + "0.0\n", + "0.0\n" + ] + } + ], + "source": [ + "from __future__ import division\n", + "from math import pi\n", + "from numpy import arange,zeros\n", + "R=.326 ; D=3*10^-7\n", + "delta_t=1 ; delta_r=.0326 ; conc_ini=10/(1.33*pi*R**3)\n", + "t1=D*delta_t/delta_r**2\n", + "print \"the initial conc. of drug is\",conc_ini\n", + "a=[0]\n", + "for i in range(2,11):\n", + " a.append(-(1-1/(i-1)))\n", + "\n", + "b=[591.4]\n", + "for i in range(2,11):\n", + " b.append(3544.5)\n", + "\n", + "c=[-1]\n", + "for i in range(2,10):\n", + " c.append(-(1+1/(i-1)))\n", + "x=[]\n", + "for i in range(1,11):\n", + " x.append(conc_ini)\n", + "#y=[]\n", + "y=zeros(10)\n", + "d=zeros(10)\n", + "Beta=zeros(10)\n", + "Gamma=zeros(10)\n", + "x=zeros(10)\n", + "print \"Conc. at centre at t=3hr, 12 hr, 24 hr,48 hr is\"\n", + "for t in arange(1,172800+delta_t,delta_t):\n", + " for i in range(1,11):\n", + " y[i-1]=x[i-1]\n", + " d[0]=y[0]*590.4\n", + " for i in range(2,11):\n", + " d[i-1]=3542.5*y[i-1]\n", + " \n", + " i=1 ; n=10\n", + " Beta[i-1]=b[i-1]\n", + " Gamma[i-1]=d[i-1]/Beta[i-1]\n", + " i1=i+1\n", + " for j in range(i1,n+1):\n", + " Beta[j-1]=b[j-1]-a[j-1]*c[j-2]/Beta[j-2]\n", + " Gamma[j-1]=(d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1]\n", + " \n", + " x[n-1]=Gamma[n-1]\n", + " n1=n-i\n", + " for k in range(1,n1+1):\n", + " j=n-k\n", + " x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]\n", + " \n", + " if t==10800 or t==43200 or t==86400 or t==172800:\n", + " print x[5]\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/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/gauss_elimination_method.png b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/gauss_elimination_method.png Binary files differnew file mode 100644 index 00000000..21a2415e --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/gauss_elimination_method.png diff --git a/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/solution_by_tdma_method.png b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/solution_by_tdma_method.png Binary files differnew file mode 100644 index 00000000..4843f486 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/solution_by_tdma_method.png diff --git a/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/valueofx123.png b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/valueofx123.png Binary files differnew file mode 100644 index 00000000..890680e6 --- /dev/null +++ b/Introduction_To_Numerical_Methods_In_Chemical_Engineering_by_P._Ahuja/screenshots/valueofx123.png |