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]
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]
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]
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]