Can matlab pso toolbox optimize a @(x,y) function?

조회 수: 9 (최근 30일)
Daniel Caliari
Daniel Caliari 2017년 1월 19일
댓글: Daniel Caliari 2017년 1월 20일
Hello everyboody! I'm trying to run the following code but I'm getting error:
f = @(x,y)sin(sqrt(x.^2+y.^2))/sqrt(x.^2+y.^2);
nvar = 2;
[x,fval] = particleswarm(f, nvar);
The error says:
Error using particleswarm>makeState (line 700)
Failure in initial objective function evaluation. PARTICLESWARM cannot continue.
Error in particleswarm>pswcore (line 170)
state = makeState(nvars,lbMatrix,ubMatrix,objFcn,options);
Error in particleswarm (line 152)
[x,fval,exitFlag,output] = pswcore(objFcn,nvars,lbRow,ubRow,output,options);
Error in Untitled (line 5)
[x,fval] = particleswarm(f, nvar);
Caused by:
Not enough input arguments.
Despite It says that there's "Not enough input arguments.", I saw many examples that was only necessary the function and the number of variables as input arguments.

채택된 답변

Matt J
Matt J 2017년 1월 19일
편집: Matt J 2017년 1월 19일
It is your objective function that must take only a single argument,
f = @(p) sin(sqrt(p(1).^2+p(2).^2))/sqrt(p(1).^2+p(2).^2);
  댓글 수: 3
Matt J
Matt J 2017년 1월 19일
Yes, it is equivalent. For plotting purposes, you can obtain a two- argument equivalent as follows,
g=@(x,y) f([x,y]);
Daniel Caliari
Daniel Caliari 2017년 1월 20일
Ok, thanks!

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

추가 답변 (0개)

카테고리

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