4

Can the solvers in SciPy deal with complex values (i.e x=x'+i*x")? I am specifically interested in using a Nelder-Mead type minimisation function. I am usually a Matlab user and I know that Matlab does not have complex solvers. If SciPy can do this then I'm a convert for sure! Thanks in advance.

  • 1
    What do you mean by "complex solver"? Comparison of two complex numbers is poorly defined since each "number" is two dimensional. Consider x > y. Is the answer real(x) > real(y), imag(x) > imag(y), |x| > |y|, angle(x) > angle(y), real(x)+imag(x) > real(y)+imag(y), or something else? – matt May 31 '13 at 18:33
  • Does [this other Stack Overflow](http://stackoverflow.com/questions/15213141/how-to-do-nonlinear-complex-root-finding-in-python?rq=1) answer help you? – Alex Szatmary Jun 14 '13 at 03:11

1 Answers1

2

It looks like neither scipy.optimize.fmin nor scipy.optimize.leastsq play nice with complex numbers. For example, fmin(lambda x: np.linalg.norm(x - np.array((1.2, 3+2j))), np.array((0j, 0j))) converges to array([ 1.19996429, 2.99997809]) and leastsq just fails. To make it work, I'd embed your complex numbers in R^2, I guess. So like

fmin(lambda x: np.linalg.norm(x - np.array((1.2, 0, 3,2))), np.array((0,0, 0,0)))

which converges to

array([  1.20000095e+00,  -4.11719096e-05,   2.99999705e+00,    2.00001270e+00])

But yea, it would be nice if those functions did play nice with complex numbers.

Ben
  • 9,184
  • 1
  • 43
  • 56