看不懂代码的话,运行一下程序就知道了。
%PSO
% options :
% https://ww2.mathworks.cn/help/gads/particleswarm.html
% https://ww2.mathworks.cn/help/gads/particle-swarm-options.html
% https://ww2.mathworks.cn/help/gads/_mw_2d669aeb-37d3-4294-8490-8340f88c256e.html
%参数选择:
rng default
% options=optimoptions('particleswarm','MinNeighborsFraction',0.1,'SelfAdjustmentWeight',1.8, ...
% 'SocialAdjustmentWeight',1.5,'SwarmSize',40,'PlotFcn',@pswplotbestf, ...
% 'InertiaRange',[0.6,0.8]);
options=optimoptions('particleswarm');
options.HybridFcn=@fminunc;
options.PlotFcn=@pswplotbestf;
x0=zeros(10,4); %4个变量
options.InitialSwarmMatrix=x0;
fun=@multirosenbrock; %测试函数
lb=[];%lb=-10*ones(1,4);
ub=[];%ub=10*ones(1,4);
[x,fval,exitFlag,output]=particleswarm(fun,4,lb,ub,options);
formatstring='particleswarm reached the value %f using %d function evalution.
';
fprintf(formatstring,fval,output.funccount);