Chapter 4 - Initial Value Problems

Exa 4.1 Page 55

In [1]:
from numpy import arange,exp
from __future__ import division
# in this problem dy/dx=x+y
x_0=0 ; y_0=0                #initial values given


def fs(x,y):
    ydash=x+y
    return ydash

for x_0 in arange(0,0.3,0.1):
    h=0.1                                    #step increment of 0.1
    f_0=fs(x_0,y_0)
    k1=h*f_0
    k2=h*fs(x_0+h/2,y_0+k1/2)
    k3=h*fs(x_0+h/2,y_0+k2/2)
    k4=h*fs(x_0+h,y_0+k3)
    y_0=y_0+(k1+2*k2+2*k3+k4)/6

y_0=y_0-(k1+2*k2+2*k3+k4)/6                    #to get value at x=0.2
print "the value of y at x=.2 using Runge Kutta method is",y_0
ae=exp(x_0)-x_0-1                                  #analytical eqn given
print "the value of y at x=0.2 from analytical eqn is",ae
the value of y at x=.2 using Runge Kutta method is 0.0214025708507
the value of y at x=0.2 from analytical eqn is 0.0214027581602

Exa 4.2 Page 57

In [2]:
from numpy import arange,exp
from __future__ import division
# in this problem dy/dx=-y/(1+x)
x_0=0; y_0=2                 #initial values given

def fr(x,y):
    ydash=-y/(1+x)
    return ydash
for x_0 in arange(0,2.5+0.01,0.01):
    h=0.01                                    #step increment of 0.01
    f_0=fr(x_0,y_0)
    k1=h*f_0
    k2=h*fr(x_0+h/2,y_0+k1/2)
    k3=h*fr(x_0+h/2,y_0+k2/2)
    k4=h*fr(x_0+h,y_0+k3)
    y_0=y_0+(k1+2*k2+2*k3+k4)/6

y_0=y_0-(k1+2*k2+2*k3+k4)/6                    #final value at x=2.5
print "the value of y at x=2.5 using Runge Kutta method is",y_0
the value of y at x=2.5 using Runge Kutta method is 0.571428571429

Exa 4.3 Page 58

In [8]:
from numpy import arange,exp,pi
from __future__ import division
rho=1000; v=1; dia=2.4*10**-2; Cp=4184             #given data 
mdot=rho*v*pi*dia**2/4
t1=mdot*Cp
U=200
Ts=250
z=0                 #initial values given
# dT/dz=U*pi*dia*(Ts-T)/(mdot*Cp)
def fr(z,T):
    Tgrad=U*pi*dia*(Ts-T)/(mdot*Cp)
    return Tgrad
T=20
for z in arange(0,10+0.01,0.01):
    h=0.01                                    #step increment of 0.01
    k1=h*fr(z,T)
    k2=h*fr(z+h/2,T+k1/2)
    k3=h*fr(z+h/2,T+k2/2)
    k4=h*fr(z+h,T+k3)
    T=T+(k1+2*k2+2*k3+k4)/6
    if z==5 :
        T=T-(k1+2*k2+2*k3+k4)/6
        print "the value of T in deg Celsius at z=5 m using Runge Kutta method is",T
    
T=T-(k1+2*k2+2*k3+k4)/6                    #final value at z=10 m
print "the value of T in deg Celsius at z=10 m using Runge Kutta method is",T
the value of T in deg Celsius at z=5 m using Runge Kutta method is 28.9818069623
the value of T in deg Celsius at z=10 m using Runge Kutta method is 37.5959411201

Exa 4.4 Page 59

In [1]:
from __future__ import division
from numpy import arange
vol=.5*.5*2                        #given data
rho=1000
m=vol*rho
vol_rate=.001
mdot=vol_rate*rho
out_A=1
U=200
Cp=4184
T1=20; Ts=250; T_exit=28                           #temp in Celsius
t1=(mdot*Cp*T1+U*out_A*Ts)/(m*Cp)                  #terms of the function
t2=(mdot*Cp+U*out_A)/(m*Cp)
#dt/dt=(mdot*Cp(T1-T)+Q_dot)/m*Cp
def fv(tm,T):
    tgrad=t1-t2*T
    return tgrad
T=20                                             #initial value

for tm in arange(0,5001,1):
    h=1                                    #step increment of 1 sec
    k1=h*fv(tm,T)
    k2=h*fv(tm+h/2,T+k1/2)
    k3=h*fv(tm+h/2,T+k2/2)
    k4=h*fv(tm+h,T+k3)
    e1=abs(T-T_exit)
    if e1<1e-3 :
        print "the time at which exit temp. in sec. is 28 C is",tm
    
    T=T+(k1+2*k2+2*k3+k4)/6
    
T=T-(k1+2*k2+2*k3+k4)/6                   #final  steady state temp.
print "the value of steady Temp in Celsius is",T
the time at which exit temp. in sec. is 28 C is 686
the value of steady Temp in Celsius is 30.4924053747

Exa 4.5 Page 62

In [2]:
from __future__ import division
from numpy import arange
m=760                                         #given data
mdot=12/60
U_into_A=11.5/60
Cp=2.3
T1=25; Ts=150
t1=(mdot*Cp*T1+U_into_A*Ts)/(m*Cp)
t2=(mdot*Cp+U_into_A)/(m*Cp)
#using energy balance we know accumulation=input-output
#T is the temp. of fluid in stirred tank
def fg(t,T):
    tgrade=(t1-t2*T)
    return tgrade
T=25
for t in arange(0,3001,1):
    h=1                                    #step increment of 1 sec
    k1=h*fg(t,T)
    k2=h*fg(t+h/2,T+k1/2)
    k3=h*fg(t+h/2,T+k2/2)
    k4=h*fg(t+h,T+k3)
    T=T+(k1+2*k2+2*k3+k4)/6
    
T=T-(k1+2*k2+2*k3+k4)/6                    #to get value at x=0.2
print "the value of T in deg C after 50 mins is",T
T_steady=(mdot*Cp*T1+U_into_A*Ts)/(mdot*Cp+U_into_A)
print "the steady state temp in deg C is",T_steady
the value of T in deg C after 50 mins is 49.7501698463
the steady state temp in deg C is 61.7647058824

Exa 4.6 Page 64

In [3]:
from __future__ import division
from numpy import arange,sqrt,pi

dia=3*10**-4                             #given data
v_sprfcl=12
rho_p=900
meu=1.8*10**-5
P=101325
T=298.15
R=8.314
M=28.84*10**-3
rho_air=P*M/(R*T)
proj_A=pi*(dia**2)/4
volm=pi*(dia**3)/6
t1=rho_air*proj_A/(volm*rho_p)                        #terms of the function
t2=((rho_air/rho_p)-1)*9.81*2
y=0
for z in arange(.01,10.01,0.01):
    h=.01
    vn1=sqrt(y)
    Re=rho_air*(12-vn1)*dia/meu
    Cd=24*(1+.15*Re**.687)/Re
    def fy(z,y):
        dy_by_dz=t1*Cd*(12-sqrt(y))**2+t2
        return dy_by_dz

    kk1=h*fy(z,y)
    kk2=h*fy(z+h/2,y+kk1/2)
    kk3=h*fy(z+h/2,y+kk2/2)
    kk4=h*fy(z+h,y+kk3)
    y=y+(kk1+2*kk2+2*kk3+kk4)/6
    
v=sqrt(y)                    #final value of velocity
print "the value of v at the end of the pneumatic conveyor is",v
the value of v at the end of the pneumatic conveyor is 10.9043471355

Exa 4.7 Page 65

In [1]:
from __future__ import division
from numpy import arange,exp
def fw(t,x,y):
    dx_dt=x+2*y
    return dx_dt
def fq(t,x,y):
    dy_dt=3*x+2*y
    return dy_dt
y=4;x=6                         #initial values
#solving by Runge-Kutta method
for t in arange(0,.3,.1):
    h=.1                                    #step increment of 0.1
    k1=h*fw(t,x,y)
    l1=h*fq(t,x,y)
    k2=h*fw(t+h/2,x+k1/2,y+l1/2)
    l2=h*fq(t+h/2,x+k1/2,y+l1/2)
    k3=h*fw(t+h/2,x+k2/2,y+l2/2)
    l3=h*fq(t+h/2,x+k2/2,y+l2/2)
    k4=h*fw(t+h,x+k3,y+l3)
    l4=h*fq(t+h,x+k3,y+l3)
    x=x+(k1+2*k2+2*k3+k4)/6
    y=y+(l1+2*l2+2*l3+l4)/6
    
