from __future__ import division
from numpy import arange,zeros
print "the values of Temp measured from centre at the gap of .2 cm are"
alpha=10**-5 ; delta_t=.1 ; delta_x=10**-3 #given data
m=alpha*delta_t/(delta_x**2)
a=[0]
for i in range(2,5):
a.append(m) #sub-diagonal
b=[(-2*m-1)/2]
for i in range(2,5):
b.append(-2*m-1) #diagonal
c=[]
for i in range(1,4):
c.append(m) #super-diagonal
x=[]
for i in range(1,5):
x.append(20) #initial temperature
y=[]
for t in arange(0.1,3.2,.1):
for i in range(1,5):
y.append(x[i-1])
#TDMA method
d=[-.5*y[0],
-y[1],
-y[2],
-y[3]-300]
i=1 ; n=4
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]
for i in range(1,5):
print x[i-1] #solution of temperature
print "-----------------"
print "----------END---------"
from __future__ import division
from numpy import zeros
delta_t=1 ; delta_x=.05 ; alpha=10**-5
t1=alpha*delta_t/delta_x**2
a=[0]
for i in range(2,10):
a.append(-t1)
b=[]
for i in range(1,10):
b.append(1+2*t1)
c=[]
for i in range(1,9):
c.append(-t1)
t=1 ; tf=3000
x=[]
for i in range(1,10):
x.append(300)
e1=425
print "time when centre temp is 425 K in secs. is"
y=zeros(10)
for t in range(1,tf+1):
for i in range(1,10):
y[i-1]=x[i-1]
d=zeros(9)
d[0]=y[0]+1.7
d[8]=y[8]+2.4
for i in range(2,9):
d[i-1]=y[i-1]
i=1 ; n=9
Beta=[b[i]]
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]
if abs(x[4]-e1)>0 and abs(x[4]-e1)<.1:
print t
break
print "the values of temp. at req. time is"
for i in range(1,10):
print x[i-1]
from __future__ import division
from numpy import zeros,arange
delta_t=.1 ; delta_r=.001 ;alpha=10**-5 #given data
t1=alpha*delta_t/delta_r**2
a=[0,
.5*t1,.75*t1,.833*t1] #sub-diagonal
b=[-4*t1-1]
for i in range(2,5):
b.append(-2*t1-1) #main diagonal
c=[4*t1,1.5*t1,1.25*t1] #super-diagonal
x=[]
for i in range(1,5):
x.append(20)
print "T1,T2,T2 & T4 at time interval of .1 sec is"
y=zeros(5)
d=zeros(5)
for t in arange(.1,2.2,.1):
for i in range(1,5):
y[i-1]=x[i-1] #TDMA Method
d[3]=-y[3]-7*t1*300/6
for i in range(1,4):
d[i-1]=-y[i-1]
i=1 ; n=4
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]
print x[3],x[2],x[1],x[0]
print "--------------------"
from __future__ import division
from numpy import zeros,arange
delta_t=.1 ; delta_r=.001 ; alpha=10**-5
t1=alpha*delta_t/delta_r**2
a=[0,0,.5,.667]
b=[-7*t1]
for i in range(2,):
b.append(-3)
x=[6,2,1.5]
x=[]
for i in range(1,5):
x.append(20)
print "T1,T2,T2 & T4 at time interval of .1 sec is"
y=zeros(4) ; d=zeros(4)
for t in arange(.1,1.5,.1):
for i in range(1,5):
y[i-1]=x[i-1]
d[3]=-y[3]-400
for i in range(1,4):
d[i-1]=-y[i-1]
i=1 ; n=4
Beta=[b[i]]
Gamma=[d[i-1]/Beta[i-1]]
i1=i+1
for j in range(i1,n+1):
Beta.append(b[j-2]-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]
print x[3],x[2],x[1],x[0]
print "-------------------"
from __future__ import division
from math import pi
from numpy import arange,zeros
R=.326 ; D=3*10^-7
delta_t=1 ; delta_r=.0326 ; conc_ini=10/(1.33*pi*R**3)
t1=D*delta_t/delta_r**2
print "the initial conc. of drug is",conc_ini
a=[0]
for i in range(2,11):
a.append(-(1-1/(i-1)))
b=[591.4]
for i in range(2,11):
b.append(3544.5)
c=[-1]
for i in range(2,10):
c.append(-(1+1/(i-1)))
x=[]
for i in range(1,11):
x.append(conc_ini)
#y=[]
y=zeros(10)
d=zeros(10)
Beta=zeros(10)
Gamma=zeros(10)
x=zeros(10)
print "Conc. at centre at t=3hr, 12 hr, 24 hr,48 hr is"
for t in arange(1,172800+delta_t,delta_t):
for i in range(1,11):
y[i-1]=x[i-1]
d[0]=y[0]*590.4
for i in range(2,11):
d[i-1]=3542.5*y[i-1]
i=1 ; n=10
Beta[i-1]=b[i-1]
Gamma[i-1]=d[i-1]/Beta[i-1]
i1=i+1
for j in range(i1,n+1):
Beta[j-1]=b[j-1]-a[j-1]*c[j-2]/Beta[j-2]
Gamma[j-1]=(d[j-1]-a[j-1]*Gamma[j-2])/Beta[j-1]
x[n-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]
if t==10800 or t==43200 or t==86400 or t==172800:
print x[5]