该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
function pso_funopt_test1
clear all;
clc;
%给定初始化条件
global c1 c2 w Kmax N
c1=1.4801;
c2=1.4801;
w=0.7153;
Kmax=100;
N=40;
i=0;
while i
for j=1:2
x1(j)=5*rand;
end
x1
if x1(1)^2+x1(2)^2<=25
i=i+1;
x0(i,1)=x1(1);
x0(i,2)=x1(2);
v0(i,1)=rand;
v0(i,2)=rand;
end
end
r=le-5;
df=le-10;
k=0
while df>0.001
k=k+1;
r=r*0.99
[xo f x v]=pso_fun(x0,v0,r);
[fc f]=fpen_in_funl(xo,r);
df=abs(fc-f);
x0=x;
v0=v;
end
k
xo,f
function [xo,f,x,v]=pso_fun(x,v,r)
global c1 c2 w Kmax N
for i=1:N
p(i)=fpen_in_funl(x(i,:),r);
y(i,:)=x(i,:);
end
pg=x(1,:);
for i=2:N
if fpen_in_funl(x(i,:),r)
pg=x(i,:);
end
end
for t=1:Kmax
for i=1:N
v(i,:)=w*v(i,:)+c1*rand*(y(i,:)-x(i,:))+c2*rand*(pg-x(i,:));
x(i,:)=x(i,:)+v(i,:);
if fpen_in_funl(x(i,:),r)
p(i)=fpen_in_funl(x(i,:),r);
y(i,:)=x(i,:);
end
if p(i)
pg=y(i,:);
end
end
end
xo=pg
f=fpen_in_funl(pg,r);
function [fc f]=fpen_in_funl(x,r)
f=4*x(1)-x(2)^2-12;
c=[x(1)^2+x(2)^2-25
-x(1)
-x(2)];
fc=0;
for i=1:3
fc=fc+(c(i)<0)*log(abs(c(i)));
end
fc=f-c*fc;
输入参数的数目不足什么情况呀