Closed
Description
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)]