Hello everyone and welcome. I’m going to show you a simple but effective Matlab code of Particle Swarm Optimization (PSO) and test the performance of PSO in solving both maximization and minimization problems. You can copy the Matlab code of PSO and customize it to solve your problems.
For more videos like this, check my YouTube channel here.
Objective function (objective_function.m)
function Z = objective_function(O)
x = O(1);
y = O(2);
Z = 3*(1-x)^2*exp(-x^2 - (y+1)^2) - 10*(x/5 - x^3 - y^5)*exp(-x^2 - y^2) -1/3*exp(-(x+1)^2 - y^2);
Main_PSO (Main_PSO.m)
clc
clear all
close all
%% Problem
nVar = 2; % number of variables
VarMin = -3; % lower bound of variable
VarMax = 3; % upper bound of varible
%% PSO parameters
MaxIter =150; % max number of iterations
nPop = 50; % population size
w = 1; % inertia
d = 0.99; % damping ratio of the inertia
c1 = 2; % acceleration 1
c2 = 2; % acceleration 2
%% Initial
x0.position = [];
x0.velocity = [];
x0.fitness = [];
x0.best.position =[];
x0.best.fitness =[];
x = repmat(x0,nPop,1); % Make a population
global_best.fitness = inf;
% Generate initial population
for i = 1: nPop
x(i).position = unifrnd(VarMin,VarMax,[1 nVar]); % generate random solutions
x(i).velocity = zeros([1 nVar]); % initial velocity
.
.
.
Sorry! This is only a half of the code.
Notice: It’s possible to watch the video and re-type the Matlab code yourself – that would take you from 1 to 3 hours; or with just €1.99 (the cost of a cup of coffee), you can download/copy the whole Matlab code within 2 minutes. It’s your choice to make.
Original price is €4.99 but today it’s only €1.99 (save €3 today – available for a limited time only)
Download the whole Matlab code here (Membership Code ID: 001)
No need to build the Matlab code from scratch because it’s very time-consuming. My idol, Jim Rohn, once said: “Time is more value than money. You can get more money, but you cannot get more time”. If you think this code can be used in your research/teaching work, you should download it and then customize/modify/apply it to your work, without any obligation of citing the original source if you don’t want. However, redistribution (i.e., downloading the code/script here and then making it available on another site on the Internet) is strictly prohibited.
If you have any question or problem, please contact Dr. Panda by email: learnwithpanda2018@gmail.com
Thank you very much and good luck with your research!
I am your subscriber.
I need the PSO Algorithm
Hi, use your email to unlock the code and copy it. Thanks
I need the PSO code
Hi, use your email to unlock the content to see and download the code. Thanks
I need the pso code
Use your email to unlock the code and download it. Good luck!
Thanks DR Panda
Hello, your website is excellent.
Actually, I am trying to implement your PSO code to resolve an aggregate production planning problem, but I have some difficulty. In that sense, could you help me with two things that I need to know?: how I can run your code for 12 months (planning periods) and how to implement constraints as: -Inventory(current month-1)+Inventory(current month).
Best wishes.
Hi, thanks for your visit. Your questions are about the problem formulation. You should do it yourself and/or with the help of your supervisors. I don’t have background to understand your problem.
hi, I want to implement PSO code to my EDM problem.could you please help me how to write PSO code for my EDM
Thanks for your suggestions!
hi, I want to implement PSO code to multilevel inverters, but facing very difficulty in finding switching pulses…could you please help me how to write PSO code for multilevel inverters in power electronics.
Hi, I don’t have background to understand your problem. All I can do is to advise you to study to understand my PSO code and then customize it to solve your problems.
hi, could you please solve PSO in multilevel inverters.
Hi, from optimization point of view, solving principle is the same. However, solving a new problems, some customization is required. Sorry, I don’t have background to understand your problem.
I need MATLAB Code of Particle Swarm Optimization
Thankyou
Hi, the matlab code of PSO is on my blog. Go there and download yourself.
i am unable to downloads
Yes, but you can copy and paste.
HI
if you can help me for building PSO code for the optimization problem
contact me on omarali.shahri@gmail.com
HI
help me for building PSO code for the optimization problem
contact me on omarali.shahri@gmail.com
Hi, send me an email.
What is the objective_function in the code
The objective function in the code is Z, one is min and another one is max.
hi
Hello, nice to meet you!
Hi, I need this code, thank you very. Email: chench@88.com
Hi, you can copy it here. Please check the link in this post.
Hello I need PSO code. Please send me
aliyecalis02@hotmail.com
You can come and download it yourself.
Hello I need PSO code. Please send me
syahrulaiman66@gmail.com
Please come and download yourself
Can I have the code. My email ainanabilah0507@gmail.com
Thank you Dr. Panda for this insightul contribution. I need the matlab code for pso. Thank you in anticipation for response
Hello sir, i am your subscriber
I need PSO code, pls help me
You can download it here
Merci Dr Panda pour cette contribution perspicace.
J’ai besoin de l’algorithme PSO
Merci beaucoup!
Hello.. Dr. Panda
I am struggling and need help to find matlab code/algorithm related to sizing PV water pumping system..
please do contact me..
eng.jabra888@gmail.com
Hello. I don’t have GA code for your specific problems. Only thing I can do now is to suggest you to customize my GA code to solve the optimization problems in your fields. Many thanks!
please send me the pso matlab code
Can you download yourself?
I cannot download the link, everytime they just ask to login and any code appears
Please login and get access to the full code. If any problem, please send me an email.
Hi, I want to implement PSO code to my USM problem. could you please help me how to write the PSO code for my USM
mail id is bikash.me.jgec@gmail.com
Hello, I don’t have the background to understand your problems