need to use Find function
3 次查看(过去 30 天)
显示 更早的评论
Hello..I already done for this..but when i'm run this program..Lbest should be different answer..but sometimes this program will show or get the same answer for Lbest..so how i need to do with this program by using find function to solve this problem..thank you for your helping me to solve this problem..
% Gravitational Search Algorithm. function [Fbest,Lbest,BestChart,MeanChart]=GSA(F_index,N,max_it,ElitistCheck,min_flag,Rpower)
%V: Velocity. %a: Acceleration. %M: Mass. Ma=Mp=Mi=M; %dim: Dimension of the test function. %N: Number of agents. %X: Position of agents. dim-by-N matrix. %R: Distance between agents in search space. %[low-up]: Allowable range for search space. %Rnorm: Norm in eq.8. %Rpower: Power of R in eq.7.
Rnorm=2;
%get allowable range and dimension of the test function. [low,up,dim]=test_functions_range(F_index);
%random initialization for agents. X=initialization(dim,N,up,low);
%create the best so far chart and average fitnesses chart. BestChart=[];MeanChart=[];
V=zeros(N,dim);
%find function %find(Lbest);
for iteration=1:max_it % iteration
%Checking allowable range.
X=space_bound(X,up,low);
%Evaluation of agents.
fitness=evaluateF(X,F_index);
if min_flag==1
[best best_X]=min(fitness); %minimization.
else
[best best_X]=max(fitness); %maximization.
end
if iteration==1
Fbest=best;Lbest=X(best_X,:);
end
if min_flag==1
if best<Fbest %minimization.
Fbest=best;Lbest=X(best_X,:);
end
else
if best>Fbest %maximization
Fbest=best;Lbest=X(best_X,:);
end
end
BestChart=[BestChart Fbest]; MeanChart=[MeanChart mean(fitness)];
%Calculation of M. eq.14-20 [M]=massCalculation(fitness,min_flag);
%Calculation of Gravitational constant. eq.13. G=Gconstant(iteration,max_it);
%Calculation of accelaration in gravitational field. eq.7-10,21. a=Gfield(M,X,G,Rnorm,Rpower,ElitistCheck,iteration,max_it);
%Agent movement. eq.11-12 [X,V]=move(X,a,V);
end %iteration
Hello..I already done for this..but when i'm run this program..Lbest should be different answer..but sometimes this program will show or get the same answer for Lbest..so how i need to do with this program by using find function to solve this problem..thank you for your helping me to solve this problem..
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!