surrogateopt: output function

3 ビュー (過去 30 日間)
Geopaul
Geopaul 2022 年 8 月 9 日
コメント済み: Alan Weiss 2022 年 8 月 11 日
How do we create a customize output function for the 'surrogateopt' that will show the solution at every iteration. I need am example for better understanding. Thank you.

採用された回答

Alan Weiss
Alan Weiss 2022 年 8 月 9 日
Try this.
lb = [-3 -3];
ub = -lb;
opts = optimoptions('surrogateopt','OutputFcn',@listout);
obj = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
[sol,fval] = surrogateopt(obj,lb,ub,opts)
function stop = listout(x,optimValues,state)
stop = false;
switch state
case 'iter'
nval = optimValues.funccount;
y = optimValues.currentX;
fprintf("Number of fevals = %g, x = [%g,%g]\n",nval,y(1),y(2))
end
end
Alan Weiss
MATLAB mathematical toolbox documentation
  3 件のコメント
Geopaul
Geopaul 2022 年 8 月 11 日
How do I save these outputs( e.g nval and y) at every iterations?
Alan Weiss
Alan Weiss 2022 年 8 月 11 日
Alan Weiss
MATLAB mathematical toolbox documentation

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by