x=x-(k1+2*k2+2*k3+k4)/6
y=y-(l1+2*l2+2*l3+l4)/6
print "the values of x and y repectively are",x,y
t_an=.2
x_an=4*exp(4*t)+2*exp(-t)
y_an=6*exp(4*t)-2*exp(-t)
print "the analytical values of x and y are respectively",x_an,y_an
the values of x and y repectively are 10.5385351539 11.7141482239
the analytical values of x and y are respectively 10.5396252201 11.7157840648

Exa 4.8 Page 66

In [1]:
from __future__ import division
from numpy import arange,exp
from math import atan,exp,sin,cos
def fw(x,y,z):
    dy_dx=z
    return dy_dx
    
def fq(x,y,z):
    dz_dx=-y
    return dz_dx
y=2; z=1                          #initial values
for x in arange(0,3.1,0.1):
    h=.1                                    #step increment of 0.1
    k1=h*fw(x,y,z)
    l1=h*fq(x,y,z)
    k2=h*fw(x+h/2,y+k1/2,z+l1/2)
    l2=h*fq(x+h/2,y+k1/2,z+l1/2)
    k3=h*fw(x+h/2,y+k2/2,z+l2/2)
    l3=h*fq(x+h/2,y+k2/2,z+l2/2)
    k4=h*fw(x+h,y+k3,z+l3)
    l4=h*fq(x+h,y+k3,z+l3)
    y=y+(k1+2*k2+2*k3+k4)/6
    z=z+(l1+2*l2+2*l3+l4)/6
    
y=y-(k1+2*k2+2*k3+k4)/6
z=z-(l1+2*l2+2*l3+l4)/6
print "the values of y and z respectively are",y,z
# for the given analytical eqns the values of A and alpha can be determined using initial values of y and z
alpha=atan(2)
A=2/sin(alpha)
y_an=A*sin(alpha+x)
z_an=A*cos(alpha+x)
print "the analytical values of y and z are",y_an,z_an
the values of y and z respectively are -1.83886143329 -1.27223682875
the analytical values of y and z are -1.83886498514 -1.27223251272

Exa 4.9 Page 67

In [2]:
from __future__ import division
from numpy import arange
def fw(x,y,z):                  #let us have dy/dx=z, therefore d2y/dx2=dz/dx
    dy_dx=z
    return dy_dx
def fq(x,y,z):
    dz_dx=-y*x
    return dz_dx
y=2 ; z=1
for x in arange(0,3.1,0.1):
    h=0.1                                    #step increment of 0.1
    k1=h*fw(x,y,z)
    l1=h*fq(x,y,z)
    k2=h*fw(x+h/2,y+k1/2,z+l1/2)
    l2=h*fq(x+h/2,y+k1/2,z+l1/2)
    k3=h*fw(x+h/2,y+k2/2,z+l2/2)
    l3=h*fq(x+h/2,y+k2/2,z+l2/2)
    k4=h*fw(x+h,y+k3,z+l3)
    l4=h*fq(x+h,y+k3,z+l3)
    y=y+(k1+2*k2+2*k3+k4)/6
    z=z+(l1+2*l2+2*l3+l4)/6
    
y=y-(k1+2*k2+2*k3+k4)/6
z=z-(l1+2*l2+2*l3+l4)/6
print "the values of y and z repectively are",y,z
the values of y and z repectively are -1.90009675418 -1.14870918402

Exa 4.10 Page 67

In [1]:
from __future__ import division
from numpy import arange,exp

Cp=2000 ; A=1 ; U=200 ; m=1000 ; mdot=2;  Ts=250                 #given data
T0=20;  T1=0;  T2=0 ; T3=0

#from energy balances for the tanks we have accumulation=inlet-outlet
T1_steady=(mdot*Cp*(T0)+U*A*(Ts))/(mdot*Cp+U*A)
print "the steady state temperature of tank 1 is",T1_steady
T2_steady=(mdot*Cp*(T1_steady)+U*A*(Ts))/(mdot*Cp+U*A)
print "the steady state temperature of tank 2 is",T2_steady
T3_steady=(mdot*Cp*(T2_steady)+U*A*(Ts))/(mdot*Cp+U*A)
print "the steady state temperature of tank 3 is",T3_steady
final_T3=.99*T3_steady
def f1(t,T1,T2,T3):
    dT1_by_dt=(mdot*Cp*(T0-T1)+U*A*(Ts-T1))/(m*Cp)
    return dT1_by_dt
def f2(t,T1,T2,T3):
    dT2_by_dt=(mdot*Cp*(T1-T2)+U*A*(Ts-T2))/(m*Cp)
    return dT2_by_dt
def f3(t,T1,T2,T3):
    dT3_by_dt=(mdot*Cp*(T2-T3)+U*A*(Ts-T3))/(m*Cp)
    return dT3_by_dt
T1=20 ; T2=20 ; T3=20
#solving by Newton's Method
for t in arange(0,10001,1):
    h=1                                    #step increment of 1
    k1=h*f1(t,T1,T2,T3)
    l1=h*f2(t,T1,T2,T3)
    m1=h*f3(t,T1,T2,T3)
    k2=h*f1(t+h/2,T1+k1/2,T2+l1/2,T3+m1/2)
    l2=h*f2(t+h/2,T1+k1/2,T2+l1/2,T3+m1/2)
    m2=h*f3(t+h/2,T1+k1/2,T2+l1/2,T3+m1/2)
    k3=h*f1(t+h/2,T1+k2/2,T2+l2/2,T3+m2/2)
    l3=h*f2(t+h/2,T1+k2/2,T2+l2/2,T3+m2/2)
    m3=h*f3(t+h/2,T1+k2/2,T2+l2/2,T3+m2/2)
    k4=h*f1(t+h,T1+k3,T2+l3,T3+m3)
    l4=h*f2(t+h,T1+k3,T2+l3,T3+m3)
    m4=h*f3(t+h,T1+k3,T2+l3,T3+m3)
    T1=T1+(k1+2*k2+2*k3+k4)/6
    T2=T2+(l1+2*l2+2*l3+l4)/6
    e1=abs(T3-final_T3)
    if e1<1e-3:
        print "the approx. time when Temperature in 3rd tank is 99% of steady value is",t
    T3=T3+(m1+2*m2+2*m3+m4)/6
the steady state temperature of tank 1 is 30.9523809524
the steady state temperature of tank 2 is 41.3832199546
the steady state temperature of tank 3 is 51.3173523378
the approx. time when Temperature in 3rd tank is 99% of steady value is 3150
the approx. time when Temperature in 3rd tank is 99% of steady value is 3151

Exa 4.11 Page 68

In [1]:
from __future__ import division
from numpy import arange,exp
#rxn given A--> B
rate_const_k=1
def fs1(t,Ca):
    dCa_by_dt=-rate_const_k*Ca
    return dCa_by_dt
Ca=1
for t in arange(0.1,3.1,0.1):
    h=0.1                                    #step increment of 0.1
    k1=h*fs1(t,Ca)
    k2=h*fs1(t+h/2,Ca+k1/2)
    k3=h*fs1(t+h/2,Ca+k2/2)
    k4=h*fs1(t+h,Ca+k3)
    Ca=Ca+(k1+2*k2+2*k3+k4)/6

print "the value of conc. at t=3 using Runge Kutta method is",Ca
Ca_anl=exp(-t)                   #analytical solution
print "the analytical soln. is",Ca_anl
the value of conc. at t=3 using Runge Kutta method is 0.0497872036658
the analytical soln. is 0.0497870683679

Exa 4.12 Page 69

In [1]:
from __future__ import division
from numpy import arange,exp
#rxn A-->B
#input=FCa0, output=FCa
#applying mass balance of component A we get d(V*Ca)/dt=F*Ca0-F*Ca-k*Ca*V
rate_const_k=1
Ca0=1 ; F=1 ;  V=10

def fr(t,Ca1):
    dVCa_by_dt=F*Ca0-F*Ca1-rate_const_k*Ca1*V
    return dVCa_by_dt
Ca1=1
for t in arange(0.1,10.1,0.1):
    h=0.1                                    #step increment of 0.1
    k1=h*fr(t,Ca1)
    k2=h*fr(t+h/2,Ca1+k1/2)
    k3=h*fr(t+h/2,Ca1+k2/2)
    k4=h*fr(t+h,Ca1+k3)
    Ca1=Ca1+(k1+2*k2+2*k3+k4)/6
                    #final value
print "the value of Ca at t=10 s using Runge Kutta method is",Ca1
Ca_steady=F*Ca0/(F+rate_const_k*V)
print "the steady state value of conc. is",Ca_steady
the value of Ca at t=10 s using Runge Kutta method is 0.0909090909091
the steady state value of conc. is 0.0909090909091

