Please Help Optimization using PSO

4 次查看(过去 30 天)
I have optimization problem using PSO "I have to write the code without using toolbox" .. I wrote the mainPSO code and the objective function but I don't know how to define the equality and inequality constraints
x1+x2+x3+x4+x5 =1000;
x1^2-4x2+5x3^3+x4^4-3.5x5^2 = 300
How to define these two constraints ???

采纳的回答

Walter Roberson
Walter Roberson 2021-1-5
%{
x1+x2+x3+x4+x5 =1000;
x1^2-4x2+5x3^3+x4^4-3.5x5^2 = 300
%}
Notice that x2 is the only variable that appears linearly in the second equation. So rewrite the first equation as
%{
x2 = 1000 - x1 - x3 - x4 - x5
%}
Now substitute that into the second equation
%{
x1^2-4*(1000 - x1 - x3 - x4 - x5)+5x3^3+x4^4-3.5x5^2 = 300
%}
This is a quadratic in x1 (or x5), so solve it for x1
syms x1 x2 x3 x4 x5
eqn = x1^2-4*(1000 - x1 - x3 - x4 - x5)+5*x3^3+x4^4-3.5*x5^2 == 300
eqn = 
X1 = solve(eqn, x1)
X1 = 
Now you run two different PSO runs, one substituting 1000 - x1 - x3 - x4 - x5 for x2 and the first of those X1 values for x1; the other run substituting 1000 - x1 - x3 - x4 - x5 for x2 and the second of those X1 values for x1. These runs will not require equality or inequality constraints (unless there are more constraints you did not tell us about.)
The runs you would do would be over 3 variables only, x3, x4, x5, with you having substituted for x1 and x2 in your objective function.

更多回答(1 个)

Ameer Hamza
Ameer Hamza 2021-1-5

类别

Help CenterFile Exchange 中查找有关 Particle Swarm 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by