summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Moncur <mtmoncur@gmail.com>2019-04-08 17:00:10 -0600
committerTyler Moncur <mtmoncur@gmail.com>2019-04-08 17:21:36 -0600
commit732d52a4c3cd91b8a2e20b99823fcd233dc32112 (patch)
treee0e83571bb563ead4ebbe5f8967b898c78aef518
parent96cacd74e50d972df8f6c8704b0f4b3c3dfbc81c (diff)
downloadnumpy-732d52a4c3cd91b8a2e20b99823fcd233dc32112.tar.gz
ENH: rotate companion matrix for all polynomial bases
-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.py5
6 files changed, 13 insertions, 7 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 bada4321e..afa330502 100644
--- a/numpy/polynomial/polynomial.py
+++ b/numpy/polynomial/polynomial.py
@@ -1428,8 +1428,9 @@ def polyroots(c):
if len(c) == 2:
return np.array([-c[0]/c[1]])
- m = polycompanion(c)
- r = la.eigvals(m[::-1,::-1])
+ # rotated companion matrix reduces error
+ m = polycompanion(c)[::-1,::-1]
+ r = la.eigvals(m)
r.sort()
return r