Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2. don't know how to fix this
1 次查看(过去 30 天)
显示 更早的评论
K = 1;% Assuming all minor losses to currently be 1
g = 32.2;
NL = 2;%Number of loops
NJ = [6;5]; % The total number of lines for the given problem/network
IW = 50000;%Number of iterations
epsln = 0.00085; % Roughness factor for Cast Iron Pipes
% Pipe Length Matrix [ft]
ZL(1,1) = 600; ZL(1,2) = 500; ZL(1,3) = 200; ZL(1,4) = 400; ZL(1,5) = 400; ZL(1,6) = 500;
ZL(2,1) = 450; ZL(2,2) = 500; ZL(2,3) = 300; ZL(2,4) = 250; ZL(2,5) = 500;
% Pipe Diameter Matrix [ft]
D(1,1) = 8/12; D(1,2) = 16/12; D(1,3) = 6/12; D(1,4) = 6/12; D(1,5) = 6/12; D(1,6) = 8/12;
D(2,1) = 6/12; D(2,2) = 6/12; D(2,3) = 6/12; D(2,4) = 8/12; D(2,5) = 8/12;
% Flow rate Matrix (cfs
Q(1,1) = 0.31175; Q(1,2) = 0.31175; Q(1,3) = 0.31175; Q(1,4) = 0.22265; Q(1,5) = 0.13355; Q(1,6) = 0.1559;
Q(2,1) = 0.1559; Q(2,2) = 0.114; Q(2,3) = 0.0695; Q(2,4) = 0.28945; Q(2,5) = 0.1559;
% Common lines
ID(1,1) = 0; ID(1,2) = 0; ID(1,3) = 0; ID(1,4) = 0; ID(1,5) = 0; ID(1,6) = 2;
ID(2,1) = 0.; ID(2,2) = 0; ID(2,3) = 0; ID(2,4) = 0; ID(2,5) = 1;
for IT = 1:IW
for I = 1:NL
for J = 1:NJ(I)
ReD(I,J) = 4*abs(Q(I,J))/(pi*D(I,J)*v);
% Calculate Friction factor and DF/DQ
if ReD < 2000
Fr(I,J) = 64/ReD;
DF_DQ(I,J) = -64/(ReD(I,J)*Q(I,J));
else
H = (abs(ReD(I,J)))^0.9;
A = epsln/(3.7*D(I,J)); B = 5.74/(ReD(I,J).^0.9); C = 5.74/H;
Fr(I,J) = 1.325/((log(A + B)).^2);
DF_DQ(I,J) = (13.69*(A + C)^-1)/(H*Q(I,J)*((log(A + C))^3));
end
alpha = 8*ZL(I,J)/(pi^2*g*D(I,J)^5); beta(I,J) = (8*K)/(pi^2*g*(D(I,J)^4)); %#ok<SAGROW>
if Q(I,J) < 0
Hf(I,J) = -(alpha*Q(I,J)^2*Fr(I,J))+ beta*Q(I,J)^2;
DHDQ(I,J) = -(2*alpha*Fr(I,J)*Q(I,J) + alpha*(Q(I,J)^2)*DF_DQ(I,J));
else
Getting Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2.for thhis code
145; Hf(I,J) = alpha*abs((Q(I,J).^2)*Fr(I,J)) + abs(beta*Q(I,J)^2);
DHDQ(I,J) = (2*alpha*Fr(I,J)*Q(I,J) + alpha*(Q(I,J)^2)*DF_DQ(I,J));
end
end
end
% Define the correction factor for each loop
for I = 1:NL
sum_Hf(I) = 0; sum_DHDQ(I) = 0;
for J = 1:NJ(I)
sum_Hf(I) = sum_Hf(I) + Hf(I,J);
sum_DHDQ(I) = sum_DHDQ(I) + DHDQ(I,J);
end
DeltaQ(I) = -sum_Hf(I)/(sum_DHDQ(I)); % % Correction Factor for each loop
end
for I = 1:NL
for J = 1:NJ(I)
if ID(I,J) == 0 % For Uncommon Lines With No Shared Loops
Q_N(I,J) = Q(I,J) + DeltaQ(I);
else % For Common Lines With Shared Loops
g = ID(I,J);
Q_N(I,J) = Q(I,J) + DeltaQ(I) - DeltaQ(g);
end
end
end
% Convergence Test
for I = 1:NL
for J = 1:NJ(I)
Q_D = abs(Q_N(I,J) - Q(I,J));
end
end
if Q_D > EPSLN
for I = 1:NL
for J = 1:NJ(I)
Q(I,J) = Q_N(I,J); % Do another iteration until it passes the convergence test
end
end
end
if Q_D < EPSLN
break; % It passes the convergence test
end
end
fprintf('The new flow rates (ft^3/s) for each pipe are \n');
fprintf('----------------------------------------------\n');
fprintf(' Line: 1 | 2 | 3 | 4 \n');
fprintf(' Loop 1: %1.3f | %1.3f | %1.3f | %1.3f | %1.3f %1.3f \n',Q_N(1,1),Q_N(1,2),Q_N(1,3),Q_N(1,4),Q_N(1,5),Q_N(1,6));
fprintf(' Loop 2: %1.3f | %1.3f | %1.3f | %1.3f | %1.3f %1.3f \n',Q_N(2,1),Q_N(2,2),Q_N(2,3),Q_N(2,4),Q_N(2,5),Q_N(2,6));
fprintf('----------------------------------------------\n');
回答(1 个)
Walter Roberson
2020-2-28
alpha = 8*ZL(I,J)/(pi^2*g*D(I,J)^5); beta(I,J) = (8*K)/(pi^2*g*(D(I,J)^4)); %#ok<SAGROW>
The second part of that line is growing beta as the loop indices increase.
Hf(I,J) = -(alpha*Q(I,J)^2*Fr(I,J))+ beta*Q(I,J)^2;
That code uses all of beta. As soon as beta grew to two elements, the right hand side becomes two elements, but the left hand side only names one location to store into.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!