我正在上python som编程课,我是个初学者。我们得到了一个任务,我们应该计算和绘制游泳池达到5摄氏度所需的时间。我已经用3个较小的容器(0.3L、0.5L和1.2L)测试了所需的时间,并在python程序中绘制了它们以查找k值。其中k值是冷却它们所用的预计时间。然后我在一个名为“GeoGebra”的程序中使用了回归,在给定体积V的情况下找到了k的函数。现在我卡住了
我要用的池是1.250.000L,我不知道如何把它编成代码并绘制出来,有人知道一些提示吗
这是我用于绘图的代码
import numpy as np
from matplotlib import pyplot as plt
filename = "temperatur.txt"
data = np.loadtxt(filename, float, skiprows = 1)
measurement_start = 0
time = data[measurement_start:, 0]
time -= time[0]
temperature = data[measurement_start:, 1]
plt.plot(time, temperature, 'x', label = "Målingene")
plt.xlabel("Time(s)")
plt.ylabel("Temperaturen(C)")
k = 0.00022
temp_outside = 5
T_0 = temperature[0]
space = 1 # space between measurements
t_start = 0
t_end = 45 * 60
N = int((t_end - t_start) / space + 1)
t = np.linspace(t_start, t_end, N)
T = np.zeros(N)
T[0] = T_0
# Eulers method
for i in range(N-1):
T[i+1] = T[i] + k * (temp_outside - T[i]) * space
print(f"Last valuei: {T[-1]}")
plt.plot(t, T, label = "Model")
plt.plot(t, (temp_outside +1) * np.ones(N), "--", label = "Temp outside + one degree")
plt.title(f"k = {k}")
plt.legend()
This is the outcome i want, just with a pool
提前谢谢
目前没有回答
相关问题 更多 >
编程相关推荐