MATLAB: How to optimize real-valued functions of complex variables within the Optimization Toolbox

complexfunctionfunctionsimaginaryminimizeOptimization Toolboxoptimize

A function of a complex variable "z" is called a complex function "f(z)". This complex function is considered real-valued if "f(z)" is real for all values of "z". I have a real-valued complex function in the form:
f(z) = |z - a|^2 + |z - b|^2
I would like to know how I determine the optimal complex value of this real-valued complex function.

Best Answer

A function of a complex variable "z" is simply a function of two variables; the real part "Re(z)" and imaginary part "Im(z)". Therefore, a function of a complex variable "z" should be a function of two variables "x1" and "x2" (i.e., "z = x1 + i*x2"). The input argument to the objective function will be the vector:
X = [x1]
[x2]
Consider the example:
f(z) = |z - (1+i)|^2 + |z - (2-3i)|^2
First, we create the following function:
function f = objfun(X)
z = X(1, :) + i*X(2, :); % Create complex value from real and imaginary parts
f = abs(z - (1 + i)).^2 + abs(z - (2 - 3i)).^2; % Evaluate complex function
Then, using the initial guess "z = 1 + 2i", the function can be optimized via the following command:
[X f] = fminunc(@objfun, [1; 2]); % Optimize function
z = X(1) + i*X(2) % Create optimal complex value
which produces the optimal value:
z =
-0.5000 + 2.0000i
Note that a warning message will be returned that FMINUNC is switching from the default algorithm.