problem in coding of firefly algorithm

hi
i am writing a program, in which i take three variable p1,p2,p3, and their object is to reach at position "t" in the shape of swarm. means at the end of iteration all variables value will be 50. here i just write the initial stage coding of program, but i am not getting the correct response. can any body help me, i will be thankful
regards
p1=10
p2=15
p3=20
t=50
b0=1
gamab=1 %initial
gamae=10 %final
for i=1:50
d1=t-p1
r1=sqrt((d1)^2)
d2=t-p2
r2=sqrt((d2)^2)
d3=t-p3
r3=sqrt((d3)^2)
gama=gamab+((gamae-gamab)*i)/50
c=gama^r1^2
b1=b0*exp(-c)
d=gama^r2^2
b2=b0*exp(-d)
e=gama^r3^2
b3=b0*exp(-e)
end

 採用された回答

Walter Roberson
Walter Roberson 2015 年 6 月 4 日

0 投票

If you want the value of the variables to change, then you need to assign them new values inside the loop. You make calculations based upon t and p1, p2, p3, but you never change any of those in your loop.

3 件のコメント

Mudasir Ahmed
Mudasir Ahmed 2015 年 6 月 4 日
編集済み: Walter Roberson 2015 年 6 月 4 日
sir, here is the complete code
clc
clear
p1=10;
p2=15;
p3=20;
t=50;
b0=1;
gamab=1; %initial
gamae=1.1; %final
alphab=0.5
alphae=0.3
for i=1:1000
d1=t-p1;
r1=sqrt((d1)^2);
d2=t-p2;
r2=sqrt((d2)^2);
d3=t-p3;
r3=sqrt((d3)^2);
gama=gamab+((gamae-gamab)*i)/50;
alpha=alphab+((alphae-alphab)*i)/50;
c=gama^r1;
b1=b0*exp(-c)
d=gama^r2;
b2=b0*exp(-d)
e=gama^r3;
b3=b0*exp(-e)
A=[b1 b2 b3];
B=[p1 p2 p3];
J=max(A)
[m1 n1]=size(B);
for y=1:n1
if A(1,y)== J;
gbestx=B(1,y)
else
end
end
p1=p1+(b1*(gbestx-p1))+alpha*(rand-0.5)
p2=p2+(b2*(gbestx-p2))+alpha*(rand-0.5)
p3=p3+(b3*(gbestx-p3))+alpha*(rand-0.5)
end
Walter Roberson
Walter Roberson 2015 年 6 月 4 日
sqrt(d^2) is abs(d)
Mudasir Ahmed
Mudasir Ahmed 2015 年 6 月 4 日
sir, what about the whole program response.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by