[英]MATLAB - how to create condition with specific requirements
我正在模擬水加熱,我需要創造一定的條件,我不知道如何正確創建它。
所需的水溫為55°C。 最低溫度為50°C。 最高溫度為70°C。
我有兩種類型的加熱 - 電加熱,將水加熱到55°C的所需溫度,光伏加熱,可將水加熱到最高溫度。
我需要創造一個條件,只有當溫度低於50°C時才開啟電加熱,並在達到55°C后停止。 如果溫度在50到55之間而沒有預先在50°C下降,則只能進行光伏加熱並且電加熱關閉。
全年每分鍾檢查一次溫度。 條件將被置於循環中。
現在,我沒有所需的溫度條件(55°C),如下所示:
for i = 1:525600
if (temeprature(i) < 70)
heating = 1; %heating from photovoltaic
else
heating = 0; % heating off
end
if (temperature(i) < 50)
heating = 2; % electric heating when there is not enough power from PV
end
if heating==0
calculations
calling functions
etc.
...
end
if heating==1
calculations
calling functions
etc.
...
end
if heating==2
calculations
calling functions
etc.
...
end
computing temperature with results from conditions
end
謝謝你的建議。
我將使用持久變量進行電加熱功能:
function [el, pv] = whatHeating(T)
persistent elHeat
if (isempty(elHeat))
elHeat = false; % Initialize to false. The only thing where it matters is if you start at 50<T<55.
end
if (T < 50)
elHeat = true;
elseif (T > 55)
elHeat = false;
end
el = elHeat; % You can't return persistent variable directly.
if (T > 70)
pv = false;
else
pv = true;
end
然后你只需在主要功能中調用此功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.