Minimize problem using PSO

I want to find a minimum value of y(and the corresponding value of L and x), for various values of L and x. How to do this using Particle Swarm Optimization ?

The equation is:

Y= (20+500*L)/x^(1.2+(3*L))

 Accepted Answer

Sam Chak
Sam Chak on 15 Jun 2022
Edited: Sam Chak on 17 Jun 2022
It seems that the function does not have any global minima.
[X, L] = meshgrid(1:3/40:4, 0.1:0.3/40:0.4);
Y = (20 + 500*L)./X.^(1.2 + 3*L);
surf(X, L, Y)
xlabel('x'); ylabel('L'); zlabel('y');
view(45, 30)
% Using PSO to minimize the function with the specified bound constraints
f = @(x) (20 + 500*x(2))./x(1).^(1.2 + 3*x(2));
nvars = 2;
lb = [1 0.1]; % lower bounds
ub = [4 0.4]; % upper bounds
[x, fval] = particleswarm(f, nvars, lb, ub)
Optimization ended: relative change in the objective value over the last OPTIONS.MaxStallIterations iterations is less than OPTIONS.FunctionTolerance.
x = 1×2
4.0000 0.4000
fval = 7.8973

4 Comments

Hello,
Thank you for helping.
I want MATLAB to display the minimum value of y and the corresponding value of x and L in which minimum occur. I don't need any graphical representaion. See the image. Ex:- If C8 is minimum, then MATLAB should display the minimum value of y and corresponding x and L values. This should be implemented stictly using "PARTICLE SWARM OPTIMIZATION". Thanks in advance.
Hi @Reji G,
Don't mention it. It's just a simple help. Please ignore the graphical representation. The Answer is updated with the PSO demonstration of minimizing the given function within the bounds {}, {} as shown in your image. The minimum point is strictly found and displayed by PSO as requested, regardless of the clues from the graphical representation.
Hello Sam,
Its working. Thank you. Need a small clarification.
  1. How to know its displaying minimum value?
  2. What changes need to be done in this program to display maximum value?
  3. How to list all the values?(for all x and L combinations. c1 to c15 in case of my image)
Hi Reji,
1. The final objective function value of swarm particles is displayed as fval which indicates the function value at best solution found so far.
2. This is how to perform the maximization:
% Using PSO to maximize the function with the specified bound constraints
f = @(x) (20 + 500*x(2))./x(1).^(1.2 + 3*x(2));
fmax = @(x) -f(x);
nvars = 2;
lb = [1 0.1]; % lower bounds
ub = [4 0.4]; % upper bounds
[x, fval] = particleswarm(fmax, nvars, lb, ub)
Optimization ended: relative change in the objective value over the last OPTIONS.MaxStallIterations iterations is less than OPTIONS.FunctionTolerance.
x = 1×2
1.0000 0.4000
fval = -220
fmaxValue = -fval % can verify the result with the graphical representation
fmaxValue = 220
3. Although the algorithm performs the search within the bound constraints, it does NOT search the entire space as in to (as in your scenario). It is possible list/store the position and the objective function value of each swarm particle in each iteration through calling the OutputFcn, something like this:
options = optimoptions(@particleswarm, 'OutputFcn', @pswoutfun)
[x, fval] = particleswarm(fmax, nvars, lb, ub, options)
where you have write the code for the pswoutfun.m file. But it can be a little tedious to write the code here. You can find some templates in
edit pswplotbestf
edit psoutputfile
For more info, please check:
If you find this tutorial on using particleswarm() is helpful, consider accepting ✔ and voting 👍 the Answer. Thanks, @Reji G!

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Asked:

on 15 Jun 2022

Commented:

on 17 Jun 2022

Community Treasure Hunt

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

Start Hunting!