fmincon/multistart won't debug/display errors in OutputFcn

4 views (last 30 days)
If "x=b" is uncommented, the code still runs and does not break on error or display the line number.
This means debugging a more complex fcontrol function is quite difficult. Is there a way to force pause on errors in multistart?
% Fmincon problem
rng default % For reproducibility
opts = optimoptions(@fmincon,'OutputFcn', @fcontrol);
problem = createOptimProblem( 'fmincon','objective', ...
@(x) x.^2 + 4*sin(5*x),'x0',3,'lb',-5,'ub',5,'options',opts);
% Run Problem
[ x, f ] = run(MultiStart( 'Display','iter'),problem,5);
function stop = fcontrol(x, optimValues, state)
stop = false; % default continue
% x=b;
end

Accepted Answer

Joel Lynch
Joel Lynch on 31 Mar 2022
I figured out the issue, 'OutputFcn' must be added in Multistart, not fmincon. This also means using different syntax for the call:
% Fmincon problem
rng default % For reproducibility
opts = optimoptions(@fmincon);
problem = createOptimProblem( 'fmincon','objective', ...
@(x) x.^2 + 4*sin(5*x),'x0',3,'lb',-5,'ub',5,'options',opts);
% Run Problem
ms = MultiStart( 'Display','iter','OutputFcn', @fcontrol);
[ x, f ] = run(ms,problem,5);
function stop = fcontrol(optimValues, state)
x = optimValues.localsolution.X;
stop = false; % default continue
% x=b;
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!