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
ComplexExpandwith the optionTargetFunctions->{Re,Im}. - Put the entire expression into an
AbsorRe(despite it being known to be real from construction) and useSimplifyorFullSimplifywith appropriate constraints (and hope it finishes in reasonable time). (Absof 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?
_?NumericQbelongs at the top of the FAQ. – Mr.Wizard Jan 22 '12 at 19:24NMinimizesymbolically pre-processes the argument. – Szabolcs Jan 22 '12 at 19:38Complex[2.,0.]does not get transformed to2.(unlike when real and imaginary parts are integers). You canTracethe evauation withTraceInternal -> True, but you don't really want to do that :) – Leonid Shifrin Jan 22 '12 at 19:44+ 0.*Iwas the problem. But with_?NumericQit indeed works! – celtschk Jan 22 '12 at 19:45