Exa 4.13 Page 70

In [1]:
from __future__ import division
from numpy import arange,exp

#given rxn A-->B-->C
k1=1;  k2=1                 #given data
def f1a(t,A,B,C):                   #functions defined
    dA_by_dt=-A
    return dA_by_dt
def f2a(t,A,B,C):
    dB_by_dt=A-B
    return dB_by_dt
def f3a(t,A,B,C):
    dC_by_dt=B
    return dC_by_dt
A=1 ;B=0 ;C=0                       #initial values
for t in arange(0.1,10.1,0.1):
    h=.1                                    #step increment of 0.1
    k1=h*f1a(t,A,B,C)
    l1=h*f2a(t,A,B,C)
    m1=h*f3a(t,A,B,C)
    k2=h*f1a(t+h/2,A+k1/2,B+l1/2,C+m1/2)
    l2=h*f2a(t+h/2,A+k1/2,B+l1/2,C+m1/2)
    m2=h*f3a(t+h/2,A+k1/2,B+l1/2,C+m1/2)
    k3=h*f1a(t+h/2,A+k2/2,B+l2/2,C+m2/2)
    l3=h*f2a(t+h/2,A+k2/2,B+l2/2,C+m2/2)
    m3=h*f3a(t+h/2,A+k2/2,B+l2/2,C+m2/2)
    k4=h*f1a(t+h,A+k3,B+l3,C+m3)
    l4=h*f2a(t+h,A+k3,B+l3,C+m3)
    m4=h*f3a(t+h,A+k3,B+l3,C+m3)
    A=A+(k1+2*k2+2*k3+k4)/6
    B=B+(l1+2*l2+2*l3+l4)/6
    C=C+(m1+2*m2+2*m3+m4)/6
    if t==.5 or t==1 or t==2 or t==5 :
        print "the conc. of A,B,C after",t,"secs is",A,B,C
    
print "the conc. of A,B,C after 10 secs respectively is",A,B,C
the conc. of A,B,C after 0.5 secs is 0.606530934423 0.303264070711 0.0902049948655
the conc. of A,B,C after 1.0 secs is 0.367879774412 0.367878080371 0.264242145217
the conc. of A,B,C after 2.0 secs is 0.135335528422 0.270669810436 0.593994661142
the conc. of A,B,C after 5.0 secs is 0.00673797751675 0.0336897324459 0.959572290037
the conc. of A,B,C after 10 secs respectively is 4.54003410163e-05 0.000454001319532 0.999500598339

Exa 4.14 Page 71

In [1]:
from __future__ import division
from numpy import arange,exp

#given rxn A+B--k1-->C
#          B+C--k2-->D
k1=1; k2=1                         #given rate constants
def f1a(t,A,B,C,D):
    dA_by_dt=-A*B
    return dA_by_dt
def f2a(t,A,B,C,D):
    dB_by_dt=-A*B-B*C
    return dB_by_dt
def f3a(t,A,B,C,D):
    dC_by_dt=A*B-B*C
    return dC_by_dt
def f4a(t,A,B,C,D):
    dD_by_dt=B*C
    return dD_by_dt
