Particle Swarm Optimization Toolbox for Non-linear Equation System Solving
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear Matlab users,
I would like to use Particle Swarm Optimization Toolbox for Non-linear Equation System Solving. I got some errors. What I am doing wrong here?
The 3 non-linear equations are as follows:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200698/image.png)
Therefore,
,
,
will be minimized. If we describe
, we can also write
will be minimized. Therefore, In Particle Swarm Optimization (PSO), I thought to minimize the epsilon ϵ to be minimize near to zero. Then the 3 non-linear equation would be solved numerically.
are coefficients.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200703/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200708/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200713/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200718/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200723/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200728/image.png)
My PSO Matlab code is as follows:
G1=2543309.32;H1=2211400.81;I1=3699427.32;
G2=446541.81;H2=1040240.96;I2=1167240.32;
G3=-5409318.49;H3=-4301537.69;I3=-5103577.6;
G4=953461.98;H4=194392.77;I4=675534.86;
G5=1561353.72;H5=1174001.77;I5=695136.68;
fun = @(x)((G1*x.^2+G2).*x(1).^2+(G3*x).*x(1)+(G4*x.^2+G5)).^2 + ((H1*x(1).^2+H2).*x(2).^2+(H3*x(1)).*x(2)+(H4*x(1).^2+H5)).^2+((I1*x.^2+I4).*x(2).^2+(I3*x).*x(2)+(I2*x.^2+I5)).^2
lb = [0,0,0];
ub = [6,6,6];
options = optimoptions('particleswarm','SwarmSize',100,'HybridFcn',@fmincon);
rng default
nvars = 3;
x = particleswarm(fun,nvars,lb,ub,options)
In my code above, I used x as λ,
as μ,
as ν.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200733/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200738/image.png)
Initial conditions(upper and lower limits for
) are between:
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200743/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1200748/image.png)
I used the PSO example here on MATLAB website and edited the codes.
Could you help me with the code? Where is my wrong here? Thank you in advance.
1 Commento
Torsten
il 20 Nov 2022
Your function "fun" returns a 3x1 vector, not a scalar value as required.
The reason is that there are some operations with the complete vector x, not only with its components.
Risposte (1)
Bala Tripura Bodapati
il 23 Nov 2022
Hi Ercan
It is my understanding that the following error is encountered when you are trying to solve the system of non-linear equations using Particle Swarm Optimization:
'Objective function must return scalar value'
As per the documentation, the objective function should return a scalar value. In the following line of code specified, the entire vector 'x' is used in some parts of the equation, which results in the function returning a vector of 3x1 instead of a scalar value:
fun = @(x)((G1*x.^2+G2).*x(1).^2+(G3*x).*x(1)+(G4*x.^2+G5)).^2 + ((H1*x(1).^2+H2).*x(2).^2+(H3*x(1)).*x(2)+(H4*x(1).^2+H5)).^2+((I1*x.^2+I4).*x(2).^2+(I3*x).*x(2)+(I2*x.^2+I5)).^2
A possible workaround is to eliminate the use of entire vector in the objective function or assign a scalar value to 'lambda' values in the system of linear equations.
0 Commenti
Vedere anche
Categorie
Scopri di più su Particle Swarm in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!