[SciPy-User] Broyden with complex numbers [Was Re: ANN: SciPy 0.11.0 beta 1 released]

Skipper Seabold jsseabold@gmail....
Tue Jun 26 15:04:00 CDT 2012

On Tue, Jun 26, 2012 at 3:49 PM, Denis Laxalde <denis@laxalde.org> wrote:
> Skipper Seabold a écrit :
>>>>> http://projects.scipy.org/scipy/ticket/1682
>>>> Fixed in master.

Thanks for having a look, btw.

>>>> Should this be backported for 0.11 as well?
>>> I think yes. This points out that the test coverage is incomplete here.
> Done.
>> I uncovered some more unusual behavior doing root finding on functions
>> with complex numbers. Is this assumed to be supported? If so, I can
>> file more bug reports.
> The nonlin module has tests with complex functions, so I guess it is
> supposed to be supported. Other modules don't apparently.

This is using broyden. Maybe it's my numpy?


I've since figured out there's a closed form solution to this function, but ...

from scipy import optimize
import numpy as np

z = np.array([ 1.01839781-0.j, 0.29594979-0.9802577j,
0.29594979+0.9802577j, -1.47466178-0.j])
r = np.abs(z)
func = lambda x : (r*np.exp(2j*np.pi*np.array(x))) - z
# correct result
optimize.broyden1(func, [0, -.203, .203, .5])

# raises an error
optimize.broyden1(func, [0, -.203, .203, .5], line_search=None)


TypeError: Cannot cast ufunc add output from dtype('complex128') to
dtype('float64') with casting rule 'same_kind'


More information about the SciPy-User mailing list