Why option for fmincon is not working ?

5 views (last 30 days)
HN
HN on 6 Nov 2020
Commented: HN on 6 Nov 2020
I defined the option as follows and it is not working. I tried many other options as well. Could anyone gives some idea ? Thanks
options = optimoptions('fmincon','Algorithm','interior-point','Display','iter-detailed',...
'MaxFunctionEvaluation',100000,'MaxIterations',2000,'FunctionTolerance',1e-10);
A=[]; b =[]; Aeq =[]; beq =[]; %x is vector
[V,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x,A,b,Aeq,beq,LB,UB,options)
  2 Comments
Steven Lord
Steven Lord on 6 Nov 2020
What does "not working" mean?
  • Did the code throw an error? If so what is the full and exact text of the error message (all the text displayed in red)? If you also received warning messages show all the warning text displayed in orange as well.
  • Did the code give you a different answer than you expected? If so show the answer you received and the answer you expected and explain why you believe the answer you expected is the correct answer.
  • Did MATLAB crash? If so please find the crash log file and send it to Technical Support for investigation.
  • Did something else unexpected happen? If so, what happened?
HN
HN on 6 Nov 2020
Sorry for misleading Steven Lord . Here is the error message I got. The problem is related to my definition not with Matlab. Thanks
Error using optimfcnchk (line 99)
NONLCON must be a function.
Error in fmincon (line 437)
confcn = optimfcnchk(NONLCON,'fmincon',length(varargin),funValCheck,flags.gradconst,false,true);
Error in Main_Opt (line 30)
[V,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x,[],[],[],[],LB,UB,options)

Sign in to comment.

Accepted Answer

HN
HN on 6 Nov 2020
I got it why. The nonlcon argument has been skipped.
[V,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x,[],[],[],[],LB,UB, [],options);
Thanks

More Answers (1)

Steven Lord
Steven Lord on 6 Nov 2020
If you want to provide an options structure to fmincon you must provide all the input arguments that precede it. While you've passed in fun, x, A, b, Aeq, beq (these four as empty matrices), LB, and UB you haven't passed in nonlcon which is the nonlinear constraint function. The documentation page for fmincon provides this advice: "If there are no nonlinear inequality or equality constraints, set nonlcon = []."

Community Treasure Hunt

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

Start Hunting!