【问题标题】:while loops for temperature falling over time温度随时间下降的while循环
【发布时间】:2016-02-01 11:52:40
【问题描述】:

我是 MATLAB 新手,正在学习如何使用 while 循环。我在使用 while 循环来解决需要计算罐中温度的问题时遇到了麻烦。水箱从 200 度开始,我需要找出它需要多少天才能降到 45 度以下,到目前为止,我只能让 MATLAB 运行一次程序,然后在 168 度处停止。如果有人可以提供帮助,将不胜感激。

% This program will calculate the # of days it will take for the...
... temperature in the tank to drop below 45 degrees celsius
clc
clear
A = 60; %Surface area of the tank in m^2
t = 86400; %Number of seconds in a day 
Cp = 4980; %The heat capacity of the liquid in  J/(kg*°C)
Tair = 23; %Average temperature surrounding the tank in °C 
To = 200; %Average ethylene glycol temperature on day 0 in °C 
h = 9.2; %The heat transfer coefficient in W/(m2*°C)
m = 35000; %The mass of liquid in the tank in kg
n = 0; %The day
Tn=0
while (Tn < 45)
    Tn =((1-((h*A*t)/(m*Cp))^n)*To+Tair);
    n=n+1;
end
Tn
n

【问题讨论】:

  • 在不知道 Matlab 是如何工作的情况下,它似乎最初进入了 while 循环,因为 Tn 为 0。你第一次执行计算,它给你一个 23。N 从 0 增加到 1 ,第二次得到 0.726*200 + 23 即 168。N 再次上升,但 Tn 不再低于 45 并且您的 while 循环结束。我猜是不是计算错了?
  • @Neil:你有一半的问题,应该是while(Tn&gt;45)
  • @Evan Streator:拿起笔和纸,求解 n=0 的公式。你得到Tn=Tair 这绝对是错误的。这就是您对n=inf 的期望
  • 我知道正确答案是第6天32度左右。但我仍在努力让循环执行此操作。
  • 因此,如果我将 Tn 0 并再次运行它,我仍然没有运气。我不知道设置 Tn 等于什么以继续循环更长的时间。我在等式中缺少括号并修复了它,现在与计算器相比可以得到正确的数字,但是我仍然迷失了 Tn。它必须在 while 循环之前定义。 @尼尔

标签: matlab while-loop temperature


【解决方案1】:

假设您的公式是正确的,这应该可以完成您的工作:

Tn=200;
while (Tn >= 45)
    Tn =((1-((h*A*t)/(m*Cp))^n)*To+Tair);
    n=n+1;
end

它肯定会第一次进入while循环,然后只要温度超过45,就会再计算一天的新温度。但也许你的公式也有问题?

【讨论】:

  • 该程序现在可以使用此修复程序!非常感谢!
  • 小幅修正,Tn >= 45(操作提到低于 45)。
猜你喜欢
  • 1970-01-01
  • 2013-12-08
  • 2016-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-24
  • 1970-01-01
  • 2017-02-27
相关资源
最近更新 更多