首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何写一段代码,让我得到周期性的循环曲线呢?

我如何写一段代码,让我得到周期性的循环曲线呢?
EN

Stack Overflow用户
提问于 2017-11-23 04:36:48
回答 1查看 44关注 0票数 0

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

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

图片来源:Cycling curve graph going from 50 to 90

这是我的代码:

if (温度<= 55)

热();

else if ( temperature >=90)

cool();

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

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

EN

回答 1

Stack Overflow用户

发布于 2017-11-23 06:13:51

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

这是一个具有线性“加热/冷却”模型和bang-bang控制器的动态系统仿真。

代码语言:javascript
复制
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)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47443491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档