求助!怎样将PSO算法来优化模糊控制器的量化因子?
PSO代码:
%待优化的目标函数
N=30;%粒子数目:
w=0.9%惯性权重:
c1=2;c2=2%学习因子:
M=1000;%最大迭代次数:
D=3;%问题的维数:
for i=1:N
for j=1:D
x(i,j)=randn;
v(i,j)=randn;
end
end
for i=1:N
p(i)=fitness(x(i,:));
y(i,:)=x(i,:);
end
pg=x(N,:);
for i=1:(N-1)
if fitness(x(i,:))<fitness(pg)
pg=x(i,:);
end
end
for t=1:M
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 fitness(x(i,:))<p(i)
p(i)=fitness(x(i,:));
y(i,:)=x(i,:);
end
if p(i)<fitness(x(i,:))
pg=y(i,:);
end
end
fgbest(t)=fitness(pg);
end
xm=pg';
fv=fitness(pg);
simulink图,子系统图在附件中
如何将此PSO算法编成S函数来优化图中的ke,kec,ku
目标函数中K=ku/(ke*kec)
页:
[1]