Particle Swarm Optimization Toolbox for Non-linear Equation System Solving

7 views (last 30 days)
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:
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.
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
fun = function_handle with value:
@(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)
Error using particleswarm>makeState
Objective function must return scalar values.

Error in particleswarm>pswcore (line 177)
state = makeState(nvars,lbMatrix,ubMatrix,objFcn,options);

Error in particleswarm (line 154)
[x,fval,exitFlag,output] = pswcore(objFcn,nvars,lbRow,ubRow,output,options);
In my code above, I used x as λ, as μ, as ν.
Initial conditions(upper and lower limits for ) are between: .
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 Comment
Torsten
Torsten on 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.

Sign in to comment.

Answers (1)

Bala Tripura Bodapati
Bala Tripura Bodapati on 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.
Refer the Particle Swarm Optimization documentation for more information.

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!