how to force fmincon to run in real numbers?
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Walter Roberson
on 18 Nov 2012
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
Matt J
on 19 Nov 2012
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.
More Answers (1)
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!