Я делаю этот код, но у меня есть проблема в строке 40 с ошибкой индекса. Я не знаю, есть ли проблема с nr-1
внутри for
.
Код:
import numpy
Z = 1
R = 1
nr = 5
nz = 4
kn = 1
ks = 1
ke = 1
kw = 1
T = numpy.zeros((nr, nz), dtype=float)
vetorq = 1
for a in range(1, 100, 1):
for i in range(0, nz, 1):
for j in range(0, nr, 1):
an = (i + (1 / 2)) * (R ** 2)*nz*kn/ ((nr**2)* Z)
ae = (i + 2) * Z*ke / nz
aw = ((i+1)*kw * Z) / nz
asul = (i + (1 / 2)) * (R ** 2)*nz*ks / (Z * (nr**2))
ap = an + ae + aw + asul
aef = 0
if (i == 0 and j == 0):
T[i, j] = ae * ((T[i, j + 1]) / ap) + asul * (
(T[i + 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i == 0 and j != 0 and j != nr - 1):
T[i, j] = ae * ((T[i, j + 1]) / ap) + aw * ((T[i, j - 1]) / ap) + asul * (
(T[i + 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i == 0 and j == nr - 1):
aef = (i + 2) * R * Z * vetorq / (nr * nz)
T[i, j] = aw * ((T[i, j - 1]) / ap) + asul * (
(T[i + 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i != 0 and i != nz - 1 and j == nr - 1):
aef = (i + 2) * R * Z * vetorq / (nr * nz)
T[i, j] = aw * ((T[i, j - 1]) / ap) + an * ((T[i - 1, j]) / ap) + asul * (
(T[i + 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i == nz - 1 and j == nr - 1):
aef = (i + 2) * R * Z * vetorq / (nr * nz)
T[i, j] = aw * ((T[i, j - 1]) / ap) + an * ((T[i - 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) /((nr ** 2) * nz * ap) + aef / ap
elif(i == nz - 1 and j != 0 and j != nr - 1):
T[i, j] = ae * ((T[i, j + 1]) / ap) + aw * ((T[i, j - 1]) / ap) + an * ((T[i - 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i == nz - 1 and j == 0):
T[i, j] = ae * ((T[i, j + 1]) / ap) + an * ((T[i - 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i != 0 and i != nz - 1 and j == 0):
T[i, j] = ae * ((T[i, j + 1]) / ap) + an * ((T[i - 1, j]) / ap) + asul * (
(T[i + 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i + 1/2) / ((nr ** 2) * nz * ap) + aef / ap
elif(i != 0 and i != nz - 1 and j != 0 and j!= nr - 1):
T[i, j] = ae * ((T[i, j + 1]) / ap) + aw * ((T[i, j - 1]) / ap) + an * ((T[i - 1, j]) / ap) + asul * (
(T[i + 1, j]) / ap) + 1846.35 * Z * (R ** 2) * (i - 1/2) / ((nr ** 2) * nz * ap) + aef / ap
print(T)