{ "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 }