8000 Perturbations in Polynomial.roots() · Issue #14186 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Perturbations in Polynomial.roots() #14186

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

Closed
f380cedric opened this issue Aug 2, 2019 · 3 comments
Closed

Perturbations in Polynomial.roots() #14186

f380cedric opened this issue Aug 2, 2019 · 3 comments

Comments

@f380cedric
Copy link
Contributor

The roots are well outside of the expected values. But, that is not the case with np.roots(). Is that expected?

Reproducing code example:

import numpy as np

def roots1(coef, x, y):
    for i in range(y.size):
        coefN = coef.copy()
        coefN[0] -= y[i]
        print(np.roots(coefN[::-1]) - x[i])

def roots2(coef, x, y):
    for i in range(y.size):
        print((np.polynomial.polynomial.Polynomial(coef) - y[i]).roots() - x[i])

x = np.arange(4) * 0.1
alpha, beta, gamma = 0.16, 1, 1e-15
coef = np.array([alpha, beta, gamma])
y = alpha + beta*x + gamma*x**2
print("roots")
roots1(coef, x, y)
print("Polynomial")
roots2(coef, x, y)
roots
[-1.e+15  0.e+00]
[-1.e+15  0.e+00]
[-1.00000000e+15  2.77555756e-17]
[-1.00000000e+15  5.55111512e-17]
Polynomial
[-1.e+15  0.e+00]
[-1.0e+15  2.5e-02]
[-1.0e+15 -7.5e-02]
[-1.e+15 -5.e-02]

Numpy/Python version information:

1.16.4 3.7.4 (default, Jul 9 2019, 16:32:37)
[GCC 9.1.1 20190503 (Red Hat 9.1.1-1)]

@ilayn
Copy link
Contributor
ilayn commented Aug 7, 2019

I get identical results via version numbers

NumPy : 1.18.0.dev0+4f7d5eb
Sys :  3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)]

@pmli
Copy link
9748 Contributor
pmli commented Aug 9, 2019

It seems the differences are due to the choice of the companion matrix form. Polynomial.roots in NumPy 1.16 and earlier uses the "standard" form, while in NumPy 1.17 and later it uses the "rotated" form (see #13202). On the other hand, np.roots seems to have always used the "rotated" form (see here).

Just as a remark, there might be more accurate methods for computing roots of polynomials. See, e.g., https://doi.org/10.1137/140983434.

@f380cedric
Copy link
Contributor Author

Since it was solved on 1.17, I'll close.

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

4 participants
0