custom stopping criteria when using fmincon

7 ビュー (過去 30 日間)
Alessandro Juri
Alessandro Juri 2011 年 4 月 1 日
Does anybody know a way to define "custom stopping criteria" when using fmincon? What I want to do is to stop fmincon when the "optimal" or the funciton value becomes NaN. For example:
Iter F-count f(x)
0 4 0.239457
1 8 0.192672
2 12 0.0374073
3 16 0.0374069
4 20 0.0355964
5 24 0.0349293
6 28 0.0347082
7 32 0.0347077
8 37 0.034304
9 41 0.0341285
10 45 0.0339353
11 49 NaN
12 53 NaN
...
I am interested in a way to stop fmicon at the 10-th iteration.
Many thanks

回答 (1 件)

Sarah Wait Zaranek
Sarah Wait Zaranek 2011 年 4 月 1 日
You can set the stop flag as part of the output function. It is described in the documentation here:
Edited to add an example:
I am stopping using x values but you can get function values from the optimValues structure.
function testerMain
x0 = [10;10;10]; % Starting guess at the solution
A = [-1 -2 -2; ... 1 2 2];
b = [0;72];
options=optimset('Algorithm','interior-point','Display','iter','OutputFcn',@outfun);
[x,fval] = fmincon(@myTestfun,x0,A,b,[],[],[],[],[],options);
disp(x)
end
function f = myTestfun(x)
f = -x(1) * x(2) * x(3);
end
function stop = outfun(x,optimValues,state)
stop = false;
if x(1) > 11
stop = true;
disp('Stopping, x > 11')
end
end

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by