How to solve the following error : "Maximum number of function evaluations exceeded; increase OPTIONS.MaxFunEvals".

I need to maximize the objective function y = exp(x) using 'fmincon' and a -ve sign in the objective function.I have used upper & lower bounds of x as 300 and 400. When I run with y=exp(x), I get the error: Maximum number of function evaluations exceeded;
increase OPTIONS.MaxFunEvals.
When I run for y = exp(-x), I get the error:
Optimization terminated: first-order optimality measure less than options.TolFun and maximum constraint violation is less
than options.TolCon.
Active inequalities (to within options.TolCon = 1e-006):
lower upper ineqlin ineqnonlin
1
The code is :
function xout = s1
%---------------------------optimization-------------------
x0 = [300]; % Just some Initial Condition
ub = [400]; % Upper bounds
lb = [300]; % Lower bounds
F = @(x) obj(x);
xout = fmincon(F,x0,[],[],[],[],lb,ub); %optimization operator
function obj = obj(x)
y = exp(x)
obj = -y
end
end
Please help me as to how I can remove this error. Thanks.

 Accepted Answer

options = struct('MaxFunEvals', 2000);
xout = fmincon(F, x0, [], [], [], [], lb, ub, options);

4 Comments

Thanks Mr.Roberson.But I just tried that and got the following error:
??? Error using ==> optimfcnchk at 287 NONLCON must be a function.
Error in ==> fmincon at 302 [confcn, msg] = optimfcnchk(NONLCON,'fmincon',length(varargin),funValCheck,gradconstflag,false,1);
Error in ==> site at 12 xout = fmincon(F, x0, [], [], [], [], lb, ub, options);
xout = fmincon(F, x0, [], [], [], [], lb, ub, [], options);
OR
xout = fminbnd(F, lb, ub, options);
Thanks Mr.Roberson. I tried and it shows following error:
Maximum number of iterations exceeded; increase OPTIONS.MaxIter.
I have added "options = struct('MaxIter',2000);"
Still it shows the same...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!