【发布时间】: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>45)。 -
@Evan Streator:拿起笔和纸,求解 n=0 的公式。你得到
Tn=Tair这绝对是错误的。这就是您对n=inf的期望 -
我知道正确答案是第6天32度左右。但我仍在努力让循环执行此操作。
-
因此,如果我将 Tn 0 并再次运行它,我仍然没有运气。我不知道设置 Tn 等于什么以继续循环更长的时间。我在等式中缺少括号并修复了它,现在与计算器相比可以得到正确的数字,但是我仍然迷失了 Tn。它必须在 while 循环之前定义。 @尼尔
标签: matlab while-loop temperature