Index exceeds the number of array elements, must not exceed 1, in a nested for loop

3 views (last 30 days)
In my code, I am analyzing a heat concentric heat exchanger and am solving for h, the local convection coefficients at points along the length of the of tube. In my nested for loop, indexed by j, I am attempting to update the length 0, dDh, for each iteration of the Nsselt number Nud. However, I keep getting the error that the index exceeds the number of array elements. there are 10 distance steps and 10 mass flow rates to analyze, so I am confused on why the sizes are a probelm. Any help is appreciated.
```clear
clc
% givens for the air
ma = 15; %kg/s
Tai = 1200; % deg-C
cpa = 1.207; % kJ/kg-K @ 1200C
ODa = 0.05; % m
IDa = 0.04; % m
% givens for the feedwater
mw = 10; %kg/s
Twi = 250; % deg-C
Two = 500; % deg-C
cpw = 4.860; % kJ/kg-K @ 250C
ODw = 0.01; %m
IDw = 0.008; %m
L = 5; %m, length of HEX bundle
Cc = mw*cpw;
Ch = ma*cpa;
A = [Cc, Ch];
Cmin = min(A);
Cmax = max(A);
Cr = Cmin/Cmax;
Tao = Tai - ((Cmax/Cmin)*(Two-Twi)); %air outlet temperature in deg-C
dT1 = Tai-Two;
dT2 = Tao - Twi;
LMTD = (dT2 - dT1)/log(dT2/dT1); %log mean temperature difference for the HEX
e = (Cc*(Two-Twi))/(Cmin*(Tai-Twi)); %HEX effectiveness
NTU = (1/(Cr-1))*log((e-1)/((e*Cr)-1)); % Net Transfer Units
Aht = pi*ODw*L; % heat transfer area (ft^2), or the outside surface area of the feedwater tube
U = (NTU*Cmin)/Aht; % overall heat transfer coefficient
%%% PART B
mw2 = [0.01:0.01:0.1]; %water mass flow rate in kg/s
rho_w = 798.6; %lg/m^3
Ac = 0.25*pi*IDw^2; %cross-sectional area of the inside of the feedwater tube
Dh = (4*Ac)/(4*pi*IDw); % hydraulic diameter for the feedwater tube
muw = 0.0001063; % dynamic visocsity of the water @ 250C (N*s/m^2)
Uw = zeros(1,length(mw2));
Red = zeros(1,length(mw2));
Nud = zeros(1,length(mw2));
k = 8; %W/m-K. thermal conductivity of water @250-C, guess beased on lower figures
step = Dh/9;
dDh = [0:step:Dh]; %size of the hydraulic diameter
h = zeros(length(mw2),length(dDh));
for i = 1:10
Uw(i) = mw2(i)/(rho_w*Ac); %velocity of the feedwater for the varying flow rates
Red(i) = (rho_w*Uw(i)*Dh)/muw;
Pr = (muw*cpw)/k;
if Red <= 5000
Nud = 4.36;
elseif Red > 5000
Nud(i) = 0.023*(Red(i)^0.8)*(Pr^0.4);
end
for j = 1:10
h(i,j) = (Nud(i)*k)/dDh(j);
end
end```

Accepted Answer

Torsten
Torsten on 10 Dec 2023
Edited: Torsten on 11 Dec 2023
Use
clear
clc
% givens for the air
ma = 15; %kg/s
Tai = 1200; % deg-C
cpa = 1.207; % kJ/kg-K @ 1200C
ODa = 0.05; % m
IDa = 0.04; % m
% givens for the feedwater
mw = 10; %kg/s
Twi = 250; % deg-C
Two = 500; % deg-C
cpw = 4.860; % kJ/kg-K @ 250C
ODw = 0.01; %m
IDw = 0.008; %m
L = 5; %m, length of HEX bundle
Cc = mw*cpw;
Ch = ma*cpa;
A = [Cc, Ch];
Cmin = min(A);
Cmax = max(A);
Cr = Cmin/Cmax;
Tao = Tai - ((Cmax/Cmin)*(Two-Twi)); %air outlet temperature in deg-C
dT1 = Tai-Two;
dT2 = Tao - Twi;
LMTD = (dT2 - dT1)/log(dT2/dT1); %log mean temperature difference for the HEX
e = (Cc*(Two-Twi))/(Cmin*(Tai-Twi)); %HEX effectiveness
NTU = (1/(Cr-1))*log((e-1)/((e*Cr)-1)); % Net Transfer Units
Aht = pi*ODw*L; % heat transfer area (ft^2), or the outside surface area of the feedwater tube
U = (NTU*Cmin)/Aht; % overall heat transfer coefficient
%%% PART B
mw2 = [0.01:0.01:0.1]; %water mass flow rate in kg/s
rho_w = 798.6; %lg/m^3
Ac = 0.25*pi*IDw^2; %cross-sectional area of the inside of the feedwater tube
Dh = (4*Ac)/(4*pi*IDw); % hydraulic diameter for the feedwater tube
muw = 0.0001063; % dynamic visocsity of the water @ 250C (N*s/m^2)
k = 8; %W/m-K. thermal conductivity of water @250-C, guess beased on lower figures
step = Dh/9;
dDh = [0:step:Dh]; %size of the hydraulic diameter
h = zeros(length(mw2),length(dDh));
for i = 1:10
Uw = mw2(i)/(rho_w*Ac); %velocity of the feedwater for the varying flow rates
Red = (rho_w*Uw*Dh)/muw;
Pr = (muw*cpw)/k;
if Red <= 5000
Nud = 4.36;
elseif Red > 5000
Nud = 0.023*(Red^0.8)*(Pr^0.4);
end
for j = 1:10
h(i,j) = (Nud*k)/dDh(j);
end
end
or change at least this part
if Red <= 5000
Nud = 4.36;
elseif Red > 5000
Nud(i) = 0.023*(Red(i)^0.8)*(Pr^0.4);
end
to
if Red(i) <= 5000
Nud(i) = 4.36;
elseif Red(i) > 5000
Nud(i) = 0.023*(Red(i)^0.8)*(Pr^0.4);
end

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!