Failure in initial objective function evaluation. PARTICLESWARM cannot continue.
4 views (last 30 days)
Show older comments
Odesanmi Gbenga Abiodun
on 15 Aug 2019
Answered: Walter Roberson
on 15 Aug 2019
%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.
0 Comments
Accepted Answer
Walter Roberson
on 15 Aug 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Map Display in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!