while 循环温度随时间下降
while loops for temperature falling over time
我是 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
假设你的公式是正确的,这应该可以完成你的工作:
Tn=200;
while (Tn >= 45)
Tn =((1-((h*A*t)/(m*Cp))^n)*To+Tair);
n=n+1;
end
第一次肯定会进入while循环,然后只要温度超过45就计算新的温度再增加一天。但也许你的公式也有问题?
我是 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
假设你的公式是正确的,这应该可以完成你的工作:
Tn=200;
while (Tn >= 45)
Tn =((1-((h*A*t)/(m*Cp))^n)*To+Tair);
n=n+1;
end
第一次肯定会进入while循环,然后只要温度超过45就计算新的温度再增加一天。但也许你的公式也有问题?