File Exchange

image thumbnail

Particle Swarm Optimization

version (8.01 KB) by Yan Ou
[xMin,yMin] = pso(fun,np,lb,ub);


Updated 24 Dec 2013

View Version History

View License

fun: function handle (y = fun(x), x is column vector)
np: number of particles
lb, ub: lb<x<ub
xMin: yMin = fun(xMin)
yMin: minimum value of the cost function fun
pso finds the global minimum for a constraint function (convex or non-con) with multiple variables.

Cite As

Yan Ou (2021). Particle Swarm Optimization (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

Haitham Hassan

How can i Multiobjective function each with different constraints ?

Maria Esmeral

Good Morning.

I want to know if for using this function should I have instaled the optimization toolbox.

Thank you

Quan Wang

Very elegant implementation.

Yan Ou

It dose constrain stuff. lb, ub: lb<x<ub

li jian

Hi,thanks for your contribution. The pso algorithm does not deal with constrained problems which makes it powerless to deal with practical problems.


oops...I may control the different LB & UB at the inside of my own test function. Sorry to make you confused. Thanks!


How many different lb & ub can I set for your PSO? If it is 1 set, so far, then I wonder if you hava a plan to update your PSO for that. Thanks!

Yan Ou

Hello Sanjaya:

The pso algorithm I posted does not deal with the integer programming issue as you mention.
But there should be two way to solve your problem.
1, Your problem have 5 variable restrict in integer domain. You can try all the combination of the 5 variable and use pso to solve the continuous optimization problem for the rest 9 variables. Then choose the smallest one from the 5 variables.
2, Try to relax your integer programming issue to a continuous programming issue.


Dear sir,
I have a problem with 16 variables, out of which 9 variables are in decimals with range 0 to 1 and the rest are integers with range 1 to 4. Can I use your codings of pso?

Ahmed ali


Yan Ou

Please let me know if you guys can run the function or not

Yan Ou

Please let me know if you guys can run the function or not

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!