我怎么写这样一个代码,让我周期性的循环曲线?

2024-04-23 16:13:05 发布

您现在位置:Python中文网/ 问答频道 /正文

这里的背景是,我试图加热和冷却一个物体,我试图得到循环温度控制系统

假设房间温度=25摄氏度(这是物体开始时的温度)。我想建立一个曲线看到的图像。当物体被加热到90度后,当它达到90度时应该冷却,当物体冷却到55度时,应该加热到90摄氏度

图片:Cycling curve graph going from 50 to 90

这是我的密码:

如果(温度<;=(第55页)

加热()

else if(温度>=90)

酷()

当温度值为56到89时,会发生什么

我的解决方案是在开头放一个heating函数,比如heat(),然后是if-else语句


Tags: from图像if图片温度else曲线graph
1条回答
网友
1楼 · 发布于 2024-04-23 16:13:05

你真的应该在编码方面做得更好,但我很无聊

这是一个动态系统模拟与线性'加热/冷却'模型和邦邦控制器

r_t =  1  # thermal resistance
t_cold = 0.8  # cooling temp
t_hot = 2.2   # heating temp
t_lo, t_hi = 1, 2  # controller thresholds
c_t = 100  # heat capacity

t_obj = [0]  # really cold start temp
h = []
for s in range(1000):
    if t_obj[-1] < t_lo:  # bang-bang logic
        heat = 1
    elif t_obj[-1] > t_hi:
        heat = 0

# equation integrating the the heat/cooling input to t_obj

    t_obj += [t_obj[-1] + ((heat * t_hot + (1 - heat) * t_cold) - t_obj[-1])/r_t/c_t]
    h.append(heat)

plt.plot(h)    # debug plot of `heat` state
plt.plot(t_obj)

enter image description here

相关问题 更多 >