2
$\begingroup$

I am trying to use NMinimize to minimize a real-valued function of complex arguments, with a supplied initial point. This doesn't seem to work well. For example, the following gives errors like "LessEqual: invalid comparison":

NMinimize[Re[x*y], {x, y}, Method -> {"SimulatedAnnealing", "InitialPoints" -> {{1 + I, 1 - I}}}]

Of course I could redescribe my function in terms of 4 real variables, the real and imaginary parts of x and y respectively. When I do this everything works fine. But it is a big hassle (the actual complex function I want to optimize is nontrivial.) Furthermore I feel that this is such a trivial translation NMinimize should be capable of doing it under the hood.

So my question is as follows: what is the easiest way to use NMinimize to minimize a real-valued function of complex variables, so that it can handle an initial point.

$\endgroup$

1 Answer 1

3
$\begingroup$

Searching through the documentation for NMinimize, there is no mention of complex numbers. However, you can simply write your own complexNMinimize which appropriately handles the transformations of variables: x -> x$Re + I x$Im.

complexNMinimize[cf_, cVars_, cIniPnts_] := 
 Module[{f, vars, iniPnts, res},
  vars = {# -> 
        Symbol[SymbolName[#] <> "$Re"] + 
     I Symbol[SymbolName[#] <> "$Im"]} & /@ cVars // Flatten;
  f = cf /. vars;
  iniPnts = ReIm /@ cIniPnts // Flatten;

  res = NMinimize[f, Variables@*Last /@ vars // Flatten, 
    Method -> {"SimulatedAnnealing", "InitialPoints" -> {iniPnts}}];

  {First@res, vars /. Last@res}
  ]

f = Abs[x - 2 + I] + Abs[y + 3 - 2 I];
complexNMinimize[f, {x, y}, {1 + I, 1 - I}]
(* {3.79948*10^-8, {x -> 2. - 1. I, y -> -3. + 2. I}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.