fmincon get x/fval if output function stops execution

1 view (last 30 days)
Hello all,
I am performing a constrained nonlinear optimization using fmincon, which for convergence reasons I wish to have a time limit imposed. I defined an output function (below) such that the output argument 'stop' is set to true when the time limit is reached, i.e.,
function stop = stopfcn(Params, optimValues, ~)
stop = false;
if etime(clock, StartTime) > MaxTime,
warning('Elapsed time exceeds %d seconds', MaxTime);
stop = true;
end
end
Variables StartTime and MaxTime are passed into the calling function.
This output function works correctly-- my optimization terminates after MaxTime seconds if convergence does not occur. The problem is that the values of X and fval that are returned by fmincon when this happens are not the values at the time of termination, but are earlier values (verified by displaying the iterations of the solver). Basically, I'd like to output the values of X and fval just before the output function stops the optimization. Is there a way to do this?
Thanks, Matt
  1 Comment
Eric
Eric on 17 Mar 2012
Hi Matt, I'm trying to due something similar with fzero, but am having trouble figuring out how to pass the starting time to the output function. If you could tell me how you did this with fmincon, it would be greatly appreciated.
Thanks,
Eric

Sign in to comment.

Answers (1)

Andrew Newell
Andrew Newell on 31 Dec 2011
I'm not sure how fmincon decides what values to return, but check out an example output function that returns the entire history of X and fval. You could adapt it to your purposes.

Community Treasure Hunt

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

Start Hunting!