Toolbox™ solvers do not accept or
handle objective functions or constraints with complex values. However,
the least-squares solvers
lsqlin, and the
can handle these objective functions under the following restrictions:
The objective function must be analytic in the complex
function sense (for details, see Nevanlinna and Paatero ). For example, the
function f(z) = Re(z) – iIm(z) is
not analytic, but the function f(z) = exp(z) is
analytic. This restriction automatically holds for
There must be no constraints, not even bounds. Complex numbers are not well ordered, so it is not clear what “bounds” might mean. When there are problem bounds, nonlinear least-squares solvers disallow steps leading to complex values.
Do not set the FunValCheck option
'on'. This option immediately halts a solver
when the solver encounters a complex value.
The problem-based approach does not support complex values in an objective function, nonlinear equalities, or nonlinear inequalities. If a function calculation has a complex value, even as an intermediate value, the final result can be incorrect.
The least-squares solvers and
to minimize the squared norm of a vector of function values. This
makes sense even in the presence of complex values.
If you have a non-analytic function or constraints, split the real and imaginary parts of the problem. For an example, see Fit a Model to Complex-Valued Data.
To get the best (smallest norm) solution, try setting a complex initial point. For example, solving 1 + x4 = 0 fails if you use a real start point:
f = @(x)1+x^4; x0 = 1; x = fsolve(f,x0)
No solution found. fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the default value of the function tolerance. x = 1.1176e-08
However, if you use a complex initial point,
x0 = 1 + 1i/10; x = fsolve(f,x0)
Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. x = 0.7071 + 0.7071i
 Nevanlinna, Rolf, and V. Paatero. Introduction to Complex Analysis. Addison-Wesley, 1969.