When using NMinimize
on functions with complex intermediate expressions (but a real end result), quite often one gets the error LessEqual::nord
. Example:
NMinimize[Abs[(a+I b)^(3/2)],{a,b}]
(*
LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.
LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.
LessEqual::nord: Invalid comparison with 0.306069 + 0. I attempted.
General::stop: Further output of LessEqual::nord
will be suppressed during this calculation.
Less::nord: Invalid comparison with -0.0745302 + 0. I attempted.
NMinimize::cvmit:
Failed to converge to the requested accuracy or precision within 100
iterations.
{1.0635969220476164*^-12 + 0.*I, {a -> -8.71759358950322*^-9, b -> 5.707170335837908*^-9}}
*)
In some cases (not the one above; I didn't find a simple one where it happens) this also results in a clearly wrong result. Therefore it's desirable to remove the error messages.
Now the only way to get rid of this error is to change the expression in a way that it doesn't trigger the error. However the expressions are generally complicated enough that it's not feasible by hand. I've found that a combination of the following strategies works sometimes:
- Use
ComplexExpand
with the optionTargetFunctions->{Re,Im}
. - Put the entire expression into an
Abs
orRe
(despite it being known to be real from construction) and useSimplify
orFullSimplify
with appropriate constraints (and hope it finishes in reasonable time). (Abs
of course only works if the result is also nonnegative)
However those strategies are not always sufficient. Therefore my question:
What are other good strategies to get the expression into a form suitable to NMinimize
?