Complex Numbers in Optimization Toolbox Solvers

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 under the following restrictions:

  • The objective function must be analytic in the complex function sense (for details, see Nevanlinna and Paatero [1]). 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 lsqlin.

  • 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 to 'on'. This option immediately halts a solver when the solver encounters a complex value.

The least-squares solvers and fsolve try 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, fsolve succeeds:

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

References

[1] Nevanlinna, Rolf, and V. Paatero. Introduction to Complex Analysis. Addison-Wesley, 1969.

Related Topics