代写代考 function Y=test1(in)

function Y=test1(in)

Copyright By PowCoder代写 加微信 powcoder

%%PSO Parameters
N=50;%粒子的个数为50
ger=100;%迭代次数为100
W=0.8;% 惯性权重
C1=0.5;% 自我学习因子
C2=1; % 群体学习因子
% N=round(in(1));%粒子的个数为60
% ger=round(in(2));%迭代次数为100
% W=in(3);% 惯性权重
% C1=in(4);% 自我学习因子
% C2=in(5); % 群体学习因子
lb=[-0.952,4.2e-5,7.4e-5,-1.98e-4,1.0e-7,0,0,14,0.0001,0.016];
ub=[-0.944,4.4e-5,7.8e-5,-1.88e-4,1.0e-5,5,5,23,0.0008,0.5];
% lb=[-1.19969,0.001,3.6e-5,-2.6e-4,1.0e-7,0,0,10,1.00e-4,0.0136];
% ub=[0.8532,0.005,9.80e-5,-9.54e-5,1.0e-5,5,5,24,8.00e-4,0.5];

dim=length(ub);%空间维数为10
Vmax=(ub-lb)/10;
Vmin=-Vmax;
BestPosition=repmat(zeros(size(ub)),Maxit,1);
BestCost=zeros(Maxit,1);

for it=1:Maxit

empty_individual.Position=[];
empty_individual.Cost=[];
pop=repmat(empty_individual,N,1);% 将保存种群信息的结构体扩展为结构体矩阵,列数等于种群大小
GlobalBest.Cost=inf;% 最优值初始化

empty_particle.Position=[]; % 种群初始化
empty_particle.Cost=[]; % 种群目标初始化
empty_particle.Velocity=[]; % 种群速度初始化
empty_particle.Best.Position=[]; % 种群最优位置初始化
empty_particle.Best.Cost=[];% 初始化所有的参数

particle(i).Position=lb+rand(1,dim).*(ub-lb);
%particle(i).Velocity=zeros(1,dim);
particle(i).Velocity=rand(1,dim).*(ub-lb)/25;
particle(i).Cost=f(particle(i).Position);
%个体最佳适应度更新
particle(i).Best.Cost=particle(i).Cost;
particle(i).Best.Position=particle(i).Position;
%种群最佳适应度更新
if particle(i).Best.Costparticle(i).Best.Cost
GlobalBest.Cost=particle(i).Best.Cost;
GlobalBest.Position=particle(i).Best.Position;
particle(i).Velocity=W* particle(i).Velocity…
+ C1*rand(1,dim).*(particle(i).Best.Position-particle(i).Position)…
+ C2*rand(1,dim).*(GlobalBest.Position-particle(i).Position);

particle(i).Velocity=min(particle(i).Velocity,Vmax);
particle(i).Velocity=max(particle(i).Velocity,Vmin);

particle(i).Position=particle(i).Position+particle(i).Velocity;
% Velocity Mirror Effect
IsOutside=(particle(i).Positionub);
particle(i).Velocity(IsOutside)=-particle(i).Velocity(IsOutside);
for j=1:dim
if particle(i).Position(j)>=ub(j)
particle(i).Position(j)=ub(j);
if particle(i).Position(j)<=lb(j) particle(i).Position(j)=lb(j); iter=iter+1; BestPosition(it,:)=GlobalBest.Position; Y=sum((F(BestPosition(it,:))).^2); 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com