Optimization using Particle Swarm

Auther : Gaul Swapnil Narhari, Developed @ IIT Kharagpur, India. By - TaraNG,emsolutions,India.
1,9K download
Aggiornato 4 mar 2013

Visualizza la licenza

A set of codes used for finding minimum of a problem. By defining appropriate fitness function desired goal can be accomplished say, finding optimum design parameters so that much more beautiful solution can be achieved! :)

About Function:
[El,fval] = pso(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a structurethat has the following inputs,

INPUT fields:
fitnessfcn: <Fitness function>
nvars: <Number of design variables>
lb: <Lower bound on X>
ub: <Upper bound on X>
Genrations: <Number of iterations>
Population: <Number of swarms (particles) used for optimization>
DispWB: <whether to disply waitbar or not '1' to display>
OUTPUT fields:
EL: < The values of optimized parameters>
fval: <Fitness value after optimization>

Example:
First, create a file to evaluate fitness function say, 'simple_fitness.m' as follows:

function y = simple_fitness(x)
y = 100*(x(1)^2 - x(2))^2 + (1 - x(3))^2 + abs(0.4 - x(2));

To minimize the fitness function, user need to pass a function handle to the fitness function as the first argument to the pso function, as well as other parameters of PROBLEM as stated above in pso(PROBLEM),

ObjectiveFunction = @simple_fitness;
nvars = 3; % Number of variables
LB = [0 0 0]; % Lower bound
UB = [3 5 10]; % Upper bound
Popln=200; % Number of particles
Genrtn=50; % Number of %iterations
WByn=1; % '1' = waitbar is ON
[x,fvalue]= pso(ObjectiveFunction, 'NumVar',nvars,'LowerBound',LB,'UpperBound',UB,'Population', ... Popln, 'Genrations', Genrtn, 'IncludeWB', WByn);
disp(x);
disp(fvalue);

After running code will get optimum parameter values more closer to, x(1)=0.6325; x(2)=0.4; x(3)=1;

Cita come

Swapnil Gaul (2025). Optimization using Particle Swarm (https://it.mathworks.com/matlabcentral/fileexchange/40609-optimization-using-particle-swarm), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2010b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
1.1.0.0

Spelling of particle & outcome of code

1.0.0.0