绘图命令在MatLab代码中不起作用

时间:2020-07-17 09:08:21

标签: matlab plot simulation

我正在编写一个代码,旨在绘制沿水箱的热水存储温度。代码如下:

Th = 50; % Hot Temperature (C)
Tc = 20; % Cold Temperature (C)
Tave = (Th+Tc)/2; % Average Temperature (C)
mf = 0.01; % Mass Flow Rate (kg/s)
H = 1.77; % Tank Height (m)
Dtank = 1.2; % Tank Diameter (m)
Dpipe = 0.05; % Inlet Pipe Diameter (m)
visc = 0.00070057; % Average Fluid Viscosity (m2/s)
rhoH = 987.68; % Hot Water Density (kg/m3)
rhoC = 997.78; % Cold Water Density (kg/m3)
rho = 0.5*(rhoH + rhoC); % Average Fluid Density (kg/m3)
k = 0.62614; % Thermal Conductivity (W/mK)
cp = 4068.5; % Specific Heat Capacity (J/kgK)
beta = 0.00032452; % Thermal Expansion Coefficient
% (1/K)
alfa = k/(rho*cp); % Diffusivity (m2/s)
g = 9.81; % Gravitational Acceration
% (m/s2)
N = 100; % Number of Nodes
delt = 1; % Time Step Size (s)
tTotal = 7200; % Total Simulation Time (s)
NumDiff = 1; % Activate Numerical Diffusivity (0 = OFF, 1 = ON)
Q = mf/rho; % Volumetric Flow Rate (L/min)
Ac = (pi/4)*(Dtank^2); % Tank Cross-section area (m2)
u = mf/(rho*(pi/4)*(Dtank^2)); % Mean Flow Velocity (m/s)
uIN = mf/(rhoH*(pi/4)*(Dpipe^2)); % Inlet Pipe Velocity (m/s)
x(1:N,1) = (H/(2*N)):(H/N):(H-H/(2*N)); % Node Locations
tEND = (tTotal/delt)+1; % Final Time Step Number
t(1:tEND,1) = 0:delt:tTotal; % Simulation time at each step(s)
if u == 0
C(1:tEND,1) = H/2; % Location of thermocline (no fluid flow) (m)
else
C = u*t; % Location of thermocline with time (w/ fluid flow) (m)
end
alfa = alfa + NumDiff*0.5*u*(H/N);
for i = 1:tEND
   for j = 1:N
      if x(j,1) > C(i,1) % Below Thermocline
          T(i,j) = Tave + (Tc-Tave)*erf((x(j,1)-C(i,1))/sqrt(4*alfa*t(i,1)));
      elseif x(j,1) < C(i,1) % Above Thermocline
          T(i,j) = (Tc + Th) - (Tave +(Tc-Tave)*erf((C(i,1)-x(j,1))/sqrt(4*alfa*t(i,1))));
      end
   end
end
figure(1)
plot(x(1:N,1),T(i,j))
title('temperature profile along the tank: Ideal Analytical Model')
xlabel('Tank Depth(m)')
ylabel('Temperature(°C)')

问题是尽管轴范围正确,但是plot命令在图框中未显示该图。如果您能提供帮助,我将不胜感激。

0 个答案:

没有答案