0
$\begingroup$

I am trying to optimize a function containing complex numbers, however I keep running into errors. Consider the simple optimization problem:

z = x + I*y;
f = Abs[z - (1 + I)^2];
FindMinimum[f, {x, y}]

The output is:

Out[1]={1.2824*10^-8, {x -> -3.00754*10^-9, y -> 2.}}

which seems to be correct. The functions I will try to optimize is more complicated, so I am trying to use the next formulation:

z[x_, y_] := x + I*y;
f[x_, y_] := Abs[z[x, y] - (1 + I)^2];
FindMinimum[f, {x, y}]

In this case I get the error message:

FindMinimum::nrnum: The function value f is not a real number at {x,y} = {1.,1.}. >>

Is there a way to optimize complex functions using functions in Mathematica? Or any advice that could help?

$\endgroup$
5
$\begingroup$

You have to specify the variables in the FindMinimum command:

z[x_, y_] := x + I*y;
f[x_, y_] := Abs[z[x, y] - (1 + I)^2];
FindMinimum[f[x,y], {x, y}]

Out[1]={1.28247*10^-8, {x -> -3.00876*10^-9, y -> 2.}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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