Failure in initial objective function evaluation. PARTICLESWARM cannot continue.

조회 수: 20 (최근 30일)
%Please help me with this problem, here is my code
fun = @(X1Fit,X2Fit)sum(abs(YFit-42.2573 + 0.2109.*X1Fit(1) - 0.3602.*X2Fit(2).^2));
rng default % For reproducibility
nvars = 2;
lb=[25 -3.38];% %lower bounds of variables
ub=[85 5.38];%%upper bounds of variables
options = optimoptions('particleswarm','SwarmSize',100,'HybridFcn',@fmincon);
[x,fval,exitflag,output] = particleswarm(fun,nvars,lb,ub,options)
fsurf(@(X1Fit,X2Fit)(YFit - 42.2573 + 0.2109.*X1Fit - (0.3602)*X2Fit.^2))
%Error
Not enough input arguments.
Error in tut1>@(X1Fit,X2Fit)sum(abs(YFit-42.2573+0.2109.*X1Fit(1)-0.3602.*X2Fit(2).^2))
Error in particleswarm>makeState (line 694)
firstFval = objFcn(state.Positions(1,:));
Error in particleswarm>pswcore (line 169)
state = makeState(nvars,lbMatrix,ubMatrix,objFcn,options);
Error in particleswarm (line 151)
[x,fval,exitFlag,output] = pswcore(objFcn,nvars,lbRow,ubRow,output,options);
Error in tut1 (line 23)
[x,fval,exitflag,output] = particleswarm(fun,nvars,lb,ub,options)
Caused by:
Failure in initial objective function evaluation. PARTICLESWARM cannot continue.

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 15일
particleswarm never passes two separate parameters to an objective function. You need to pack all of the parameters together into a single vector. You can separate them into separate variables inside the function.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by