MATLAB: FSOLVE seems to find complex roots correctly (although it shouldn’t)

fsolve complex

I am using an oldish version of MatLab, r2009a, where the manual entry on FSOLVE states that, "when x has complex variables, the variables must be split into real and imaginary parts".
However, FSOLVE seems to handle complex solutions quite well. Here's a simple example:
opt=optimset('Maxiter',200,'TolX',1e-7,'Tolfun',1e-7);
fsolve(@(x)1i*x^2-2i*x+5i,0.5i,opt)
Optimization terminated: first-order optimality is less than options.TolFun.
ans =
1.0000 + 2.0000i
I've also checked the actual problem I'm working with — an eigenvalue problem for a second-order linear differential operator — and FSOLVE works for it perfectly well too (I've solved the problem twice: by applying FSOLVE to the complex problem "as is" and by splitting it into real and imaginary parts).
So, my question is: in which cases FSOLVE canNOT handle complex roots?

Best Answer

The description of when fsolve works with complex functions is in Complex Numbers in Optimization Toolbox Solvers. In short, the fsolve algorithms have not changed, but MathWorks has only relatively recently qualified its algorithms to work with complex numbers under the condition that the objective functions are analytic, and the algorithms often work better using a complex initial point.
Alan Weiss
MATLAB mathematical toolbox documentation