Project Update
阶段性练习:二维温度场可视化
阶段性练习:二维温度场可视化
项目目标
在 \(1\text{m} \times 1\text{m}\) 的二维薄板上,构造一个中心高温、四周低温的温度场:
\[ T(x,y) = 20+ 80\exp\left[ -\frac{(x-0.5)^2+(y-0.5)^2}{2\sigma^2} \right] \]取:
\(\sigma = 0.15\)
解答
import numpy as np
import matplotlib.pyplot as plt
x_lenth = 1
y_lenth = 1
nx = 200
ny = 200
x = np.linspace(0,x_lenth,nx)
y = np.linspace(0,y_lenth,ny)
X,Y = np.meshgrid(x,y)
temperature = (
20 + 80 * np.exp(
-(
(
(X-0.5)**2 + (Y-0.5)**2
)/(2*0.15**2)
)
)
)
fig , ax = plt.subplots()
image = ax.imshow(
temperature,
extent = [0,x_lenth,0,y_lenth],
vmin = 20,
vmax = 100,
origin = "lower",
)
fig.colorbar(
image,
ax = ax,
label = 'Temperature',
)
ax.set_title("2D Temperature Field")
ax.set_xlabel("x(m)")
ax.set_ylabel("y(m)")
plt.show()