matlab 运行程序后显示Undefined function or variable 'i1'.
c1=1.49445;c2=1.49445;maxgen=200;sizepop=100;psize=3;Vmax=5;Vmin=-5;lb=ones(psize,1)*...
c1=1.49445;c2=1.49445;
maxgen=200;
sizepop=100;
psize = 3;
Vmax=5;Vmin=-5;
lb = ones(psize,1)*(-10);
ub = ones(psize,1)*10;
bound = [lb,ub];
wstart = 0.9;wend = 0.4;
w = wstart-(wstart-wend)*((i1/maxgen)^2);
pop=zeros(sizepop,psize);
V=zeros(sizepop,psize);
fitness=zeros(1,sizepop);
for i1=1:sizepop
pop(i1,:) = (bound(:,2)-bound(:,1))'.*rand(1,psize)+bound(:,1)';
V(i1,:)=rands(1,psize)*(Vmax-Vmin)+Vmin;
fitness(i1)=fun(pop(i1,:));
end
V(i2,:)=w*V(i2,:)+c1*rand*(gbest(i2,:) - pop(i2,:))+c2*rand*(zbest - pop(i2,:));
tempV = V(i2,:);
tempV(tempV > Vmax) = Vmax;
tempV(tempV < Vmin) = Vmin;
V(i2,:) = tempV;
pop(i2,:)=pop(i2,:)+V(i2,:);
for i3 = 1:psize
if pop(i2,i3) >= bound(i3,2)
pop(i2,i3) = bound(i3,2);
end
if pop(i2,i3) <= bound(i3,1)
pop(i2,i3) = bound(i3,1);
end
end
哪一步出错了呢 求大神指教
函数是
f = x1**2+x2**2-x3**2+3*sin(x1*x2*x3)
求解:在坐标范围x~(-10,10) z~(-10,10) y~(-10,10)的范围中的最大值,以及最大值所对应的x1,x2,x3 展开
maxgen=200;
sizepop=100;
psize = 3;
Vmax=5;Vmin=-5;
lb = ones(psize,1)*(-10);
ub = ones(psize,1)*10;
bound = [lb,ub];
wstart = 0.9;wend = 0.4;
w = wstart-(wstart-wend)*((i1/maxgen)^2);
pop=zeros(sizepop,psize);
V=zeros(sizepop,psize);
fitness=zeros(1,sizepop);
for i1=1:sizepop
pop(i1,:) = (bound(:,2)-bound(:,1))'.*rand(1,psize)+bound(:,1)';
V(i1,:)=rands(1,psize)*(Vmax-Vmin)+Vmin;
fitness(i1)=fun(pop(i1,:));
end
V(i2,:)=w*V(i2,:)+c1*rand*(gbest(i2,:) - pop(i2,:))+c2*rand*(zbest - pop(i2,:));
tempV = V(i2,:);
tempV(tempV > Vmax) = Vmax;
tempV(tempV < Vmin) = Vmin;
V(i2,:) = tempV;
pop(i2,:)=pop(i2,:)+V(i2,:);
for i3 = 1:psize
if pop(i2,i3) >= bound(i3,2)
pop(i2,i3) = bound(i3,2);
end
if pop(i2,i3) <= bound(i3,1)
pop(i2,i3) = bound(i3,1);
end
end
哪一步出错了呢 求大神指教
函数是
f = x1**2+x2**2-x3**2+3*sin(x1*x2*x3)
求解:在坐标范围x~(-10,10) z~(-10,10) y~(-10,10)的范围中的最大值,以及最大值所对应的x1,x2,x3 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询