# Chapter 8 - Chemical Reaction & Dissusion in a spherical Catalyst Pellet¶

## Exa 8.1 Page 158¶

In [1]:
from __future__ import division
from numpy import zeros
x=[];x1=[]
for i in range(1,101):
x.append(0)

Iter=0 ;  e1=1 ;  f=1
a=[0]
while e1>1e-6 and f>1e-6:
Iter=Iter+1
for i in range(1,101):
x1.append(x[i-1])
for i in range(2,101):
a.append(1-(1/(i-1)))
b=[-6.01]
for i in range(2,101):
b.append(-2.01)
c=[6]
for i in range(2,100):
c.append(1+(1/(i-1)))
#for i=1:99,d(i)=0, end, d(100)=-100/99,
d=zeros(100)
d[99]=-100/99
i=1 ; n=100 ; Beta = [b[i-1]]
Gamma = [d[i-1]/Beta[i-1]]
i1=i+1
for j in range(i1,n+1):
Beta.append((b[j-1]-a[j-1]*c[j-2])/Beta[j-2])
Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
x=zeros(n)
x[-1]=Gamma[n-1]
n1=n-i
for k in range(1,n1+1):
j=n-k
x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]

e1=abs(x[0]-x1[0])
f=abs(x[99]-x1[99])

print "the solution by TDMA of node 77 to 99 by 1st order rxn. is",Iter
for i in range(78,101):
print x[i-1]

the solution by TDMA of node 77 to 99 by 1st order rxn. is 1
2.11327608271e-05
-6.97708390547e-06
-6.19992402138e-05
2.04759969916e-05
0.000182009868277
-6.01295131167e-05
-0.000534648505839
0.000176680552708
0.0015714263084
-0.000519440824961
-0.00462125771268
0.00152798240852
0.0135974017665
-0.00449702200409
-0.0400286588926
0.0132417745751
0.117895160831
-0.0390097044184
-0.34739360391
0.114972976752
1.02409485606
-0.339006034307
-3.02025227398


## Exa 8.2 Page 162¶

In [2]:
from __future__ import division
from numpy import zeros
x=zeros(100)
Iter=0 ; e1=1 ; f=1
k=.1 ; D=10**-9 ; r=.01 ; delta_r=r/10 ; t1=k*delta_r**2/D
x1=[]; a=[0] ; b=[0] ;d=[0]
while e1>1e-6 and f>1e-6:
Iter=Iter+1
for i in range(1,101):
x1.append(x[i-1])
for i in range(2,101):
a.append(1-(1/(i-1)))
b=[-6-t1*x1[0]]
for i in range(2,101):
b.append(-2-t1*x1[i-1])
c=[6]
for i in range(2,100):
c.append(1+(1/(i-1)))
for i in range(1,100):
d.append(0)
d.append(-100/99)
i=1 ;  n=100 ;  Beta=[b[i-1]]
Gamma=[d[i-1]/Beta[i-1]]
i1=i+1
for j in range(i1,n+1):
Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])
Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
x=zeros(n)
x[-1]=Gamma[n-1]
n1=n-i
for k in range(1,n1+1):
j=n-k
x[j-1]=Gamma[j-1]-c[j-1]*x[j-1]/Beta[j-1]
e1=abs(x[0]-x1[0])
f=abs(x[99]-x1[99])

print "the solution by TDMA of node 77 to 99 by 2nd order rxn. is"
for i in range(77,101):
print x[i-1]

the solution by TDMA of node 77 to 99 by 2nd order rxn. is
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
-0.0


## Exa 8.3 Page 163¶

In [3]:
from __future__ import division
from numpy import zeros,exp
x=zeros(100) ; x1=zeros(100); a=zeros(100) ;                        #initial values

e2=1 ;  f1=1 ; Iter=0                          #assumed values
k=.1*10**-2 ;  D=10**-9 ; r=.01 ; delta_r=r/100 ; t1=k*delta_r**2/D        #given data
#now solving the eqns for all the nodes and then simplifying we get the following relations
d=[]
while e2>1e-6 and f1>1e-6:
Iter=Iter+1
for i in range(1,101):
x1[i-1]=x[i-1]

for i in range(2,101):
a[i-1]=1-(1/(i-1))
b=[-6-t1*exp((1-x1[0])/(2-x1[0]))]
for i in range(2,101):
b.append(-2-t1*exp((1-x[i-1])/(2-x[i-1])))
c=[6]
for i in range(2,100):
c.append(1+(1/(i-1)))
for i in range(1,100):
d.append(0)
d.append(-100/99)
i=1 ;  n=100 ;  Beta = [b[i-1]]
Gamma=[d[i-1]/Beta[i-1]]
i1=i+1
for j in range(i1,n+1):
Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])
Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
x=zeros(n)
x[-1]=Gamma[n-1]
n1=n-i
for k in range(1,n1+1):
j=n-k
x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]

e2=abs(x[0]-x1[0])
f1=abs(x[99]-x1[99])

print "the solution by TDMA of node 77 to 100 by 1st order rxn. is"
for i in range(76,101):
print x[i-1]

the solution by TDMA of node 77 to 100 by 1st order rxn. is
0.0604887704253
0.0678168756519
0.0760392035241
0.0852643022272
0.095613536562
0.107222479921
0.120242419314
0.134841969734
0.151208788326
0.169551370725
0.190100900502
0.213113107034
0.238870065591
0.26768184402
0.299887860369
0.335857761202
0.375991556122
0.420718642949
0.470495220437
0.525799398375
0.587123060992
0.654959197343
0.729782956961
0.812024100415
0.902027799616


## Exa 8.4 Page 164¶

In [4]:
from __future__ import division
from numpy import zeros,exp
x=zeros(100);x=zeros(100)
Iter=0 ; e1=1 ; f1=1
while e1>1e-6 and f1>1e-6:
Iter=Iter+1
for i in range(1,101):
x1[i-1]=x[i-1]
for i in range(2,101):
a[i-1]=1-(1/(i-1))
b=[-6-.01*exp((10-10*x1[0])/(11-10*x1[0]))]
for i in range(2,101):
b.append(-2-.01*exp((10-10*x1[i-1])/(11-10*x1[i-1])))
c=[6]; d= []
for i in range(2,100):
c.append(1+(1/(i-1)))
for i in range(1,100):
d.append(0)
d.append(-100/99)
i=1 ;  n=100 ;
Beta=[b[i-1]]
Gamma=[d[i-1]/Beta[i-1]]
i1=i+1
for j in range(i1,n+1):
Beta.append(b[j-1]-a[j-1]*c[j-2]/Beta[j-2])
Gamma.append((d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1])
x=zeros(n)
x[-1]=Gamma[n-1]
n1=n-i
for k in range(1,n1+1):
j=n-k
x[j-1]=Gamma[j-1]-c[j-1]*x[j]/Beta[j-1]

e1=abs(x[0]-x1[0])
f1=abs(x[99]-x1[99])

print "the solution by TDMA of node 77 to 99 by 1st order rxn. is"
for i in range(76,101):
print x[i-1]

the solution by TDMA of node 77 to 99 by 1st order rxn. is
0.0274150220283
0.0316615335985
0.0365714178414
0.0422488399165
0.0488143356681
0.0564073663768
0.0651892620654
0.0753466078611
0.087095133412
0.100684170249
0.116401745411
0.134580380148
0.155603657639
0.179913609207
0.208018937265
0.240504032341
0.278038627503
0.321387721808
0.371421006027
0.429120250921
0.495581544008
0.572005825625
0.659662934735
0.759791838019
0.873325342972