我是蟒蛇的新手。我正在做一个关于熔炉热建模的项目。为此,我需要首先使用以下公式获得炉内材料的密度分布:dm/dt = d(ρV)/dt = ∑m˙in - ∑m˙out + Rg。最初,我要解决 3 个网格点,这是我尝试过的代码。但我得到的输出并不令人满意。请帮忙。
我使用 numpy 和 matplotlib.pyplot 库编写了程序。
''' creating grids'''
gp = np.linspace(0, L, n)
rho = np.ones(n) * rho0
drhodt = np.empty(n)
t = np.arange(0, t_final, dt)
result = np.zeros((int(t_final/dt), n))
''' computation part'''
for j in range (1, len(t)):
plt.clf()
for i in range (1,n-1):
rho[0] = rho1
rho[n - 1] = rho2
drhodt[i] = (V_r / V) * (rho[i-1] - rho[i] + Rg)
rho = rho + drhodt*dt
result[j] = rho
print(result)
''' plotting the values'''
plt.figure(1)
plt.plot(gp, rho)
plt.axis([0, L, 0, 3000])
plt.xlabel('distance')
plt.ylabel('density')
plt.pause(0.01)
plt.figure(2)
plt.plot(t, result)
plt.axis([0, t_final, 0, 3000])
plt.xlabel('time')
plt.ylabel('density')
plt.show()
'''
我期望代码的结果是密度与网格点和密度与时间的 2 个不同配置文件。但是在运行密度与时间曲线时,我收到了 3 条不需要的不同曲线的错误。我只需要一条曲线来描绘不同时间步长的密度。