[Numpy-discussion] Problem with roots and complex coefficients

lorenzo bolla lbolla@gmail....
Thu Apr 19 11:02:05 CDT 2007


updated.
now it works. many thanks.
L.

On 4/19/07, Nils Wagner <nwagner@iam.uni-stuttgart.de> wrote:
>
> lorenzo bolla wrote:
> > dear all,
> > I've some problems with numpy.roots.
> > take a look at the following code:
> >
> > ========================================
> > import numpy
> >
> > OK = numpy.roots([1, 1, 1])
> > OK = numpy.roots([1j, 1])
> > KO = numpy.roots([1, 1j, 1])
> > ========================================
> >
> > it fails with this error message, trying to execute the last line:
> >
> > TypeError: can't convert complex to float; use
> > abs(z)/usr/lib/python2.4/site-packages/numpy/lib/polynomial.py in
> > roots(p)
> >     119     if N > 1:
> >     120         # build companion matrix and find its eigenvalues (the
> > roots)
> > --> 121         A = diag(NX.ones((N-2,), p.dtype), -1)
> >     122         A[0, :] = -p[1:] / p[0]
> >     123         roots = _eigvals(A)
> >
> > /usr/lib/python2.4/site-packages/numpy/lib/twodim_base.py in diag(v, k)
> >      66             i = arange(0,n+k)
> >      67             fi = i+(i-k)*n
> > ---> 68         res.flat[fi] = v
> >      69         return res
> >      70     elif len(s)==2:
> >
> > TypeError: can't convert complex to float; use abs(z)
> >
> > any ideas?
> > thanks,
> > Lorenzo
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Numpy-discussion mailing list
> > Numpy-discussion@scipy.org
> > http://projects.scipy.org/mailman/listinfo/numpy-discussion
> >
> Works fine for me. Maybe you are using an old numpy version.
>
> >>> from numpy import *
> >>> roots([1, 1, 1])
> array([-0.5+0.8660254j, -0.5-0.8660254j])
> >>> roots([1j, 1])
> array([-0.+1.j])
> >>> roots([1, 1j, 1])
> array([  0.00000000e+00-1.61803399j,   1.38777878e-17+0.61803399j])
> >>> import numpy
> >>> numpy.__version__
> '1.0.3.dev3716'
>
>
> Nils
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070419/7bbd5f9c/attachment.html 


More information about the Numpy-discussion mailing list