![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1033715/image.png)
Minimize problem using PSO
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Reji G
el 15 de Jun. de 2022
Comentada: Sam Chak
el 17 de Jun. de 2022
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))
0 comentarios
Respuesta aceptada
Sam Chak
el 15 de Jun. de 2022
Editada: Sam Chak
el 17 de Jun. de 2022
Hi @Reji G
It seems that the function does not have any global minima.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1033715/image.png)
[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)
4 comentarios
Sam Chak
el 17 de Jun. de 2022
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)
fmaxValue = -fval % can verify the result with the graphical representation
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036255/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036260/image.png)
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!
Más respuestas (0)
Ver también
Categorías
Más información sobre Particle Swarm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!