Codes in MATLAB For Particle Swarm Optimization: March 2016
Codes in MATLAB For Particle Swarm Optimization: March 2016
net/publication/296636431
CITATIONS READS
7 148,291
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Mahamad Nabab Alam on 02 March 2016.
Particle swarm optimization (PSO) codes in MATLAB suitable for solving constrained optimization problem
Save the following codes in MATLAB script file (*.m) and save as ofun.m.
----------------------------------------------------------------------------------------------------------------------------------start
function f=ofun(x)
c0=[];
c0(1)=x(1)+x(2)+x(3)-5; % <=0 type constraints
c0(2)=x(1)^2+2*x(2)-x(3); % <=0 type constraints
Save the following main program codes in MATLAB script file (*.m) as run_pso.m (any name can be used) and
run.
----------------------------------------------------------------------------------------------------------------------------------start
tic
clc
clear all
close all
rng default
1
ResearchGate, March 2016
% pso algorithm---------------------------------------------------start
ite=1;
tolerance=1;
while ite<=maxite && tolerance>10^-12
% evaluating fitness
for i=1:n
f(i,1)=ofun(x(i,:));
end
2
ResearchGate, March 2016
pbest(i,:)=x(i,:);
f0(i,1)=f(i,1);
end
end
% calculating tolerance
if ite>100;
tolerance=abs(ffmin(ite-100,run)-fmin0);
end