Failure in initial objective function evaluation. PARTICLESWARM cannot continue.
19 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Odesanmi Gbenga Abiodun
il 15 Ago 2019
Risposto: Walter Roberson
il 15 Ago 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 Commenti
Risposta accettata
Walter Roberson
il 15 Ago 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Map Display in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!