how to force fmincon to run in real numbers?

Hi:
I'm using fmincon with user-defined fun and nonlcon. All values are real. But I found that sometimes fmincon tries to search in complex numbers, and appears dead. How can I force fmincon to run in real numbers, if it can't find optimal value in real numbers, just exit with an error, don't run into complex numbers. Or is there any matlab function can meet my requirement (search in real)? Thank you.

 Accepted Answer

fmincon will only search in complex numbers if a result returned from the user-provided function is complex (such as log of a negative number.) Possibly you need to use stricter constraints.
What you can do is provide an options structure that has the function value check option set true. That will test for infinite and nan and imaginary function values returned by your user function, and will stop the minimization if it encounters one.

3 Comments

Heng
Heng on 19 Nov 2012
Edited: Heng on 19 Nov 2012
I checked the code and find the input parameters to my func violates the Ax<=b constraint. To be specific, I demand that the search is within nonnegative real numbers, so I specify parameter A of fmincon to be -eye(N) and b to be zeros(NR,1), which is equivalent to each xi>=0. Why fmincon didn't check this inequality constraint before calling my function? Is it a bug of fmincon? btw, even if I set lb to be zeros(NR,1), the same thing happens -- fmincon sends negative x to my function, regardless of this constraint.
You shouldn't be using A*x<=b constraints to enforce simple bound constraints like x(i)>=0. FMINCON has ub and lb arguments for that.
Also, be aware that FMINCON does not generally try to satisfy the constraints at every iteration. It will only try to satisfy them asymptotically. The exception is the ub and lb constraints, which certain FMINCON algorithms will satisfy all the time (like SQP which I mention in my Answer). However, you need to express your positivity constraints using lb to take advantage of that.
I followed your advise by using SQP, fmincon finally stop sending negative parameters to my function. Thank you very much! :-)

Sign in to comment.

More Answers (1)

Matt J
Matt J on 18 Nov 2012
If you write your function to return NaN or Inf in the regions where it would normally be complex-valued, the SQP algorithm in FMINCON will try to take smaller steps when it encounters those regions and hopefully maneuver around them.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!