Failure in initial objective function evaluation. PARTICLESWARM cannot continue.
19 ビュー (過去 30 日間)
古いコメントを表示
Odesanmi Gbenga Abiodun
2019 年 8 月 15 日
回答済み: Walter Roberson
2019 年 8 月 15 日
%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 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Map Display についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!