在试图通过矩形板执行python传热代码时,其尺寸在X方向为3米,在Y方向为5米。我在尝试绘制网格网格时遇到了一个错误,错误是x(50,30)和z(30,50)的形状不匹配
这是密码
# Simple Numerical Laplace Equation Solution using Finite Difference Method
import numpy as np
import matplotlib.pyplot as plt
# Set maximum iteration
maxIter = 700
# Set Dimension and delta
lenX = 30
lenY = 50
delta = 1
# Boundary condition
Tleft = 100
Tright = 75
Ttop = 250
Tbottom = 300
# Initial guess of interior grid
Tguess = 0
# Set colour interpolation and colour map
colorinterpolation = 50
colourMap = plt.cm.coolwarm
# Set meshgrid
n1, n2 = (30, 50)
dimX = np.linspace(0, 30, n1)
dimY = np.linspace(0, 50, n2)
X, Y = np.meshgrid(dimX, dimY)
# Set array size and set the interior value with Tguess
T = np.empty((lenX, lenY))
T.fill(Tguess)
# Set Boundary condition
T[(lenY-1):, :] = Ttop
T[:1, :] = Tbottom
T[:, (lenX-1):] = Tright
T[:, :1] = Tleft
# Iteration (We assume that the iteration is convergence in maxIter = 700)
print("Please wait for a moment")
for iteration in range(0, maxIter):
for i in range(1, lenX-1, delta):
for j in range(1, lenY-1, delta):
T[i, j] = 0.25 * (T[i+1][j] + T[i-1][j] + T[i][j+1] + T[i][j-1])
print("Iteration finished")
# Configure the contour
plt.title("Contour of Temperature")
plt.contourf(X, Y, T, colorinterpolation, cmap=colourMap)
# Set Colorbar
plt.colorbar()
# Show the result in the plot window
plt.show()
print("")
你需要
从docs开始:
(默认值为
indexing='xy'
)顺便说一句,你的初始条件应该是
相关问题 更多 >
编程相关推荐