# python - 在房屋形状的域

``````import numpy as np
import matplotlib.pyplot as plt

floor=25
rightwall=25
leftwall=25
ceiling=30
width=19
height=20
numofnodes=width*height
#all the variables above depend on user input

K=[]
K = [[0 for i in range(numofnodes)]for j in range(numofnodes)]

for i in range (numofnodes):
for j in range (numofnodes):
if(i==j):
K[i][j]=-4
for i in range(numofnodes-1):
K[i][i 1]=1
for i in range(1,numofnodes):
K[i][i-1]=1
for i in range(numofnodes-width):
K[i][i width]=1
for i in range(width, numofnodes):
K[i][i-width]=1
for i in range(1,height):
K[width*i][(width*i)-1]=0
for i in range(height):
K[(width*i)-1][(width*i)]=0

D1=np.zeros([numofnodes,1])
for i in range(width):
D1[i]=leftwall

D2=np.zeros([numofnodes,1])
for i in range(height):
D2[(i*width)]=floor

D3=np.zeros([numofnodes,1])
for i in range(1,height 1):
D3[(i*width)-1]=ceiling

D4=np.zeros([numofnodes,1])
for i in range(numofnodes-width, numofnodes):
D4[i]=rightwall
D=np.zeros([numofnodes,1])
Dnew=np.negative(D1 D2 D3 D4)

Kinv=np.linalg.inv(K)
T=np.dot(Kinv,Dnew)

Tnew=np.reshape(T,(height,width))
Tmatrix=np.transpose(Tnew)

fig = plt.figure(figsize=(6, 4))
ax.set_title('temp distribution')
plt.imshow(Tmatrix,origin='lower', interpolation='bilinear')
ax.set_aspect('auto')
plt.clim(25,30)
plt.colorbar(orientation='vertical')
plt.grid()
plt.show()
``````

#### 0 个答案:

DABAN RP主题是一个优秀的主题，极致后台体验，无插件，集成会员系统
U19学习网站 » python - 在房屋形状的域