Array indices must be positive integers or logical values. Error in WCA (line 44) pop(i).cos​t=objectiv​e_function​(pop(i).po​sition); I am getting this issue while I am running the code of distribution load flow analysis

1 次查看(过去 30 天)
I have attached two files in this questions, the objective is to call the fx file in BackawardFarwardNew_28bus.m to implement the WCA !!, could you please tell how to integrate or what is the issue i am facing here, its quite urgent..!!
for i=1:Npop
pop(i).position=LB+(UB-LB).*rand(1,nvars);
pop(i).cost=objective_function(pop(i).position);
this is the 44th line of water cycle algorithm where i got the error

回答(1 个)

Walter Roberson
Walter Roberson 2021-5-3
In BackwardFarwardNew_28bus.m you have
objective_function = min(P_l);
[Xmin,Fmin,NFEs,Elapsed_Time]=WCA(objective_function,LB,UB,nvars,Npop,Nsr,dmax,max_it)
so you are taking min() of something and passingå it in as objective_function .
What is that thing, P_l ? Well, you have
for i=size(LD,1):-1:1
c=[];
P_l = [];
e=[];
[c e]=find(LD(:,2:3)==LD(i,3));
if size(c,1)-1==0
IB(LD(i,1))=I(LD(i,3));
x = LD(:,4);
P_l = real(((IB(LD(i,1)))^2).*x)
else
IB(LD(i,1))=I(LD(i,3))+sum(IB(LD(c,1)))-IB(LD(i,1));
x =LD(:,4);
P_l = real(((IB(LD(i,1)))^2).*x)
end
end
That runs a loop (backwards), and every iteration of the loop it resets all of P_l to empty, and then it sets P_l to P_l = real(((IB(LD(i,1)))^2).*x) where x = LD(:,4); looks like a column vector. So P_l appears that it will be a column vector after the for loop. With the .* operator, it is most likely numeric, but at the moment we cannot rule out symbolic or even something more strange such as transfer function.
So what is IB ?
IB=zeros(size(LD,1),1);
That is numeric, as was most likely.
So, you loop backwards over the rows of LD, and each time you overwrite all of P_l with a numeric vector. Then afterwards you take min() of the numeric vector, giving a numeric scalar result. And you pass that numeric scalar result into WCA.
What does WCA do with it?
% Water Cycle Algorithm (WCA) (Standard Version)
% This code is prepared for single objective function (minimization), unconstrained, and continuous problems.
so WCA is expecting to minimize a function. Most likely the first parameter,
function [Xmin,Fmin,NFEs,Elapsed_Time]=WCA(objective_function,LB,UB,nvars,Npop,Nsr,dmax,max_it)
objective_function. But you passed a numeric scalar into that position.
pop(i).cost=objective_function(pop(i).position);
objective_function is a numeric scalar. The only valid indices for it are scalar true, any number of false, and any number of numeric 1 . But
pop(i).position=LB+(UB-LB).*rand(1,nvars);
That is not going to be true, false, or 1.
You need to review your BackwardFarwardNew_28bus.m and figure out what it is that you want to minimize. You need to be passing in a function handle, and the function handle has to expect to receive (in the context of your code) a vector of length 6, and the function handle has to return a scalar numeric value.

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by