Objective and constraint function evolution count in fmincon

How to find number of objective and constraint function , gradient, hessian count in fmincon using interior point method?

Answers (1)

The number of function evaluations and number of iterations is returned in fmincon's 4th output argument. The number of Hessian and gradient evaluations should equal the number of iterations.

4 Comments

But funcCount gives the number of objective function evolution only.If there are many constraints, the F-count can be significantly less than the total number of function evaluations. see http://in.mathworks.com/help/optim/ug/iterations-and-function-counts.html
I see. Well, you can always use persistent variables to count the calls to the constraints (or whatever function). The following, for example, will allow your nonlcon function to return the number of calls when only 1 output argument is requested, but operate normally the rest of the time.
function varargout=nonlcon(...)
persistent count
if isempty(count), count=0; end
count=count+1;
if nargin==1
varargout={count}; return
else
ceq=...
c=...
varargout={c,ceq};
end
end
Thank you sir for your kind help.
Sir I have one problem min 4(x(1)^2+x(2)^2) subject to x(1)^2+x(2)^2-225<=0 0<=x(1)<=5 0<=x(2)<=3.
For this problem how to write nonlcon with constraints evalutions count?
function varargout=nonlcon(x)
persistent count
if isempty(count), count=0; end
count=count+1;
if nargin==1
varargout={count}; return
else
ceq=[];
c=norm(x)^2-225;
varargout={c,ceq};
end
end

Sign in to comment.

Commented:

on 18 Sep 2017

Community Treasure Hunt

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

Start Hunting!