what does the error mean "Index in position 2 exceeds array bounds (must not exceed 1). Error in heat2 (line 116) if abs(Qforced(r,c) - Qfree(1,iterations)) < 0.001"

1 visualización (últimos 30 días)
line 116 is underlined below
Tamb = linspace(261,283,10); %in Kelvin
Vwind = linspace(2.778,19.44,10);%in m/s
Tfree = linspace(150,308,10000); %in Kelvin
%constants
dia = 0.3; %in m
length = 1.8; %in m
Thum = 308; %in Kelvin
grav = 9.81; %m/s^2
k250 = 0.02227;
k300 = 0.02624;
dens250 = 1.4128;
dens300 = 1.1774;
visc250 = 1.5990*10^(-5);
visc300 = 1.8462*10^(-5);
Pr250 = 0.722;
Pr300 = 0.708;
r = 1;
c = 1;
hforced = zeros(100);
hfree = zeros(100);
Twind = zeros(100);
Qforced = zeros(10);
Qfree = zeros(10);
while r <= 10
while c <= 10
Tfilm = (Thum + Tamb(1,c))/2; %film t in Kelvin
%interpolation k, dens, visc, and Pr
k = ((k300-k250)/(300-250))*(Tfilm-250)+k250;
dens = ((dens300-dens250)/(300-250))*(Tfilm-250)+dens250;
visc = ((visc300-visc250)/(300-250))*(Tfilm-250)+visc250;
Pr = ((Pr300-Pr250)/(300-250))*(Tfilm-250)+Pr250;
%to get forced convection
Re = (Vwind(1,r) * dens * dia)/visc;
%if Re
cf1 = 0.0266;
nf1 = 0.805;
Nud = cf1*(Re^(nf1))*Pr^(1/3); %40,000<Re<400,000
%end
hf1 = (Nud*k)/dia;
%to get free convection
Beta = Tfilm^-1;
Gr = (length^3*(Thum-Tamb(1,c))*(dens^2)*Beta*grav)/visc^2;
Ra = Gr*Pr;
if Ra >= 10^4 && Ra <= 10^9
cf2 = 0.59;
mf2 = 1/4;
else if Ra > 10^9 && Ra <= 10^13
cf2 = 0.1;
mf2 = 1/3;
end
end
Nuf = cf2*(Ra^(mf2));
%end
hf2 = (Nuf*k)/length;
%to get wind chill temp
Twd = Thum - (hf1*(Thum-Tamb(1,c)))/hf2;
Qforced = hf1 * (Thum-Tamb(1,c));
Qfree = hf2 * (Thum-Tamb(1,c));
hforced(r,c)=hf1;
hfree(r,c)=hf2;
c = c + 1;
end
c = 1;
r = r + 1;
end
f = 1;
Qfree = 0;
while f <= 100
Tfilm = ((Thum + Tfree(1,f))/2); %film t in Kelvin
%interpolation k, dens, visc, and Pr
k = ((k300-k250)/(300-250))*(Tfilm-250)+k250;
dens = ((dens300-dens250)/(300-250))*(Tfilm-250)+dens250;
visc = ((visc300-visc250)/(300-250))*(Tfilm-250)+visc250;
Pr = ((Pr300-Pr250)/(300-250))*(Tfilm-250)+Pr250;
%q te forced
%q related to velocity and t
%to get free convection
Beta = 1/Tfilm;
Gr = (length^3*(Thum-Tamb(1,c))*(dens^2)*Beta*grav)/visc^2;
Ra = Gr*Pr;
if Ra >= 10^4 && Ra <= 10^9
cf2 = 0.59;
mf2 = 1/4;
else if Ra > 10^9 && Ra <= 10^13
cf2 = 0.1;
mf2 = 1/3;
end
end
Nuf = cf2*(Ra^(mf2));
%end
hf2 = (Nuf*k)/length;
hfree(1,f) = hf2;
%to get wind chill temp
Qfree = hf2 * (Thum-Tfree(1,f));
f = f + 1;
end
r = 1;
c = 1;
iterations = 1;
TwindChill = zeros(10);
while r <= 10
while c<= 10
while iterations <= 10000000
if abs(Qforced(r,c) - Qfree(1,iterations)) < 0.001 --> line 116
TwindChill(r,c) = Tfree(1,iterations) - 273;
else
TwindChill(r,c) = TwindChill(r,c);
end
iterations = iterations + 1;
end
iterations = 1;
c= c+1;
end
c=1;
r = r +1;
end
%output Twind hforced hfree
Twd;
hforced;
hfree;
%plot Twind, Tamb, Vwind
%plot3(Twind, Tamb, Vwind, 'r-');
%grid on;
%legend('Wind Chill') %change the file name
%xlabel('Wind Chill Temperature')
%ylabel('Ambient Temperature')
%zlabel('Wind Velocity')
%smooth lines
%hold on

Respuestas (1)

Asvin Kumar
Asvin Kumar el 9 de Jun. de 2020
At some point in your program, either the ‘r’ or ‘c’ or ‘iterations’ variables are being used to index into a position in their respective matrices which does not exist. So, this might mean one or many of these things:
  1. The value of ‘r’ is larger than the number of rows in Qforced. Use >> size(Qforced,1) to find the number of rows in ‘Qforced’.
  2. The value of ‘c’ is larger than the number of columns in ‘Qforced’. Use >> size(Qforced,2) to find the number of columns in ‘Qforced’.
  3. The value of ‘iterations’ is larger than the number of columns in ‘Qfree’. Use >> size(Qfree,2) to find the number of columns in ‘Qfree’.

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by