📄 chap2_ex7_2.m
字号:
% Chap2_Ex7_2.m
clc; close all; clear all
R=0.0008; C=300; Qbar=36000;
tau=R*C;
T0=50; % outside temperature
Tinit=T0; % initial temperature
Tss=R*Qbar+T0;
Td=75; % desired temperature
del=3; % thermostat swing
T_low=Td-del; % low thermostat cutoff
T_high=Td+del; % high thermostat cutoff
t1=tau*log((Tss-T0)/(Tss-T_high));
t2=t1+tau*log((T_high-T0)/(T_low-T0));
t3=t2+tau*log((Tss-T_low)/(Tss-T_high));
Tstep=0.001;
Tfinal=t3;
nfinal=round(Tfinal/Tstep);
t(1)=0;
T_A(1)=Tinit;
%%%%% T(n) section %%%%%
for n=1:nfinal
t(n+1)=n*Tstep;
if T_A(n) < T_low % check if T is below lower thermostat cutoff
Q=Qbar; % furnace is on
elseif T_A(n) > T_high % check if T is above upper thermostat cutoff
Q=0; % furnace is off
elseif T_low < T_A(n) & T_A(n) < T_high & T_A(n) > T_A(n-1) % check if T is in thermostat band and increasing
Q=Qbar;
else % T is in thermostat band and decreasing
Q=0;
end % if
T_A(n+1)=(1-Tstep/tau)*T_A(n)+(Tstep/tau)*(R*Q+T0); % update T_A
end % for
freq=25;
plot(t(1:freq:end),T_A(1:freq:end),'.')
hold on
xlabel('\itt \rm(hrs)','FontSize',11)
ylabel('\itT \rm(deg F)','FontSize',11)
%%%%% T(t) section %%%%%
ti=linspace(0,t1,100);
Ti=Tinit*exp(-ti/tau)+Tss*(1-exp(-ti/tau));
plot(ti,Ti)
ti=linspace(t1,t2,50);
Ti=T_high*exp(-(ti-t1)/tau)+T0*(1-exp(-(ti-t1)/tau));
plot(ti,Ti)
ti=linspace(t2,t3,100);
Ti=T_low*exp(-(ti-t2)/tau)+Tss*(1-exp(-(ti-t2)/tau));
plot(ti,Ti)
plot([0 1.5],[T_low T_low],':')
plot([0 1.5],[T_high T_high],':')
legend('\itT_{A}\rm(\itn\rm), \itn \rm= 0,25,50,...','\itT\rm(\itt\rm), \itt \geq \rm 0',4)
text(0.4,65,'Step size \Delta\itT \rm= 0.001 hr','FontSize',11)
text(0.1,73,'\itT_{d} - \Delta','FontSize',11)
text(0.1,79,'\itT_{d} + \Delta','FontSize',11)
title('Building Temperature vs Time','FontSize',11)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -