summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-04-08 19:40:11 -0600
committerGitHub <noreply@github.com>2019-04-08 19:40:11 -0600
commit167a31ba45d5ac72dea066962f59c0b31940d0a3 (patch)
treee0e83571bb563ead4ebbe5f8967b898c78aef518 /numpy
parent5c3cb43c294df1ce10b0301b14d90540e311b449 (diff)
parent732d52a4c3cd91b8a2e20b99823fcd233dc32112 (diff)
downloadnumpy-167a31ba45d5ac72dea066962f59c0b31940d0a3.tar.gz
Merge pull request #13202 from mtmoncur/rotated-companion-matrix
ENH: use rotated companion matrix to reduce error
Diffstat (limited to 'numpy')
-rw-r--r--numpy/polynomial/chebyshev.py3
-rw-r--r--numpy/polynomial/hermite.py3
-rw-r--r--numpy/polynomial/hermite_e.py3
-rw-r--r--numpy/polynomial/laguerre.py3
-rw-r--r--numpy/polynomial/legendre.py3
-rw-r--r--numpy/polynomial/polynomial.py3
6 files changed, 12 insertions, 6 deletions
diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py
index 836f47363..c37b2c6d6 100644
--- a/numpy/polynomial/chebyshev.py
+++ b/numpy/polynomial/chebyshev.py
@@ -1743,7 +1743,8 @@ def chebroots(c):
if len(c) == 2:
return np.array([-c[0]/c[1]])
- m = chebcompanion(c)
+ # rotated companion matrix reduces error
+ m = chebcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r
diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py
index dcd0a2b4d..3870d1054 100644
--- a/numpy/polynomial/hermite.py
+++ b/numpy/polynomial/hermite.py
@@ -1476,7 +1476,8 @@ def hermroots(c):
if len(c) == 2:
return np.array([-.5*c[0]/c[1]])
- m = hermcompanion(c)
+ # rotated companion matrix reduces error
+ m = hermcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r
diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py
index 48e5eab20..b12c0d792 100644
--- a/numpy/polynomial/hermite_e.py
+++ b/numpy/polynomial/hermite_e.py
@@ -1471,7 +1471,8 @@ def hermeroots(c):
if len(c) == 2:
return np.array([-c[0]/c[1]])
- m = hermecompanion(c)
+ # rotated companion matrix reduces error
+ m = hermecompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r
diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py
index 41d15142a..e103dde92 100644
--- a/numpy/polynomial/laguerre.py
+++ b/numpy/polynomial/laguerre.py
@@ -1475,7 +1475,8 @@ def lagroots(c):
if len(c) == 2:
return np.array([1 + c[0]/c[1]])
- m = lagcompanion(c)
+ # rotated companion matrix reduces error
+ m = lagcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r
diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py
index d56e2ae2c..9eec9740d 100644
--- a/numpy/polynomial/legendre.py
+++ b/numpy/polynomial/legendre.py
@@ -1505,7 +1505,8 @@ def legroots(c):
if len(c) == 2:
return np.array([-c[0]/c[1]])
- m = legcompanion(c)
+ # rotated companion matrix reduces error
+ m = legcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r
diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py
index e3eb7ec5a..afa330502 100644
--- a/numpy/polynomial/polynomial.py
+++ b/numpy/polynomial/polynomial.py
@@ -1428,7 +1428,8 @@ def polyroots(c):
if len(c) == 2:
return np.array([-c[0]/c[1]])
- m = polycompanion(c)
+ # rotated companion matrix reduces error
+ m = polycompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r