For release R2016b and after:
Generally, Optimization Toolbox solvers do not accept or handle objective functions or constraints with complex values. However, the least-squares solvers "lsqcurvefit", "lsqnonlin", and "lsqlin", and the "fsolve" solver can handle these objective functions with some restrictions as mentioned in the following documentation:
The problem statement can be solved as follows:
>> f = @(z)1 + z^2 - z;
>> x0 = 1 + 1i/10;
>> y = fsolve(f,x0)
For release R2016a and before:
The "fsolve" function cannot directly handle complex-valued functions or variables. However, a complex-valued function of a complex variable "z" can also be thought of as a system of 2 real-valued equations in 2 real variables.
Consider the problem statement:
To solve this complex function using the "fsolve" function, we first create the following function file:
function F = myfun(X)
z = X(1, :) + j*X(2, :); % Create complex value from real and imaginary parts
f = z.^2 - z + 1; % Evaluate complex function
F = [real(f); imag(f)]; % Separate real and imaginary parts
Then, using the initial guess "z = 1 + 2j", the function can be solved by the following command:
>> [z fval] = fsolve(@myfun, [1; 2])
which produces the results:
z =
0.5000
0.8661
fval =
6.2523e-005
Therefore, the complex value that produces a local minimum of "abs(f(z))" is found to be: