plotting in for loop

1 回表示 (過去 30 日間)
Yusuf Ziya ÜNEL
Yusuf Ziya ÜNEL 2020 年 7 月 5 日
コメント済み: Yusuf Ziya ÜNEL 2020 年 7 月 6 日
I tried to plot a linear continious graph but my graph shows only specific dots. I tried to turn my output data of for loop but an error comes up. Can anyone help me to plot a decent graph?
length_1 = 20; % house length parameters
length_2 = 10;
length_3 = 4;
beta = 40; % roof angle
N_win = 4; % number of windows
N_wall = 1; % number of walls "all in one'
areaWin = 1; % area of windows
areaWall = 236; % area off walls
thermWall = 136.8; % wall thermal coeffient
thermWin = 2808; % window thermal coeffient
thickWin = 0.07; % thickness of wind
thickWall = 0.2; % thickness of walls
airDen = 1.225; % air density
ca = 1.01; % thermal capasity of air
COP = 2; % coeffiecient of performance
P = 3; % power 3KW
Volume = (length_1*length_2*length_3) + (tand(beta)*length_1*length_2); %house volume
mass = Volume*airDen;
R_win = (1/N_win) * (thickWin/(thermWin*areaWin)); %resistance of windows
R_wall = (1/N_wall) * (thickWall/(thermWall*areaWall)); %resistance of walls
Rh = 1/(1/R_wall + 1/R_win); %paralel circuit
fprintf("Volume = %f\n",Volume)
fprintf("Mass = %f\n",mass)
fprintf("Walls' R = %f\n",R_wall)
fprintf("Windows' R = %f\n",R_win)
fprintf("Rh = %f\n\n",Rh)
deltaT = 0.1; %6 minutes period of an hour = 6/60
Tini = 19; %initial temp starts with fav temp of household's owner
Ptotal = 0; %total power consumption counter
for t = 12:0.1:16 %Time between 12-16 o'clock
Tout=0;
fprintf("Time = %.2f\n",t);
fprintf("Tin,h = %.2f\n\n",Tini);
plot(t,Tini,"r-o")
grid on
hold off
if (t>12) && (t<14.1)
Tout = 30; %12am-14am outside temperature
elseif (t>14) && (t<15.1)
Tout = 31; %14am-15am outside temperature
elseif (t>15) && (t<16.1)
Tout = 30; %15am-16am outside temperature
end
if Tini<21
U = 0; %HVAC is OFF
else
U = 1; %HVAC is ON
end
hold on
Tini=((1-(deltaT/(1000*mass*Rh)))*Tini+(deltaT/(1000*mass*Rh))*Tout-U*((COP*P*deltaT)/(0.000277*mass*ca)));
Ptotal = Ptotal + P*U; %total power
end
fprintf("Total Power Consumption = %.d KW\n",Ptotal)

回答 (1 件)

darova
darova 2020 年 7 月 5 日
See my recommendations
  3 件のコメント
darova
darova 2020 年 7 月 6 日
can you show the code?
Yusuf Ziya ÜNEL
Yusuf Ziya ÜNEL 2020 年 7 月 6 日
length_1 = 20; %house length parameters
length_2 = 10;
length_3 = 4;
beta = 40; %roof angle
N_win = 4; %number of windows
N_wall = 1; %number of walls "all in one"
areaWin = 1; %area of windows
areaWall = 236; %area off walls
thermWall = 136.8; %wall thermal coeffient
thermWin = 2808; %window thermal coeffient
thickWin = 0.07; %thickness of windows
thickWall = 0.2; %thickness of walls
airDen = 1.225; %air density
ca = 1.01; %thermal capasity of air
COP = 2; %coeffiecient of performance
P = 3; %power 3KW
Volume = (length_1*length_2*length_3) + (tand(beta)*length_1*length_2); %house volume
mass = Volume*airDen;
R_win = (1/N_win) * (thickWin/(thermWin*areaWin)); %resistance of windows
R_wall = (1/N_wall) * (thickWall/(thermWall*areaWall)); %resistance of walls
Rh = 1/(1/R_wall + 1/R_win); %paralel circuit
fprintf("Volume = %f\n",Volume)
fprintf("Mass = %f\n",mass)
fprintf("Walls' R = %f\n",R_wall)
fprintf("Windows' R = %f\n",R_win)
fprintf("Rh = %f\n\n",Rh)
t = 12:0.1:16;
deltaT = 0.1; %6 minutes period of an hour = 6/60
Tini = 19; %initial temp starts with fav temp of household's owner
Tout = 30; %for debugging
Ptotal = 0; %total power consumption counter
for i = 1:length(t)
fprintf("Time = %.2f\n",t);
fprintf("Tin,h = %.2f\n\n",Tini);
plot(t,Tini);
xlabel("Time")
ylabel("T_in,h")
grid on
if t(i)>12 && t(i)<14.1
Tout = 30; %12am-14am outside temperature
elseif t(i)>14 && t(i)<15.1
Tout = 31; %14am-15am outside temperature
elseif t(i)>15 && t(i)<16.1
Tout = 30; %15am-16am outside temperature
end
if Tini(i)<21
U = 0; %HVAC is OFF
else
U = 1; %HVAC is ON
end
hold on
Tini(i+1)=((1-(deltaT/(1000*mass*ca*Rh)))*Tini(i)+(deltaT/(1000*mass*ca*Rh))*Tout-U*((COP*P*deltaT)/(0.000277*mass*ca)));
Ptotal = Ptotal + P*U; %total power
end
fprintf("Total Power Consumption = %.d KW\n",Ptotal)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeElectrical Block Libraries についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by