View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

2.8 | 4 ratings Rate this file 14 Downloads (last 30 days) File Size: 2.67 KB File ID: #29519 Version: 1.0
image thumbnail



Micael Couceiro (view profile)


Easy-to-use MatLab function for PSO.

| Watch this File

File Information

Easy-to-use MatLab function for PSO (Particle Swarm Optimization). Limited to optimization problems of nine variables but can easily be extended many variables.

xbest = pso(func)
xbest - solution of the optimization problem. The number of columns depends on the input func. size(func,2)=number of xi variables
func - string containing a mathematic expression. Variables are defined as xi. For instance, func='2*x1+3*x2' means that it is an optimization problem of two variables.

[xbest,fit] = pso(func)
fit - returns the optimized value of func using the xbest solution.

[xbest,fit] = pso(func,xmin)
xmin - minimum value of xi. size(xmin,2)=number of xi variables. Default -100.

[xbest,fit] = pso(func,xmin,xmax)
xmax - maximum value of xi. size(xmax,2)=number of xi variables. Default 100.

[xbest,fit] = pso(func,xmin,xmax,type)
type - minimization 'min' or maximization 'max' of the problem. Default 'min'.

[xbest,fit] = pso(func,xmin,xmax,type,population)
population - number of the swarm population. Default 50.

[xbest,fit] = pso(func,xmin,xmax,type,population,iterations)
iterations - number of iterations. Default 500.

Example: xbest = pso('10+5*x1^2-0.8*x2',[-10 -20],[20 40],'min')

Micael S. Couceiro

Original algorithm developed by:
Kennedy, J. and Eberhart, R. C. (1995).
"Particle swarm optimization".
Proceedings of the IEEE 1995 International Conference on Neural Networks, pp. 1942-1948.

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
30 Apr 2015 shijith P T

??? Input argument "func" is undefined.

Error in ==> pso at 47

??? Input argument "func" is undefined.

24 Mar 2015 Joy Goswami

16 Dec 2013 Neeraj Bhanot


Swarming...Subscripted assignment dimension mismatch.

Error in psoboundspenalize (line 32)
state.ConstrViolations(i,:) = [c,ceq] ;

Error in pso (line 407)
state = boundcheckfcn(state,Aineq,bineq,Aeq,beq,LB,UB,nonlcon,...

Please look into above problem.


Comment only
26 Mar 2012 Vinod

Vinod (view profile)

14 Dec 2011 huda nawaf

please, i want to include pso in matlab, how get it

Contact us