A=1; B=1 ; C=0 ; D=0                            #initial values
for t in arange(.1,10.1,0.1):
    h=.1                                    #step increment of 0.1
    k1=h*f1a(t,A,B,C,D)
    l1=h*f2a(t,A,B,C,D)
    m1=h*f3a(t,A,B,C,D)
    n1=h*f4a(t,A,B,C,D)
    k2=h*f1a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    l2=h*f2a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    m2=h*f3a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    n2=h*f4a(t+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    k3=h*f1a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    l3=h*f2a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    m3=h*f3a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    n3=h*f4a(t+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    k4=h*f1a(t+h,A+k3,B+l3,C+m3,D+n3)
    l4=h*f2a(t+h,A+k3,B+l3,C+m3,D+n3)
    m4=h*f3a(t+h,A+k3,B+l3,C+m3,D+n3)
    n4=h*f4a(t+h,A+k3,B+l3,C+m3,D+n3)
    A=A+(k1+2*k2+2*k3+k4)/6
    B=B+(l1+2*l2+2*l3+l4)/6
    C=C+(m1+2*m2+2*m3+m4)/6
    D=D+(n1+2*n2+2*n3+n4)/6
    if t==.5  or t==1 or t==2 or t==5:
        print "the conc. of A,B,C,D after",t,"secs is",A,B,C,D
    
    print "the conc. of A,B,C,D after 10 secs respectively is",A,B,C,D
the conc. of A,B,C,D after 10 secs respectively is 0.909221602698 0.904970552714 0.0865273473177 0.00425104998406
the conc. of A,B,C,D after 10 secs respectively is 0.834171033289 0.819591322892 0.151249256314 0.0145797103969
the conc. of A,B,C,D after 10 secs respectively is 0.771526698493 0.743175149135 0.20012175215 0.0283515493576
the conc. of A,B,C,D after 10 secs respectively is 0.718763584219 0.67487940149 0.237352233053 0.0438841827281
the conc. of A,B,C,D after 0.5 secs is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469
the conc. of A,B,C,D after 10 secs respectively is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469
the conc. of A,B,C,D after 10 secs respectively is 0.635587969272 0.55922762747 0.288051688925 0.0763603418024
the conc. of A,B,C,D after 10 secs respectively is 0.602518712698 0.510295639479 0.305258214083 0.0922230732191
the conc. of A,B,C,D after 10 secs respectively is 0.573825046136 0.466370377686 0.318720285414 0.10745466845
the conc. of A,B,C,D after 10 secs respectively is 0.548779962461 0.426859807297 0.329299882375 0.121920155164
the conc. of A,B,C,D after 1.0 secs is 0.52680094957 0.391245989895 0.337644090755 0.135554959675
the conc. of A,B,C,D after 10 secs respectively is 0.52680094957 0.391245989895 0.337644090755 0.135554959675
the conc. of A,B,C,D after 10 secs respectively is 0.507417223315 0.359077536366 0.344243089736 0.148339686949
the conc. of A,B,C,D after 10 secs respectively is 0.490245152639 0.329961657439 0.349471352161 0.1602834952
the conc. of A,B,C,D after 10 secs respectively is 0.474969674462 0.303556564616 0.353617215693 0.171413109846
the conc. of A,B,C,D after 10 secs respectively is 0.461330119618 0.27956455757 0.356904318334 0.181765562048
the conc. of A,B,C,D after 10 secs respectively is 0.449109312513 0.257725910909 0.359507285883 0.191383401604
the conc. of A,B,C,D after 10 secs respectively is 0.438125119864 0.23781355818 0.361563318452 0.200311561684
the conc. of A,B,C,D after 10 secs respectively is 0.428223846389 0.219628516078 0.363180823301 0.208595330311
the conc. of A,B,C,D after 10 secs respectively is 0.419275034438 0.202995969535 0.364445900659 0.216279064903
the conc. of A,B,C,D after 10 secs respectively is 0.411167339142 0.187761933365 0.36542725508 0.223405405777
the conc. of A,B,C,D after 2.0 secs is 0.403805233709 0.173790409818 0.366179942399 0.230014823891
the conc. of A,B,C,D after 10 secs respectively is 0.403805233709 0.173790409818 0.366179942399 0.230014823891
the conc. of A,B,C,D after 10 secs respectively is 0.397106360172 0.160960968915 0.366748248571 0.236145391257
the conc. of A,B,C,D after 10 secs respectively is 0.390999385517 0.149166687328 0.367167916295 0.241832698188
the conc. of A,B,C,D after 10 secs respectively is 0.385422256195 0.138312390419 0.36746787803 0.247109865775
the conc. of A,B,C,D after 10 secs respectively is 0.380320768708 0.128313150237 0.367671612821 0.252007618471
the conc. of A,B,C,D after 10 secs respectively is 0.375647392533 0.119092999585 0.36779821452 0.256554392948
the conc. of A,B,C,D after 10 secs respectively is 0.37136029568 0.11058382858 0.36786323722 0.2607764671
the conc. of A,B,C,D after 10 secs respectively is 0.367422533931 0.102724435507 0.367879367645 0.264698098424
the conc. of A,B,C,D after 10 secs respectively is 0.363801372979 0.0954597083513 0.367856962394 0.268341664627
the conc. of A,B,C,D after 10 secs respectively is 0.360467719057 0.0887399171885 0.367804479075 0.271727801868
the conc. of A,B,C,D after 10 secs respectively is 0.357395638584 0.0825201008309 0.367728823663 0.274875537753
the conc. of A,B,C,D after 10 secs respectively is 0.354561951166 0.0767595337823 0.367635631451 0.277802417384
the conc. of A,B,C,D after 10 secs respectively is 0.351945883361 0.0714212617803 0.367529495058 0.280524621581
the conc. of A,B,C,D after 10 secs respectively is 0.349528772976 0.0664716960569 0.367414150106 0.283057076919
the conc. of A,B,C,D after 10 secs respectively is 0.347293815565 0.0618802579883 0.367292626859 0.285413557576
the conc. of A,B,C,D after 10 secs respectively is 0.345225846335 0.0576190670956 0.367167374425 0.287606779239
the conc. of A,B,C,D after 10 secs respectively is 0.343311151848 0.0536626664309 0.367040362736 0.289648485417
the conc. of A,B,C,D after 10 secs respectively is 0.341537306905 0.0499877802859 0.366913166476 0.291549526619
the conc. of A,B,C,D after 10 secs respectively is 0.339893032801 0.0465730999121 0.36678703431 0.293319932889
the conc. of A,B,C,D after 10 secs respectively is 0.338368073749 0.0433990935763 0.366662946079 0.294968980172
the conc. of A,B,C,D after 10 secs respectively is 0.336953088837 0.0404478378093 0.366541660135 0.296505251028
the conc. of A,B,C,D after 10 secs respectively is 0.335639557286 0.0377028671538 0.366423752583 0.297936690132
the conc. of A,B,C,D after 10 secs respectively is 0.334419695135 0.0351490400977 0.366309649828 0.299270655037
the conc. of A,B,C,D after 10 secs respectively is 0.333286381788 0.0327724192024 0.366199655626 0.300513962586
the conc. of A,B,C,D after 10 secs respectively is 0.332233095079 0.0305601637072 0.366093973549 0.301672931372
the conc. of A,B,C,D after 10 secs respectively is 0.331253853723 0.0285004331231 0.365992725677 0.3027534206
the conc. of A,B,C,D after 10 secs respectively is 0.330343166195 0.0265823005295 0.365895968139 0.303760865666
the conc. of A,B,C,D after 10 secs respectively is 0.329495985212 0.0247956744548 0.365803704032 0.304700310757
the conc. of A,B,C,D after 10 secs respectively is 0.328707667101 0.0231312283662 0.365715894165 0.305576438734
the conc. of A,B,C,D after 10 secs respectively is 0.32797393547 0.0215803369203 0.365632465979 0.30639359855
the conc. of A,B,C,D after 5.0 secs is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412
the conc. of A,B,C,D after 10 secs respectively is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412
the conc. of A,B,C,D after 10 secs respectively is 0.326654770412 0.0187878815118 0.365478340688 0.3078668889
the conc. of A,B,C,D after 10 secs respectively is 0.326062343718 0.0175320794959 0.365407392061 0.308530264222
the conc. of A,B,C,D after 10 secs respectively is 0.325510466935 0.0163612651761 0.365340331307 0.309149201758
the conc. of A,B,C,D after 10 secs respectively is 0.32499627244 0.0152695523777 0.365277007498 0.309726720062
the conc. of A,B,C,D after 10 secs respectively is 0.324517107234 0.0142514797992 0.365217265332 0.310265627434
the conc. of A,B,C,D after 10 secs respectively is 0.324070515374 0.0133019781679 0.36516094742 0.310768537206
the conc. of A,B,C,D after 10 secs respectively is 0.323654222036 0.0124163402028 0.36510789613 0.311237881834
the conc. of A,B,C,D after 10 secs respectively is 0.323266119025 0.0115901931149 0.365057955064 0.31167592591
the conc. of A,B,C,D after 10 secs respectively is 0.322904251582 0.0108194734013 0.365010970238 0.31208477818
the conc. of A,B,C,D after 10 secs respectively is 0.32256680636 0.010100403717 0.364966790997 0.312466402643
the conc. of A,B,C,D after 10 secs respectively is 0.322252100453 0.00942947163274 0.364925270727 0.31282262882
the conc. of A,B,C,D after 10 secs respectively is 0.32195857136 0.00880341010523 0.364886267385 0.313155161255
the conc. of A,B,C,D after 10 secs respectively is 0.321684767811 0.00821917950607 0.364849643884 0.313465588305
the conc. of A,B,C,D after 10 secs respectively is 0.321429341352 0.0076739510701 0.364815268365 0.313755390282
the conc. of A,B,C,D after 10 secs respectively is 0.321191038641 0.0071650916388 0.364783014357 0.314025947002
the conc. of A,B,C,D after 10 secs respectively is 0.320968694361 0.00669014958624 0.364752760865 0.314278544774
the conc. of A,B,C,D after 10 secs respectively is 0.320761224716 0.00624684182645 0.364724392395 0.314514382889
the conc. of A,B,C,D after 10 secs respectively is 0.320567621448 0.00583304181063 0.364697798914 0.314734579638
the conc. of A,B,C,D after 10 secs respectively is 0.320386946326 0.00544676843143 0.36467287578 0.314940177894
the conc. of A,B,C,D after 10 secs respectively is 0.320218326064 0.00508617575939 0.364649523631 0.315132150305
the conc. of A,B,C,D after 10 secs respectively is 0.320060947646 0.00474954354349 0.364627648251 0.315311404103
the conc. of A,B,C,D after 10 secs respectively is 0.319914053998 0.00443526841398 0.364607160417 0.315478785584
the conc. of A,B,C,D after 10 secs respectively is 0.319776940002 0.00414185573132 0.364587975728 0.31563508427
the conc. of A,B,C,D after 10 secs respectively is 0.319648948802 0.00386791202995 0.364570014426 0.315781036772
the conc. of A,B,C,D after 10 secs respectively is 0.319529468398 0.00361213801035 0.364553201214 0.315917330388
the conc. of A,B,C,D after 10 secs respectively is 0.319417928488 0.00337332203659 0.364537465062 0.316044606451
the conc. of A,B,C,D after 10 secs respectively is 0.319313797541 0.00315033410046 0.364522739018 0.316163463441
the conc. of A,B,C,D after 10 secs respectively is 0.319216580097 0.0029421202165 0.364508960022 0.316274459881
the conc. of A,B,C,D after 10 secs respectively is 0.319125814253 0.00274769721536 0.364496068709 0.316378117038
the conc. of A,B,C,D after 10 secs respectively is 0.319041069335 0.00256614790527 0.364484009235 0.31647492143
the conc. of A,B,C,D after 10 secs respectively is 0.318961943743 0.00239661657445 0.364472729088 0.316565327169
the conc. of A,B,C,D after 10 secs respectively is 0.318888062945 0.00223830480885 0.364462178919 0.316649758136
the conc. of A,B,C,D after 10 secs respectively is 0.318819077617 0.00209046760225 0.364452312369 0.316728610015
the conc. of A,B,C,D after 10 secs respectively is 0.318754661915 0.00195240973716 0.364443085908 0.316802252177
the conc. of A,B,C,D after 10 secs respectively is 0.318694511869 0.00182348241684 0.364434458678 0.316871029453
the conc. of A,B,C,D after 10 secs respectively is 0.318638343895 0.00170308013039 0.36442639234 0.316935263765
the conc. of A,B,C,D after 10 secs respectively is 0.3185858934 0.0015906377339 0.364418850933 0.316995255667
the conc. of A,B,C,D after 10 secs respectively is 0.318536913498 0.00148562773249 0.364411800736 0.317051285766
the conc. of A,B,C,D after 10 secs respectively is 0.318491173806 0.00138755774864 0.364405210136 0.317103616058
the conc. of A,B,C,D after 10 secs respectively is 0.318448459329 0.00129596816386 0.364399049506 0.317152491165
the conc. of A,B,C,D after 10 secs respectively is 0.318408569419 0.00121042992125 0.364393291084 0.317198139497
the conc. of A,B,C,D after 10 secs respectively is 0.318371316807 0.0011305424778 0.364387908864 0.317240774329
the conc. of A,B,C,D after 10 secs respectively is 0.318336526703 0.0010559318958 0.364382878489 0.317280594807
the conc. of A,B,C,D after 10 secs respectively is 0.318304035957 0.000986249063808 0.364378177149 0.317317786893
the conc. of A,B,C,D after 10 secs respectively is 0.318273692274 0.000921168038026 0.36437378349 0.317352524236
the conc. of A,B,C,D after 10 secs respectively is 0.318245353488 0.000860384495848 0.36436967752 0.317384968992
the conc. of A,B,C,D after 10 secs respectively is 0.318218886882 0.000803614293751 0.364365840529 0.317415272588
the conc. of A,B,C,D after 10 secs respectively is 0.318194168558 0.000750592122388 0.364362255007 0.317443576435
the conc. of A,B,C,D after 10 secs respectively is 0.318171082842 0.000701070252194 0.364358904569 0.317470012589
the conc. of A,B,C,D after 10 secs respectively is 0.318149521739 0.000654817363294 0.364355773886 0.317494704375

Exa 4.15 Page 72

In [1]:
from __future__ import division
from numpy import arange,exp

rc_k1=1                      #given rate constant
u=1                 #mean axial velocity
def fm(x,Ca):
    dCa_by_dx=-Ca
    return dCa_by_dx
Ca=1
for x in arange(.1,10.1,0.1):
    h=0.1                                    #step increment of 0.1
    k1=h*fm(x,Ca)
    k2=h*fm(x+h/2,Ca+k1/2)
    k3=h*fm(x+h/2,Ca+k2/2)
    k4=h*fm(x+h,Ca+k3)
    Ca=Ca+(k1+2*k2+2*k3+k4)/6
    if x==.5 or x==1 or x==2 or x==5:
        print "length is",x,"the value of conc. at",x,"length is",Ca
    print "the value of Ca at x=10 using Runge Kutta method in plug flow reactor is",Ca
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.9048375
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.818730901406
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.740818422001
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.670320288917
length is 0.5 the value of conc. at 0.5 length is 0.606530934423
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.606530934423
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.548811934376
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.496585618671
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.449329289734
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.4065699912
length is 1.0 the value of conc. at 1.0 length is 0.367879774412
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.367879774412
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.33287141538
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.301194539314
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.272532113966
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.246597276671
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.22313046333
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.201896810613
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.182683805373
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.165299157744
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.149568876646
length is 2.0 the value of conc. at 2.0 length is 0.135335528422
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.135335528422
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.122456661198
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.110803379177
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.100259052606
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0907181505125
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0820851845144
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.074273753143
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0672056771095
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0608102168616
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0550233645995
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0497872036658
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.045049328897
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0407623221358
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0368832776556
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0333733727457
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0301974791617
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.027323811551
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0247236093343
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.022370848861
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0202419829563
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0183157052532
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.016572736952
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0149956338718
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0135686118635
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0122773888371
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0111090418218
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0100518776295
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00909531582456
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00822978283241
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00744661612362
length is 5.0 the value of conc. at 5.0 length is 0.00673797751675
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00673797751675
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00609677473132
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00551659040595
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00499161787144
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00451660303575
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00408679179936
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00369788247475
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00334598273375
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00302757065185
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00273945945969
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00247876564886
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0022428801128
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00202944203407
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0018363152565
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0016615669059
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00150344804522
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00136037617062
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00123091937328
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00111378200842
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.00100779172804
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000911887747724
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000825110229931
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000746590677676
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000675543242311
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000611256858515
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000553088127716
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000500454878763
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000452830341362
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000409737874002
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000370746193568
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000335465058922
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000303541365253
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000274655610082
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000248518695587
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000224869035219
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000203469935655
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000184107227903
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000166587123828
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000150734276656
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000136390026054
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.0001234108102
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000111666728974
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 0.000101040243878
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 9.142500167e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 8.27247699485e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 7.48524740283e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 6.77293254686e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 6.12840335337e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 5.54520916925e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 5.01751320168e-05
the value of Ca at x=10 using Runge Kutta method in plug flow reactor is 4.54003410163e-05

Exa 4.16 Page 73

In [2]:
from __future__ import division
from numpy import arange,exp
#given rxn A-->B-->C
rc_k1=1 ;  rc_k2=1                           #given rate constants
u=1                                  #mean axial velocity
def f1e(x,A,B,C):
    dA_by_dx=-A
    return dA_by_dx
def f2e(x,A,B,C):
    dB_by_dx=A-B
    return dB_by_dx
def f3e(x,A,B,C):
    dC_by_dx=B
    return dC_by_dx
A=1 ; B=0 ; C=0
for x in arange(.1,10.1,0.1):
    h=.1                                    #step increment of 0.1
    k1=h*f1e(x,A,B,C)
    l1=h*f2e(x,A,B,C)
    m1=h*f3e(x,A,B,C)
    k2=h*f1e(x+h/2,A+k1/2,B+l1/2,C+m1/2)
    l2=h*f2e(x+h/2,A+k1/2,B+l1/2,C+m1/2)
    m2=h*f3e(x+h/2,A+k1/2,B+l1/2,C+m1/2)
    k3=h*f1e(x+h/2,A+k2/2,B+l2/2,C+m2/2)
    l3=h*f2e(x+h/2,A+k2/2,B+l2/2,C+m2/2)
    m3=h*f3e(x+h/2,A+k2/2,B+l2/2,C+m2/2)
    k4=h*f1e(x+h,A+k3,B+l3,C+m3)
    l4=h*f2e(x+h,A+k3,B+l3,C+m3)
    m4=h*f3e(x+h,A+k3,B+l3,C+m3)
    A=A+(k1+2*k2+2*k3+k4)/6
    B=B+(l1+2*l2+2*l3+l4)/6
    C=C+(m1+2*m2+2*m3+m4)/6
    if x==.5 or x==1 or x==2 or x==5:
        print "the conc. of A,B,C at a distance of",x,"mtr is",A,B,C
    print "the conc. of A,B,C at a distance of 10 mtr is",A,B,C
the conc. of A,B,C at a distance of 10 mtr is 0.9048375 0.0904833333333 0.00467916666667
the conc. of A,B,C at a distance of 10 mtr is 0.818730901406 0.16374542625 0.0175236723438
the conc. of A,B,C at a distance of 10 mtr is 0.740818422001 0.222244503187 0.0369370748121
the conc. of A,B,C at a distance of 10 mtr is 0.670320288917 0.26812688087 0.0615528302129
the conc. of A,B,C at a distance of 0.5 mtr is 0.606530934423 0.303264070711 0.0902049948655
the conc. of A,B,C at a distance of 10 mtr is 0.606530934423 0.303264070711 0.0902049948655
the conc. of A,B,C at a distance of 10 mtr is 0.548811934376 0.329285644298 0.121902421325
the conc. of A,B,C at a distance of 10 mtr is 0.496585618671 0.347608332368 0.15580604896
the conc. of A,B,C at a distance of 10 mtr is 0.449329289734 0.359461776502 0.191208933763
the conc. of A,B,C at a distance of 10 mtr is 0.4065699912 0.365911307095 0.227518701705
the conc. of A,B,C at a distance of 1.0 mtr is 0.367879774412 0.367878080371 0.264242145217
the conc. of A,B,C at a distance of 10 mtr is 0.367879774412 0.367878080371 0.264242145217
the conc. of A,B,C at a distance of 10 mtr is 0.33287141538 0.366156870802 0.300971713818
the conc. of A,B,C at a distance of 10 mtr is 0.301194539314 0.36143178282 0.337373677867
the conc. of A,B,C at a distance of 10 mtr is 0.272532113966 0.354290116686 0.373177769348
the conc. of A,B,C at a distance of 10 mtr is 0.246597276671 0.345234597569 0.40816812576
the conc. of A,B,C at a distance of 10 mtr is 0.22313046333 0.334694153762 0.442175382908
the conc. of A,B,C at a distance of 10 mtr is 0.201896810613 0.323033409445 0.475069779942
the conc. of A,B,C at a distance of 10 mtr is 0.182683805373 0.310561039032 0.506755155595
the conc. of A,B,C at a distance of 10 mtr is 0.165299157744 0.297537113811 0.537163728444
the conc. of A,B,C at a distance of 10 mtr is 0.149568876646 0.284179557008 0.566251566346
the conc. of A,B,C at a distance of 2.0 mtr is 0.135335528422 0.270669810436 0.593994661142
the conc. of A,B,C at a distance of 10 mtr is 0.135335528422 0.270669810436 0.593994661142
the conc. of A,B,C at a distance of 10 mtr is 0.122456661198 0.257157804331 0.620385534471
the conc. of A,B,C at a distance of 10 mtr is 0.110803379177 0.24376631167 0.645430309153
the conc. of A,B,C at a distance of 10 mtr is 0.100259052606 0.230594759128 0.669146188265
the conc. of A,B,C at a distance of 10 mtr is 0.0907181505125 0.217722558639 0.691559290848
the conc. of A,B,C at a distance of 10 mtr is 0.0820851845144 0.205212016305 0.712702799181
the conc. of A,B,C at a distance of 10 mtr is 0.074273753143 0.193110868916 0.732615377941
the conc. of A,B,C at a distance of 10 mtr is 0.0672056771095 0.181454492616 0.751339830274
the conc. of A,B,C at a distance of 10 mtr is 0.0608102168616 0.170267823146 0.768921959992
the conc. of A,B,C at a distance of 10 mtr is 0.0550233645995 0.159567022548 0.785409612852
the conc. of A,B,C at a distance of 10 mtr is 0.0497872036658 0.149360923205 0.800851873129
the conc. of A,B,C at a distance of 10 mtr is 0.045049328897 0.139652276496 0.815298394607
the conc. of A,B,C at a distance of 10 mtr is 0.0407623221358 0.130438830177 0.828798847687
the conc. of A,B,C at a distance of 10 mtr is 0.0368832776556 0.121714255781 0.841402466563
the conc. of A,B,C at a distance of 10 mtr is 0.0333733727457 0.113468944822 0.853157682432
the conc. of A,B,C at a distance of 10 mtr is 0.0301974791617 0.105690690371 0.864111830467
the conc. of A,B,C at a distance of 10 mtr is 0.027323811551 0.0983652686215 0.874310919828
the conc. of A,B,C at a distance of 10 mtr is 0.0247236093343 0.0914769332948 0.883799457371
the conc. of A,B,C at a distance of 10 mtr is 0.022370848861 0.0850088342147 0.892620316924
the conc. of A,B,C at a distance of 10 mtr is 0.0202419829563 0.0789433700032 0.900814647041
the conc. of A,B,C at a distance of 10 mtr is 0.0183157052532 0.0732624836464 0.9084218111
the conc. of A,B,C at a distance of 10 mtr is 0.016572736952 0.0679479086101 0.915479354438
the conc. of A,B,C at a distance of 10 mtr is 0.0149956338718 0.0629813722389 0.922022993889
the conc. of A,B,C at a distance of 10 mtr is 0.0135686118635 0.0583447623414 0.928086625795
the conc. of A,B,C at a distance of 10 mtr is 0.0122773888371 0.0540202621252 0.933702349038
the conc. of A,B,C at a distance of 10 mtr is 0.0111090418218 0.0499904579973 0.938900500181
the conc. of A,B,C at a distance of 10 mtr is 0.0100518776295 0.0462384241723 0.943709698198
the conc. of A,B,C at a distance of 10 mtr is 0.00909531582456 0.0427477875262 0.948156896649
the conc. of A,B,C at a distance of 10 mtr is 0.00822978283241 0.0395027756892 0.952267441478
the conc. of A,B,C at a distance of 10 mtr is 0.00744661612362 0.036488250981 0.956065132895
the conc. of A,B,C at a distance of 5.0 mtr is 0.00673797751675 0.0336897324459 0.959572290037
the conc. of A,B,C at a distance of 10 mtr is 0.00673797751675 0.0336897324459 0.959572290037
the conc. of A,B,C at a distance of 10 mtr is 0.00609677473132 0.0310934079477 0.962809817321
the conc. of A,B,C at a distance of 10 mtr is 0.00551659040595 0.0286861380141 0.96579727158
the conc. of A,B,C at a distance of 10 mtr is 0.00499161787144 0.0264554528939 0.968552929235
the conc. of A,B,C at a distance of 10 mtr is 0.00451660303575 0.0243895440817 0.971093852883
the conc. of A,B,C at a distance of 10 mtr is 0.00408679179936 0.022477251391 0.97343595681
the conc. of A,B,C at a distance of 10 mtr is 0.00369788247475 0.0207080465001 0.975594071025
the conc. of A,B,C at a distance of 10 mtr is 0.00334598273375 0.0190720137577 0.977582003509
the conc. of A,B,C at a distance of 10 mtr is 0.00302757065185 0.0175598289195 0.979412600429
the conc. of A,B,C at a distance of 10 mtr is 0.00273945945969 0.0161627363844 0.981097804156
the conc. of A,B,C at a distance of 10 mtr is 0.00247876564886 0.0148725254067 0.982648708944
the conc. of A,B,C at a distance of 10 mtr is 0.0022428801128 0.0136815056861 0.984075614201
the conc. of A,B,C at a distance of 10 mtr is 0.00202944203407 0.0125824826701 0.985388075296
the conc. of A,B,C at a distance of 10 mtr is 0.0018363152565 0.0115687328431 0.9865949519
the conc. of A,B,C at a distance of 10 mtr is 0.0016615669059 0.0106339792294 0.987704453865
the conc. of A,B,C at a distance of 10 mtr is 0.00150344804522 0.00977236729316 0.988724184662
the conc. of A,B,C at a distance of 10 mtr is 0.00136037617062 0.00897844138125 0.989661182448
the conc. of A,B,C at a distance of 10 mtr is 0.00123091937328 0.00824712182381 0.990521958803
the conc. of A,B,C at a distance of 10 mtr is 0.00111378200842 0.00757368278121 0.99131253521
the conc. of A,B,C at a distance of 10 mtr is 0.00100779172804 0.00695373090227 0.99203847737
the conc. of A,B,C at a distance of 10 mtr is 0.000911887747724 0.00638318484014 0.992704927412
the conc. of A,B,C at a distance of 10 mtr is 0.000825110229931 0.00585825565583 0.993316634114
the conc. of A,B,C at a distance of 10 mtr is 0.000746590677676 0.00537542812596 0.993877981196
the conc. of A,B,C at a distance of 10 mtr is 0.000675543242311 0.00493144296007 0.994393013798
the conc. of A,B,C at a distance of 10 mtr is 0.000611256858515 0.00452327992376 0.994865463218
the conc. of A,B,C at a distance of 10 mtr is 0.000553088127716 0.0041481418561 0.995298770016
the conc. of A,B,C at a distance of 10 mtr is 0.000500454878763 0.00380343956414 0.995696105557
the conc. of A,B,C at a distance of 10 mtr is 0.000452830341362 0.00348677757223 0.996060392086
the conc. of A,B,C at a distance of 10 mtr is 0.000409737874002 0.00319594070023 0.996394321426
the conc. of A,B,C at a distance of 10 mtr is 0.000370746193568 0.00292888144198 0.996700372364
the conc. of A,B,C at a distance of 10 mtr is 0.000335465058922 0.00268370811317 0.996980826828
the conc. of A,B,C at a distance of 10 mtr is 0.000303541365253 0.0024586737366 0.997237784898
the conc. of A,B,C at a distance of 10 mtr is 0.000274655610082 0.00225216563167 0.997473178758
the conc. of A,B,C at a distance of 10 mtr is 0.000248518695587 0.00206269567487 0.99768878563
the conc. of A,B,C at a distance of 10 mtr is 0.000224869035219 0.00188889119768 0.997886239767
the conc. of A,B,C at a distance of 10 mtr is 0.000203469935655 0.00172948648895 0.998067043575
the conc. of A,B,C at a distance of 10 mtr is 0.000184107227903 0.00158331486896 0.998232577903
the conc. of A,B,C at a distance of 10 mtr is 0.000166587123828 0.00144930130341 0.998384111573
the conc. of A,B,C at a distance of 10 mtr is 0.000150734276656 0.00132645552638 0.998522810197
the conc. of A,B,C at a distance of 10 mtr is 0.000136390026054 0.00121386564215 0.998649744332
the conc. of A,B,C at a distance of 10 mtr is 0.0001234108102 0.00111069217717 0.998765897013
the conc. of A,B,C at a distance of 10 mtr is 0.000111666728974 0.00101616255434 0.998872170717
the conc. of A,B,C at a distance of 10 mtr is 0.000101040243878 0.00092956596312 0.998969393793
the conc. of A,B,C at a distance of 10 mtr is 9.142500167e-05 0.000850248600221 0.999058326398
the conc. of A,B,C at a distance of 10 mtr is 8.27247699485e-05 0.000777609256704 0.999139665973
the conc. of A,B,C at a distance of 10 mtr is 7.48524740283e-05 0.000711095228747 0.999214052297
the conc. of A,B,C at a distance of 10 mtr is 6.77293254686e-05 0.0006501985304 0.999282072144
the conc. of A,B,C at a distance of 10 mtr is 6.12840335337e-05 0.000594452387883 0.999344263579
the conc. of A,B,C at a distance of 10 mtr is 5.54520916925e-05 0.000543427996156 0.999401119912
the conc. of A,B,C at a distance of 10 mtr is 5.01751320168e-05 0.000496731519568 0.999453093348
the conc. of A,B,C at a distance of 10 mtr is 4.54003410163e-05 0.000454001319532 0.999500598339

Exa 4.17 Page 74

In [3]:
from __future__ import division
from numpy import arange,exp
#given rxn A+B--k1-->C
#          B+C--k2-->D
rc_k1=1 ; rc_k2=1                             #rate constants
def f1a(x,A,B,C,D):
    dA_by_dx=-A*B
    return dA_by_dx
def f2a(x,A,B,C,D):
    dB_by_dx=-A*B-B*C
    return dB_by_dx
def f3a(x,A,B,C,D):
    dC_by_dx=A*B-B*C
    return dC_by_dx
def f4a(x,A,B,C,D):
    dD_by_dx=B*C
    return dD_by_dx
A=1 ; B=1 ; C=0 ;D=0
for x in arange(.1,10.1,0.1):
    h=.1                                    #step increment of 0.1
    k1=h*f1a(x,A,B,C,D)
    l1=h*f2a(x,A,B,C,D)
    m1=h*f3a(x,A,B,C,D)
    n1=h*f4a(x,A,B,C,D)
    k2=h*f1a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    l2=h*f2a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    m2=h*f3a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    n2=h*f4a(x+h/2,A+k1/2,B+l1/2,C+m1/2,D+n1/2)
    k3=h*f1a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    l3=h*f2a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    m3=h*f3a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    n3=h*f4a(x+h/2,A+k2/2,B+l2/2,C+m2/2,D+n2/2)
    k4=h*f1a(x+h,A+k3,B+l3,C+m3,D+n3)
    l4=h*f2a(x+h,A+k3,B+l3,C+m3,D+n3)
    m4=h*f3a(x+h,A+k3,B+l3,C+m3,D+n3)
    n4=h*f4a(x+h,A+k3,B+l3,C+m3,D+n3)
    A=A+(k1+2*k2+2*k3+k4)/6
    B=B+(l1+2*l2+2*l3+l4)/6
    C=C+(m1+2*m2+2*m3+m4)/6
    D=D+(n1+2*n2+2*n3+n4)/6
    if x==.5 or x==1 or x==2 or x==5:
        print "the conc. of A,B,C,D after",x,"secs is",A,B,C,D
    
    print "the conc. of A,B,C,D after 10 secs respectively is",A,B,C,D
the conc. of A,B,C,D after 10 secs respectively is 0.909221602698 0.904970552714 0.0865273473177 0.00425104998406
the conc. of A,B,C,D after 10 secs respectively is 0.834171033289 0.819591322892 0.151249256314 0.0145797103969
the conc. of A,B,C,D after 10 secs respectively is 0.771526698493 0.743175149135 0.20012175215 0.0283515493576
the conc. of A,B,C,D after 10 secs respectively is 0.718763584219 0.67487940149 0.237352233053 0.0438841827281
the conc. of A,B,C,D after 0.5 secs is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469
the conc. of A,B,C,D after 10 secs respectively is 0.673948358905 0.613838104858 0.265941387048 0.0601102540469
the conc. of A,B,C,D after 10 secs respectively is 0.635587969272 0.55922762747 0.288051688925 0.0763603418024
the conc. of A,B,C,D after 10 secs respectively is 0.602518712698 0.510295639479 0.305258214083 0.0922230732191
the conc. of A,B,C,D after 10 secs respectively is 0.573825046136 0.466370377686 0.318720285414 0.10745466845
the conc. of A,B,C,D after 10 secs respectively is 0.548779962461 0.426859807297 0.329299882375 0.121920155164
the conc. of A,B,C,D after 1.0 secs is 0.52680094957 0.391245989895 0.337644090755 0.135554959675
the conc. of A,B,C,D after 10 secs respectively is 0.52680094957 0.391245989895 0.337644090755 0.135554959675
the conc. of A,B,C,D after 10 secs respectively is 0.507417223315 0.359077536366 0.344243089736 0.148339686949
the conc. of A,B,C,D after 10 secs respectively is 0.490245152639 0.329961657439 0.349471352161 0.1602834952
the conc. of A,B,C,D after 10 secs respectively is 0.474969674462 0.303556564616 0.353617215693 0.171413109846
the conc. of A,B,C,D after 10 secs respectively is 0.461330119618 0.27956455757 0.356904318334 0.181765562048
the conc. of A,B,C,D after 10 secs respectively is 0.449109312513 0.257725910909 0.359507285883 0.191383401604
the conc. of A,B,C,D after 10 secs respectively is 0.438125119864 0.23781355818 0.361563318452 0.200311561684
the conc. of A,B,C,D after 10 secs respectively is 0.428223846389 0.219628516078 0.363180823301 0.208595330311
the conc. of A,B,C,D after 10 secs respectively is 0.419275034438 0.202995969535 0.364445900659 0.216279064903
the conc. of A,B,C,D after 10 secs respectively is 0.411167339142 0.187761933365 0.36542725508 0.223405405777
the conc. of A,B,C,D after 2.0 secs is 0.403805233709 0.173790409818 0.366179942399 0.230014823891
the conc. of A,B,C,D after 10 secs respectively is 0.403805233709 0.173790409818 0.366179942399 0.230014823891
the conc. of A,B,C,D after 10 secs respectively is 0.397106360172 0.160960968915 0.366748248571 0.236145391257
the conc. of A,B,C,D after 10 secs respectively is 0.390999385517 0.149166687328 0.367167916295 0.241832698188
the conc. of A,B,C,D after 10 secs respectively is 0.385422256195 0.138312390419 0.36746787803 0.247109865775
the conc. of A,B,C,D after 10 secs respectively is 0.380320768708 0.128313150237 0.367671612821 0.252007618471
the conc. of A,B,C,D after 10 secs respectively is 0.375647392533 0.119092999585 0.36779821452 0.256554392948
the conc. of A,B,C,D after 10 secs respectively is 0.37136029568 0.11058382858 0.36786323722 0.2607764671
the conc. of A,B,C,D after 10 secs respectively is 0.367422533931 0.102724435507 0.367879367645 0.264698098424
the conc. of A,B,C,D after 10 secs respectively is 0.363801372979 0.0954597083513 0.367856962394 0.268341664627
the conc. of A,B,C,D after 10 secs respectively is 0.360467719057 0.0887399171885 0.367804479075 0.271727801868
the conc. of A,B,C,D after 10 secs respectively is 0.357395638584 0.0825201008309 0.367728823663 0.274875537753
the conc. of A,B,C,D after 10 secs respectively is 0.354561951166 0.0767595337823 0.367635631451 0.277802417384
the conc. of A,B,C,D after 10 secs respectively is 0.351945883361 0.0714212617803 0.367529495058 0.280524621581
the conc. of A,B,C,D after 10 secs respectively is 0.349528772976 0.0664716960569 0.367414150106 0.283057076919
the conc. of A,B,C,D after 10 secs respectively is 0.347293815565 0.0618802579883 0.367292626859 0.285413557576
the conc. of A,B,C,D after 10 secs respectively is 0.345225846335 0.0576190670956 0.367167374425 0.287606779239
the conc. of A,B,C,D after 10 secs respectively is 0.343311151848 0.0536626664309 0.367040362736 0.289648485417
the conc. of A,B,C,D after 10 secs respectively is 0.341537306905 0.0499877802859 0.366913166476 0.291549526619
the conc. of A,B,C,D after 10 secs respectively is 0.339893032801 0.0465730999121 0.36678703431 0.293319932889
the conc. of A,B,C,D after 10 secs respectively is 0.338368073749 0.0433990935763 0.366662946079 0.294968980172
the conc. of A,B,C,D after 10 secs respectively is 0.336953088837 0.0404478378093 0.366541660135 0.296505251028
the conc. of A,B,C,D after 10 secs respectively is 0.335639557286 0.0377028671538 0.366423752583 0.297936690132
the conc. of A,B,C,D after 10 secs respectively is 0.334419695135 0.0351490400977 0.366309649828 0.299270655037
the conc. of A,B,C,D after 10 secs respectively is 0.333286381788 0.0327724192024 0.366199655626 0.300513962586
the conc. of A,B,C,D after 10 secs respectively is 0.332233095079 0.0305601637072 0.366093973549 0.301672931372
the conc. of A,B,C,D after 10 secs respectively is 0.331253853723 0.0285004331231 0.365992725677 0.3027534206
the conc. of A,B,C,D after 10 secs respectively is 0.330343166195 0.0265823005295 0.365895968139 0.303760865666
the conc. of A,B,C,D after 10 secs respectively is 0.329495985212 0.0247956744548 0.365803704032 0.304700310757
the conc. of A,B,C,D after 10 secs respectively is 0.328707667101 0.0231312283662 0.365715894165 0.305576438734
the conc. of A,B,C,D after 10 secs respectively is 0.32797393547 0.0215803369203 0.365632465979 0.30639359855
the conc. of A,B,C,D after 5.0 secs is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412
the conc. of A,B,C,D after 10 secs respectively is 0.327290848644 0.0201350182323 0.365553320944 0.307155830412
the conc. of A,B,C,D after 10 secs respectively is 0.326654770412 0.0187878815118 0.365478340688 0.3078668889
the conc. of A,B,C,D after 10 secs respectively is 0.326062343718 0.0175320794959 0.365407392061 0.308530264222
the conc. of A,B,C,D after 10 secs respectively is 0.325510466935 0.0163612651761 0.365340331307 0.309149201758
the conc. of A,B,C,D after 10 secs respectively is 0.32499627244 0.0152695523777 0.365277007498 0.309726720062
the conc. of A,B,C,D after 10 secs respectively is 0.324517107234 0.0142514797992 0.365217265332 0.310265627434
the conc. of A,B,C,D after 10 secs respectively is 0.324070515374 0.0133019781679 0.36516094742 0.310768537206
the conc. of A,B,C,D after 10 secs respectively is 0.323654222036 0.0124163402028 0.36510789613 0.311237881834
the conc. of A,B,C,D after 10 secs respectively is 0.323266119025 0.0115901931149 0.365057955064 0.31167592591
the conc. of A,B,C,D after 10 secs respectively is 0.322904251582 0.0108194734013 0.365010970238 0.31208477818
the conc. of A,B,C,D after 10 secs respectively is 0.32256680636 0.010100403717 0.364966790997 0.312466402643
the conc. of A,B,C,D after 10 secs respectively is 0.322252100453 0.00942947163274 0.364925270727 0.31282262882
the conc. of A,B,C,D after 10 secs respectively is 0.32195857136 0.00880341010523 0.364886267385 0.313155161255
the conc. of A,B,C,D after 10 secs respectively is 0.321684767811 0.00821917950607 0.364849643884 0.313465588305
the conc. of A,B,C,D after 10 secs respectively is 0.321429341352 0.0076739510701 0.364815268365 0.313755390282
the conc. of A,B,C,D after 10 secs respectively is 0.321191038641 0.0071650916388 0.364783014357 0.314025947002
the conc. of A,B,C,D after 10 secs respectively is 0.320968694361 0.00669014958624 0.364752760865 0.314278544774
the conc. of A,B,C,D after 10 secs respectively is 0.320761224716 0.00624684182645 0.364724392395 0.314514382889
the conc. of A,B,C,D after 10 secs respectively is 0.320567621448 0.00583304181063 0.364697798914 0.314734579638
the conc. of A,B,C,D after 10 secs respectively is 0.320386946326 0.00544676843143 0.36467287578 0.314940177894
the conc. of A,B,C,D after 10 secs respectively is 0.320218326064 0.00508617575939 0.364649523631 0.315132150305
the conc. of A,B,C,D after 10 secs respectively is 0.320060947646 0.00474954354349 0.364627648251 0.315311404103
the conc. of A,B,C,D after 10 secs respectively is 0.319914053998 0.00443526841398 0.364607160417 0.315478785584
the conc. of A,B,C,D after 10 secs respectively is 0.319776940002 0.00414185573132 0.364587975728 0.31563508427
the conc. of A,B,C,D after 10 secs respectively is 0.319648948802 0.00386791202995 0.364570014426 0.315781036772
the conc. of A,B,C,D after 10 secs respectively is 0.319529468398 0.00361213801035 0.364553201214 0.315917330388
the conc. of A,B,C,D after 10 secs respectively is 0.319417928488 0.00337332203659 0.364537465062 0.316044606451
the conc. of A,B,C,D after 10 secs respectively is 0.319313797541 0.00315033410046 0.364522739018 0.316163463441
the conc. of A,B,C,D after 10 secs respectively is 0.319216580097 0.0029421202165 0.364508960022 0.316274459881
the conc. of A,B,C,D after 10 secs respectively is 0.319125814253 0.00274769721536 0.364496068709 0.316378117038
the conc. of A,B,C,D after 10 secs respectively is 0.319041069335 0.00256614790527 0.364484009235 0.31647492143
the conc. of A,B,C,D after 10 secs respectively is 0.318961943743 0.00239661657445 0.364472729088 0.316565327169
the conc. of A,B,C,D after 10 secs respectively is 0.318888062945 0.00223830480885 0.364462178919 0.316649758136
the conc. of A,B,C,D after 10 secs respectively is 0.318819077617 0.00209046760225 0.364452312369 0.316728610015
the conc. of A,B,C,D after 10 secs respectively is 0.318754661915 0.00195240973716 0.364443085908 0.316802252177
the conc. of A,B,C,D after 10 secs respectively is 0.318694511869 0.00182348241684 0.364434458678 0.316871029453
the conc. of A,B,C,D after 10 secs respectively is 0.318638343895 0.00170308013039 0.36442639234 0.316935263765
the conc. of A,B,C,D after 10 secs respectively is 0.3185858934 0.0015906377339 0.364418850933 0.316995255667
the conc. of A,B,C,D after 10 secs respectively is 0.318536913498 0.00148562773249 0.364411800736 0.317051285766
the conc. of A,B,C,D after 10 secs respectively is 0.318491173806 0.00138755774864 0.364405210136 0.317103616058
the conc. of A,B,C,D after 10 secs respectively is 0.318448459329 0.00129596816386 0.364399049506 0.317152491165
the conc. of A,B,C,D after 10 secs respectively is 0.318408569419 0.00121042992125 0.364393291084 0.317198139497
the conc. of A,B,C,D after 10 secs respectively is 0.318371316807 0.0011305424778 0.364387908864 0.317240774329
the conc. of A,B,C,D after 10 secs respectively is 0.318336526703 0.0010559318958 0.364382878489 0.317280594807
the conc. of A,B,C,D after 10 secs respectively is 0.318304035957 0.000986249063808 0.364378177149 0.317317786893
the conc. of A,B,C,D after 10 secs respectively is 0.318273692274 0.000921168038026 0.36437378349 0.317352524236
the conc. of A,B,C,D after 10 secs respectively is 0.318245353488 0.000860384495848 0.36436967752 0.317384968992
the conc. of A,B,C,D after 10 secs respectively is 0.318218886882 0.000803614293751 0.364365840529 0.317415272588
the conc. of A,B,C,D after 10 secs respectively is 0.318194168558 0.000750592122388 0.364362255007 0.317443576435
the conc. of A,B,C,D after 10 secs respectively is 0.318171082842 0.000701070252194 0.364358904569 0.317470012589
the conc. of A,B,C,D after 10 secs respectively is 0.318149521739 0.000654817363294 0.364355773886 0.317494704375

Exa 4.18 Page 75

In [4]:
from __future__ import division
from numpy import arange,exp,pi
T=294.15
#rxn A-->B
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
b=E/(R*T1) ; k1=5.64*10**13*exp(-b);  A=pi*dia**2/4; na0=mdot*1000/MW; Ts=388.71
k=k1*exp(b*(1-T1/T))

#dX_by_dV=ra/na0
#dX_by_dV=k*(1-X)/F
#from energX balance
#mdot*Cp*dT_by_dz+ra*A*H_RXN-q=0
#q=U*pi*dia*(Ts-T)
#-mdot*Cp*dT_by_dV+4*U/dia*(Ts-T)-ra*H_rxn=0
F=mdot/rho
t1=A*k1/F

s1=mdot*Cp/A
s2=4*U/dia
s3=H_rxn*t1

def fg1(z,X,T):
    dX_by_dz=t1*(1-X)*exp(b*(1-T1/T))
    return dX_by_dz
def fd1(z,X,T):
     ra=na0/A*(t1*(1-X)*exp(b*(1-T1/T)))
     dT_by_dz=(ra*H_rxn-s2*(Ts-T))/-s1
     return dT_by_dz
         
    
X=0 ; T=294.15
for z in arange(0,350.1,0.1):
    h=.1                                    #szep incremenz of 0.1
    k1=h*fg1(z,X,T)
    l1=h*fd1(z,X,T)
    k2=h*fg1(z+h/2,X+k1/2,T+l1/2)
    l2=h*fd1(z+h/2,X+k1/2,T+l1/2)
    k3=h*fg1(z+h/2,X+k2/2,T+l2/2)
    l3=h*fd1(z+h/2,X+k2/2,T+l2/2)
    k4=h*fg1(z+h,X+k3,T+l3)
    l4=h*fd1(z+h,X+k3,T+l3)
    X=X+(k1+2*k2+2*k3+k4)/6
    T=T+(l1+2*l2+2*l3+l4)/6
    #condition for height calc. for 90% conversion
    if X>.9 and X<.9005 :
        print "the height of the tower required for 90% conversion in mtrs is",z
    
the height of the tower required for 90% conversion in mtrs is 199.2
the height of the tower required for 90% conversion in mtrs is 199.3