File Exchange

image thumbnail

Particle Swarm Optimization Simulation

version 1.1 (12.7 KB) by Sam Elshamy
an animated simulation of particles searching for the minima of a simple function


Updated 30 Nov 2014

View License

An animated simulation of Particles in 2D searching for a global minima of a simple function using Particle Swarm Optimization algorithm

Cite As

Sam Elshamy (2020). Particle Swarm Optimization Simulation (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (51)

Ali Ali

Dear Mr. Wesam,

Hoping this finds you well,

I appreciate if you can tell me why you are using the formula below for updating your algorithm:
swarm(i, 1, 1) = swarm(i, 1, 1) + swarm(i, 2, 1)/1.3;
specifically (/1.3).

Nick Zheng

Perfect tools, easy to use, thanks a lot!


Please help me with matlab programme or code for (1) generation of data on PSO; (2) training of the data to achieve stability of a microgrid.
Thank you


i need the code for optimal location of DG using PSO......... help me pleas on this
mail id:

abbas issa

Hello, I'm looking for simple matlab code for PSO that can optimize the base station placement in mobile communication based particle swarm optimization

Obed Kondo

Hello Sir,
Please, can you help me with a matlab programme on finding optimal location of wells (drilling petroleum wells) using PSO?
My objective function is maximization of Net Present Value in drilling oil wells

Please, kindly help me

Thank you

i need the code for placement and sizing of DG using PSO can u help me pleas.

i need the code for placement and sizing of DG can u help me pleas

can u help in optimizing...minimize
C=0.15247* P^2+ 38.5397*P+756.79800

Hello sir,
Can you help me to find the optimal placement and capacity of Distributed Generation by using PSO?
please help me


First, thanks for sharing this code.
I want to do an optimal sizing & placement of Distributed Generation on networks.
could you tell me how to write the objective function in matlab ?
Thank you



Do u know how Mr. Arif Rizvi ?

Arif Rizvi

Very nice code . I am new learner of matlab ,I am working on Placement of Distributed Generation on Smart Grid usinf PSO , Can any one give me this code explanation.I have a problem at line no 35. Why here use 1000 ?
swarm(:, 4, 1) = 1000;



I have a question
this code is too simple for my criteria.
is it possible to modify this code for multi-objective optimization.



awesome code.
very simple , easy to understand and very close to the theoretical model of PSO.
as a starter in PSO, I am lucky to run through this code.

i need to ask you if i have 7 variables how can i put them in the program

anum eman

easy to learn PSO realy


good work

nice work boy but can u please tell me how to find global maxima for PSO

Very good! It is easy to learn PSO concept.
Thank you very much.

This is very useful in understanding PSO. Thank you for the share.

good is easy to understand and we are able to observe the movement of particles..



Good one!!, It is easy and simple to understand.

hu jia

Good code.thank you!!

Thank you !

Lyeyee Wong

May I know what is the function of 'Live_fn.m'?


A very clear example...
Nice work.....

Thanks a lot dear for your sharing us your code
with the best regard


C Lunga

Igor S

Learned PSO on simple example :) Thanx!

Royalos Yin

It is a good tutorial tool.
Thank you.

jonghoon han


Sarayut Nonsiri

Thank you very much for your code.

rahim mozafari

thank you for sharing your code

mo ar

craig hudson

good code!

still not sure about what implications the [temp, gbest] line has in relation to the updated velocity but the rest I have picked up with relative ease!

Amr Yassin

Thank you Wesam for sharing your PSO code it was realy useuful and easy to use

Neil King

Nice, really nice. Simple but effective demonstration of how the algorithm works.

wang li

I love you!you are best!Thank you for sharing your code!

li chong

I expect one day i can write matlab program like you,you set me a example

Sushrut Pavanaskar

Perfect Graphical Simulation is seen !!

Rafael Gomez

Nice example!!!

xuemei zhu




Now available in Toolbox format.

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