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.

 채택된 답변

Walter Roberson
Walter Roberson 2012년 11월 18일

0 개 추천

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

Heng
Heng 2012년 11월 19일
편집: Heng 2012년 11월 19일
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.
Matt J
Matt J 2012년 11월 19일
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.
Heng
Heng 2012년 11월 19일
I followed your advise by using SQP, fmincon finally stop sending negative parameters to my function. Thank you very much! :-)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2012년 11월 18일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

태그

질문:

2012년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by