# Solving a non-convex optimization problem using fmincon

I am trying to solve a non-convex optimization problem using fmincon(). At each iteration, I am iteratively looking for the optimum value and when the termination criterion is satisfied, I keep this value as an initial value for fmincon() and run the code for the second iteration.

The problem is the code is running fine for the first to third iteration and then I get the following error

Error using sqpInterface Finite difference derivatives at initial point contain Inf or NaN values. Fmincon cannot continue.

Error in fmincon (line 823) [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = sqpInterface(funfcn,X,full(A),full(B),full(Aeq),full(Beq), .

How can I get rid of this error?

• The error tells you that derivatives that fmincon() had calculated are Inf or NaN for whatever reason. Without knowing what you are doing, it's impossible to say why does it happen. I would start by introducing the problem, looking at the intermediate values (say grad, Hessian, etc at the previous iterations) to find out how the problem behaves. In the current for of the question, there is not a lot we can help you with. – Anton Menshov May 10 at 19:46
• Thank you so much for your reply. It is weird, sometimes the code is running fine for 5 iterations, sometimes for 10 iterations and sometimes stops at the second iteration. What I don't understand is, how does one optimal value from previous iteration, that now is considered as an initial value, can generate such an error? Is it allowed to show the code here and see if someone can help me to get rid of the error? Thanks again – Susan May 10 at 20:44
• I don;t understand what you are doing. Are you running FMINCON until it terminates due to meeting a termination criterion. And then re-running FMINCON using the ending (optimal?) value of the optimization variables as starting values for this new invocation of FMINCON, without any changes having been made to the FMINCON inputs except for the starting values? if so, that doesn't seem to make much sense. Or are you just invoking FMINCON once, and noticing that it produces the finite difference error on some iteration prior to meeting the termination criterion? – Mark L. Stone May 10 at 22:35
• Hah, now that I think of it, your name sounds familiar. This is apparently the problem from ask.cvxr.com/t/…. . And your multiple invocations might be based on reliinearizing on each FMINCON invocation. This is NOT what you should do. Rather, provide FMOINCON the nonlinear non-convex problem and let it solve it ..., once. Furthermore, my guess is finite difference error is due to log(neg argument). Yiu could place bound so that argument must stay positive. Better yet, supply gradient (at least), and even better, also Hessian. – Mark L. Stone May 10 at 22:42
• If you want the least drama, use YALMIP yalmip.github.io to call FMINCON - that will allow you to enter the model in algebraic form, and save you from making various errors).. YALMIP will supply the first derivatives of objective and constraints to FMINCON (but won't supply Hessian). Further, you can use BMIBNB (included with YALMIP) with FMINCON as upper solver to try to solve to global optimality. iI you use YALMIP, you can ask for help at groups.google.com/forum/?fromgroups#!forum/yalmip – Mark L. Stone May 10 at 22:48