Page 41 - 4968
P. 41
ion()
for j in range(m):
X = zeros(n - 1, float)
X = k * (u[0:-2, j] + u[2:, j]) - (2 * k - h * h) * u[1:-
1, j]
X[0] = X[0] + k * A * u[0, j+1]
X[-1] = X[-1] + k * A * u[n, j+1]
u[1:-1, j+1] = tdma.solve(D1, D2, D3, X)
print(u.transpose())
cla()
imshow(u.transpose())
draw()
input("Press any key")
def factor(a, d, c):
n = len(d)
for i in range(1, n):
a[i-1] = a[i-1] / d[i-1]
d[i] = d[i] - a[i-1] * c[i-1]
return
def solve(a, d, c, b):
n = len(d)
x = [0] * n
x[0] = b[0]
for i in range( 1, n ):
x[i] = b[i] - a[i-1] * x[i-1]
x[n-1] = x[n-1] / d[n-1]
for i in range(n-2, -1, -1):
x[i] = (x[i] - c[i] * x[i+1]) / d[i]
return x
41