Particle Swarm Optimization Toolbox for Non-linear Equation System Solving

조회 수: 7 (최근 30일)
ercan duzgun
ercan duzgun 2022년 11월 20일
답변: Bala Tripura Bodapati 2022년 11월 23일
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
Torsten
Torsten 2022년 11월 20일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Bala Tripura Bodapati
Bala Tripura Bodapati 2022년 11월 23일
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.

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by