Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roots(polynomial) drops zero roots if only one non-zero coeff in polynomial (Trac #323) #921

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 4 comments

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/323 on 2006-10-05 by trac user RyanGutenkunst, assigned to unknown.

roots(polynomial) drops zero roots if only one non-zero coeff in polynomial

Example (roots of x^{2} == 0)

numpy.roots((1,0,0))
array([], dtype=float64)

Also, roots fails if all coeffs are 0

numpy.roots((0,0))
Traceback (most recent call last):
File "", line 1, in ?
File "/afs/msc.cornell.edu/home/jsethna/ryang/installed/lib/python2.4/site-packages/numpy/lib/polynomial.py", line 96, in roots
trailing_zeros = len(p) - non_zero[-1] - 1
IndexError: index out of bounds

The attached patch fixes both issues. (For the all-zero polynomial, an empty array is returned. This is what matlab does.)

@numpy-gitbot
Copy link
Author

Attachment added by trac user RyanGutenkunst on 2006-10-05: RGutenkunst_polynomial.patch

@numpy-gitbot
Copy link
Author

trac user FabriciO wrote on 2006-10-14

Replying to [comment:1 oliphant]:
I don't agree that changeset 3265 closes ticket #921.
The modifications only solve the case when all coefficient are zero like

roots(poly1d([0,0,0])

but not when there is only one coefficient that is non-zero :

roots(poly1d([1,0,0])

@numpy-gitbot
Copy link
Author

@teoliphant wrote on 2006-10-14

Please provide the error you are getting. This works fine for me.

roots(poly1d([1,0,0]))
array([0., 0.])

@numpy-gitbot
Copy link
Author

trac user FabriciO wrote on 2006-10-14

Sorry, as I got numpy from bleeding-edge apt-get repository (cf http://deb-scipy.alioth.debian.org/), I was thinking that I have a version with the bug fixed.

But with the previous example, I have the following result:

>>> import numpy
>>> numpy.__version__
'1.0rc1'
>>> numpy.lib.polynomial.roots(numpy.lib.polynomial.poly1d([1,0,0]))
array([], dtype=float64)

I'll wait debian-scipy-team release...
Sorry for having reopened the ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant