Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding polynomial roots using Python -- Possible Numpy Extension Bug

I am using Numpy to obtain the roots of polynomials. Numpy provides a module 'polynomial'.

My hand calc for x^2 + 5*x + 6 = 0 is x = -2 & x = -3. (Simple)

But my code shows me the wrong answer: array([-0.5 , -0.33333333]) (Inversed?)

Could anyone please find the culprit in my code? Or is it simply a bug?

from numpy.polynomial import Polynomial as P
p = P([1, 5, 6])
p.roots()
like image 350
Fake Howard Avatar asked Sep 25 '13 22:09

Fake Howard


1 Answers

Simply pass it in the other order,

p = P([6, 5, 1])
like image 102
gg349 Avatar answered Sep 28 '22 02:09

gg349