i want the pbest value from p(i) not i value

3 ビュー (過去 30 日間)
Manjutha Manavalan
Manjutha Manavalan 2016 年 5 月 5 日
回答済み: Walter Roberson 2016 年 5 月 5 日
clc;
clear all;
close all;
it=100; %ITERATION
c1=2; %Accelaration coefficient
c2=2;%Accelaration coefficient
w=0.7;%Inertia
%n=10;
i=[1 2 3 4 5 6 7 8 9 10];% particles
p(i)=[0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.10];
% pp=p;
% a=p(5);
% display(a);
x=size(p(i));
position(i)=rand(x);
pos=position(i);
% pos1=position(i);
y=size(p(i));
velocity(i)=rand(y);
for k=1:it
for l=1:i
f=p.^2;
end
%pbest
for d=1:i
% pbest=p;
% pos=position;
val=[p(i)];
poss=[pos];
[poss val]=min(poss);
pbest=val;
% val = min(pbest(~ismember(p,0)));
% ind = find(val==pbest);
end
end
display(pbest);
  1 件のコメント
Adam
Adam 2016 年 5 月 5 日
Please format your whole code and preferably add some information as to what it is doing and what is wrong rather than just pasting in code.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 5 月 5 日
You have the order of outputs reversed for min. The first output is the value and the second is the position; you are using position and then value.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by