please how to compare the values of a given parameter between two successive iterations on matlab ?
34 次查看(过去 30 天)
显示 更早的评论
i have the following code and when i run it matlab display the following error message : Attempted to access gbest_FV(0); index must be a positive integer or logical.
Error in GCPSO2 (line 157) if gbest_FV(ite) < gbest_FV(ite-1)
ite =1 ; while ite <= maxite
%ig velocity update for j=1:M v_ig(1,j)= -x_ig0(1,j) + gbest(1,j) + w*v_ig0(1,j) + rho(ite)*(1-2*r) ; end
for j=1:M x_ig(1,j) = gbest(1,j) + w*v_ig(1,j)+ rho(ite)*(1-2*r) ; end
%% velocity update of the other particles for i=1:NP for j=1:M v(i,j)=w.*v0(i,j)+c1*r.*(pbest_x(i,j)-x0(i,j))+c2*r.*(gbest(1,j)-x0(i,j)); end end
%% position update for i=1:NP for j=1:M x(i,j)=x0(i,j)+v(i,j); end end
x_t = zeros(NP+1,1) ; x_t = cat(1,x,x_ig); FV_x_t = fun1(NP,M,x_t,DM1,DM2,pm1,pm2);
%%% updating pbest and its fitness value for i=1:NP+1 if FV_x_t(i,1)< pbest_FV(i,1) pbest_x(i,:)=x_t(i,:); pbest_FV(i,1) = FV_x_t(i,1) ; end end
[FV_x_tmin,index]=min(pbest_FV); % finding out the best particle
%%% updating gbest and best fitness if FV_x_tmin < gbest_FV gbest=pbest_x(index,:) ; gbest_FV= FV_x_tmin ; end sigmaa = 0; if ite>1 if gbest_FV(ite+1) < gbest_FV(ite) sigmaa = sigmaa + 1; end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!