MATLAB Answers

how to bypass my complex values inside objective functions? bounds and constraints not working…

9 views (last 30 days)
jun on 26 Oct 2014
Commented: Nayan Rawat on 9 Sep 2019
This is of my dissertation. Huge headache! I am estimating this 20-parameter time-series model, minimizing this GMM objective function.
I was many times given the error message ’obj function returns complex values, fmincon or fminsearch cannot continue’. I know that fmincon/fminsearch these minimizers only handle real values, only real number can be minimized. My problem lies in a very complicated Square Root expression inside my obj function. The expression is so complex a function of those parameters that no way I could simply bound my parameters to guarantee the expression positive.
fmincon has the option to attach constraints, so I constrained that expression to be positive, but as many have pointed out here on Matlab forums, constraints in “fmincon algorithm” is not strictly obeyed. In my case, I still receive same error message after constrained. While fminsearch does not deal with constraints.
What are the solutions to this complex error? Bounds or constraints appear not working for it. Can one in some way tell the minimizer to skip/ignore this complex iteration and proceed to the next feasible iteration? Or is there a totally different solver that is free from complex issues? Gratefully appreciate any relevant feedback.

Answers (2)

Roger Stafford
Roger Stafford on 26 Oct 2014
I would suggest that in computing your objective function, you yourself apply the constraint of non-negativity to the expression inside the square root by applying max(expression,0) to it. Then when a negative value occurs in the expression, the square root will simply be zero and never complex-valued.

  1 Comment

jun on 26 Oct 2014
Thanks for the quick reply! Sounds a small smart move that could possible make a whole difference. Will absolutely try that and get back here. Thanks again Roger.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by