# Python numpy.linalg.eigvals() Examples

The following are code examples for showing how to use numpy.linalg.eigvals(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
def do(self, a, b):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 2
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))

a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray)) 
Example 3
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 4
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))

a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray)) 
Example 5
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 6
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_linalg.py    GNU General Public License v3.0 6 votes
def do(self, a, b):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 7
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))

a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray)) 
Example 8
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 9
 Project: MARRtino-2.0   Author: DaniAffCH   File: test_linalg.py    GNU General Public License v3.0 6 votes
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))

a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray)) 
Example 10
 Project: MARRtino-2.0   Author: DaniAffCH   File: test_linalg.py    GNU General Public License v3.0 6 votes
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 11
def do(self, a, b):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 12
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))

a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray)) 
Example 13
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 14
def test_0_size(self):
# Check that all kinds of 0-sized arrays work
class ArraySubclass(np.ndarray):
pass
a = np.zeros((0, 1, 1), dtype=np.int_).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.float64)
assert_equal((0, 1), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray))

a = np.zeros((0, 0), dtype=np.complex64).view(ArraySubclass)
res = linalg.eigvals(a)
assert_(res.dtype.type is np.complex64)
assert_equal((0,), res.shape)
# This is just for documentation, it might make sense to change:
assert_(isinstance(res, np.ndarray)) 
Example 15
def do(self, a, b, tags):
d = linalg.det(a)
(s, ld) = linalg.slogdet(a)
if asarray(a).dtype.type in (single, double):
else:
assert_almost_equal(d, multiply.reduce(ev, axis=-1))
assert_almost_equal(s * np.exp(ld), multiply.reduce(ev, axis=-1))

s = np.atleast_1d(s)
ld = np.atleast_1d(ld)
m = (s != 0)
assert_almost_equal(np.abs(s[m]), 1)
assert_equal(ld[~m], -inf) 
Example 16
def do(self, a, b):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 17
def test_types(self):
def check(dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype))
for dtype in [single, double, csingle, cdouble]:
yield check, dtype 
Example 18
def do(self, a, b, tags):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 19
def test_types(self, dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype)) 
Example 20
def do(self, a, b, tags):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 21
def test_types(self, dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype)) 
Example 22
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_linalg.py    GNU General Public License v3.0 5 votes
def do(self, a, b):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 23
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: test_linalg.py    GNU General Public License v3.0 5 votes
def test_types(self):
def check(dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype))
for dtype in [single, double, csingle, cdouble]:
yield check, dtype 
Example 24
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: bench_decom.py    GNU General Public License v3.0 5 votes
def bench_eigvals():
numpy_eigvals = nl.eigvals
scipy_eigvals = sl.eigvals
print()
print('           Finding matrix eigenvalues')
print('      ==================================')
print('      |    contiguous     |   non-contiguous ')
print('----------------------------------------------')
print(' size |  scipy  | numpy   |  scipy  | numpy ')

for size,repeat in [(20,150),(100,7),(200,2)]:
repeat *= 1
print('%5s' % size, end=' ')
sys.stdout.flush()

a = random([size,size])

print('| %6.2f ' % measure('scipy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()

print('| %6.2f ' % measure('numpy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()

a = a[-1::-1,-1::-1]  # turn into a non-contiguous array
assert_(not a.flags['CONTIGUOUS'])

print('| %6.2f ' % measure('scipy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()

print('| %6.2f ' % measure('numpy_eigvals(a)',repeat), end=' ')
sys.stdout.flush()

print('   (secs for %s calls)' % (repeat)) 
Example 25
def do(self, a, b, tags):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 26
def test_types(self):
def check(dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype))
for dtype in [single, double, csingle, cdouble]:
check(dtype) 
Example 27
def make(self, key):
z2 = z.reshape(z.shape[0], -1)
cov = np.cov(z2.T)
vals = np.real(eigvals(cov))[:100]
key['eigen_values'] = vals
self.insert1(key) 
Example 28
def make(self, key):
z2 = z.reshape(z.shape[0], -1)
cov = np.cov(z2.T)
vals = np.real(eigvals(cov))
key['eigen_values'] = vals
self.insert1(key) 
Example 29
 Project: MARRtino-2.0   Author: DaniAffCH   File: test_linalg.py    GNU General Public License v3.0 5 votes
def do(self, a, b, tags):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 30
 Project: MARRtino-2.0   Author: DaniAffCH   File: test_linalg.py    GNU General Public License v3.0 5 votes
def test_types(self, dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype)) 
Example 31
def do(self, a, b):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 32
def test_types(self):
def check(dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype))
for dtype in [single, double, csingle, cdouble]:
yield check, dtype 
Example 33
def is_positive_definite(A):
if A is None:
return False
return (eigvals(A) > 0).all() 
Example 34
def is_positive_definite(A):
if A is None:
return False
return (eigvals(A) > 0).all() 
Example 35
def is_positive_definite(alpha):
return (eigvals(array(alpha[1:]).reshape(2, 2)) > 0).all() 
Example 36
def do(self, a, b, tags):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 37
def test_types(self):
def check(dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype))
for dtype in [single, double, csingle, cdouble]:
yield check, dtype 
Example 38
def setupClass(cls):
global np
global eigvals
try:
import numpy as np
import scipy
from numpy.linalg import eigvals
except ImportError:
raise SkipTest('SciPy not available.') 
Example 39
def test_eigenvector_v_katz_random(self):
G = networkx.gnp_random_graph(10,0.5, seed=1234)
e = networkx.eigenvector_centrality_numpy(G)
k = networkx.katz_centrality_numpy(G, 1.0/l)
for n in G:
assert_almost_equal(e[n], k[n]) 
Example 40
def do(self, a, b, tags):
ev = linalg.eigvals(a)
evalues, evectors = linalg.eig(a)
assert_almost_equal(ev, evalues) 
Example 41
def test_types(self, dtype):
x = np.array([[1, 0.5], [0.5, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, dtype)
x = np.array([[1, 0.5], [-1, 1]], dtype=dtype)
assert_equal(linalg.eigvals(x).dtype, get_complex_dtype(dtype)) 
Example 42
def polyroots(c):
"""
Compute the roots of a polynomial.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * x^i.

Parameters
----------
c : 1-D array_like
1-D array of polynomial coefficients.

Returns
-------
out : ndarray
Array of the roots of the polynomial. If all the roots are real,
then out is also real, otherwise it is complex.

--------
chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the power series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

Examples
--------
>>> import numpy.polynomial.polynomial as poly
>>> poly.polyroots(poly.polyfromroots((-1,0,1)))
array([-1.,  0.,  1.])
>>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
dtype('float64')
>>> j = complex(0,1)
>>> poly.polyroots(poly.polyfromroots((-j,0,j)))
array([  0.00000000e+00+0.j,   0.00000000e+00+1.j,   2.77555756e-17-1.j])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = polycompanion(c)
r = la.eigvals(m)
r.sort()
return r

#
# polynomial class
# 
Example 43
def hermroots(c):
"""
Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([ 0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([ -1.00000000e+00,  -1.38777878e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-.5*c[0]/c[1]])

m = hermcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 44
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([ -4.44089210e-16,   1.00000000e+00,   2.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

m = lagcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 45
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([ 0.,  2.,  0.,  1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = hermecompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 46
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = chebcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 47
def hermroots(c):
"""
Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([-1.00000000e+00, -1.38777878e-17,  1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-.5*c[0]/c[1]])

# rotated companion matrix reduces error
m = hermcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 48
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([-4.4408921e-16,  1.0000000e+00,  2.0000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

# rotated companion matrix reduces error
m = lagcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 49
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([0., 2., 0., 1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.]) # may vary

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

# rotated companion matrix reduces error
m = hermecompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 50
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00]) # may vary

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

# rotated companion matrix reduces error
m = chebcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 51
def polyroots(c):
"""
Compute the roots of a polynomial.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * x^i.

Parameters
----------
c : 1-D array_like
1-D array of polynomial coefficients.

Returns
-------
out : ndarray
Array of the roots of the polynomial. If all the roots are real,
then out is also real, otherwise it is complex.

--------
chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the power series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

Examples
--------
>>> import numpy.polynomial.polynomial as poly
>>> poly.polyroots(poly.polyfromroots((-1,0,1)))
array([-1.,  0.,  1.])
>>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
dtype('float64')
>>> j = complex(0,1)
>>> poly.polyroots(poly.polyfromroots((-j,0,j)))
array([  0.00000000e+00+0.j,   0.00000000e+00+1.j,   2.77555756e-17-1.j])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = polycompanion(c)
r = la.eigvals(m)
r.sort()
return r

#
# polynomial class
# 
Example 52
def legroots(c):
"""
Compute the roots of a Legendre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, chebroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such values.
Roots with multiplicity greater than 1 will also show larger errors as
the value of the series near such points is relatively insensitive to
errors in the roots. Isolated roots near the origin can be improved by
a few iterations of Newton's method.

The Legendre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.legendre as leg
>>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0, all real roots
array([-0.85099543, -0.11407192,  0.51506735])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = legcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 53
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([ -4.44089210e-16,   1.00000000e+00,   2.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

m = lagcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 54
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([ 0.,  2.,  0.,  1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = hermecompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 55
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = chebcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 56
def nearestPD(A):
"""Find the nearest positive-definite matrix to input

A Python/Numpy port of John D'Errico's nearestSPD MATLAB code [1], which
credits [2].

[1] https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd

[2] N.J. Higham, "Computing a nearest symmetric positive semidefinite
matrix" (1988): https://doi.org/10.1016/0024-3795(88)90223-6
"""

B = (A + A.T) / 2
_, s, V = la.svd(B)

H = np.dot(V.T, np.dot(np.diag(s), V))

A2 = (B + H) / 2

A3 = (A2 + A2.T) / 2

if isPD(A3):
return A3

spacing = np.spacing(la.norm(A))
# The above is different from [1]. It appears that MATLAB's chol Cholesky
# decomposition will accept matrixes with exactly 0-eigenvalue, whereas
# Numpy's will not. So where [1] uses eps(mineig) (where eps is Matlab
# for np.spacing), we use the above definition. CAVEAT: our spacing
# will be much larger than [1]'s eps(mineig), since mineig is usually on
# the order of 1e-16, and eps(1e-16) is on the order of 1e-34, whereas
# spacing will, for Gaussian random matrixes of small dimension, be on
# othe order of 1e-16. In practice, both ways converge, as the unit test
# below suggests.
I = np.eye(A.shape[0])
k = 1
while not isPD(A3):
mineig = np.min(np.real(la.eigvals(A3)))
A3 += I * (-mineig * k**2 + spacing)
k += 1

return A3 
Example 57
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: polynomial.py    GNU General Public License v3.0 4 votes
def polyroots(c):
"""
Compute the roots of a polynomial.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * x^i.

Parameters
----------
c : 1-D array_like
1-D array of polynomial coefficients.

Returns
-------
out : ndarray
Array of the roots of the polynomial. If all the roots are real,
then out is also real, otherwise it is complex.

--------
chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the power series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

Examples
--------
>>> import numpy.polynomial.polynomial as poly
>>> poly.polyroots(poly.polyfromroots((-1,0,1)))
array([-1.,  0.,  1.])
>>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
dtype('float64')
>>> j = complex(0,1)
>>> poly.polyroots(poly.polyfromroots((-j,0,j)))
array([  0.00000000e+00+0.j,   0.00000000e+00+1.j,   2.77555756e-17-1.j])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = polycompanion(c)
r = la.eigvals(m)
r.sort()
return r

#
# polynomial class
# 
Example 58
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: hermite.py    GNU General Public License v3.0 4 votes
def hermroots(c):
"""
Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([ 0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([ -1.00000000e+00,  -1.38777878e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-.5*c[0]/c[1]])

m = hermcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 59
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: laguerre.py    GNU General Public License v3.0 4 votes
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([ -4.44089210e-16,   1.00000000e+00,   2.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

m = lagcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 60
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: hermite_e.py    GNU General Public License v3.0 4 votes
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([ 0.,  2.,  0.,  1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = hermecompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 61
 Project: att   Author: Centre-Alt-Rendiment-Esportiu   File: chebyshev.py    GNU General Public License v3.0 4 votes
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = chebcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 62
def polyroots(c):
"""
Compute the roots of a polynomial.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * x^i.

Parameters
----------
c : 1-D array_like
1-D array of polynomial coefficients.

Returns
-------
out : ndarray
Array of the roots of the polynomial. If all the roots are real,
then out is also real, otherwise it is complex.

--------
chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the power series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

Examples
--------
>>> import numpy.polynomial.polynomial as poly
>>> poly.polyroots(poly.polyfromroots((-1,0,1)))
array([-1.,  0.,  1.])
>>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
dtype('float64')
>>> j = complex(0,1)
>>> poly.polyroots(poly.polyfromroots((-j,0,j)))
array([  0.00000000e+00+0.j,   0.00000000e+00+1.j,   2.77555756e-17-1.j])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = polycompanion(c)
r = la.eigvals(m)
r.sort()
return r

#
# polynomial class
# 
Example 63
def legroots(c):
"""
Compute the roots of a Legendre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, chebroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such values.
Roots with multiplicity greater than 1 will also show larger errors as
the value of the series near such points is relatively insensitive to
errors in the roots. Isolated roots near the origin can be improved by
a few iterations of Newton's method.

The Legendre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.legendre as leg
>>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0, all real roots
array([-0.85099543, -0.11407192,  0.51506735])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = legcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 64
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([ -4.44089210e-16,   1.00000000e+00,   2.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

m = lagcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 65
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([ 0.,  2.,  0.,  1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = hermecompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 66
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = chebcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 67
 Project: MARRtino-2.0   Author: DaniAffCH   File: hermite.py    GNU General Public License v3.0 4 votes
def hermroots(c):
"""
Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([-1.00000000e+00, -1.38777878e-17,  1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-.5*c[0]/c[1]])

# rotated companion matrix reduces error
m = hermcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 68
 Project: MARRtino-2.0   Author: DaniAffCH   File: laguerre.py    GNU General Public License v3.0 4 votes
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([-4.4408921e-16,  1.0000000e+00,  2.0000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

# rotated companion matrix reduces error
m = lagcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 69
 Project: MARRtino-2.0   Author: DaniAffCH   File: hermite_e.py    GNU General Public License v3.0 4 votes
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([0., 2., 0., 1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.]) # may vary

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

# rotated companion matrix reduces error
m = hermecompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 70
 Project: MARRtino-2.0   Author: DaniAffCH   File: chebyshev.py    GNU General Public License v3.0 4 votes
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00]) # may vary

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

# rotated companion matrix reduces error
m = chebcompanion(c)[::-1,::-1]
r = la.eigvals(m)
r.sort()
return r 
Example 71
def polyroots(c):
"""
Compute the roots of a polynomial.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * x^i.

Parameters
----------
c : 1-D array_like
1-D array of polynomial coefficients.

Returns
-------
out : ndarray
Array of the roots of the polynomial. If all the roots are real,
then out is also real, otherwise it is complex.

--------
chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the power series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

Examples
--------
>>> import numpy.polynomial.polynomial as poly
>>> poly.polyroots(poly.polyfromroots((-1,0,1)))
array([-1.,  0.,  1.])
>>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
dtype('float64')
>>> j = complex(0,1)
>>> poly.polyroots(poly.polyfromroots((-j,0,j)))
array([  0.00000000e+00+0.j,   0.00000000e+00+1.j,   2.77555756e-17-1.j])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = polycompanion(c)
r = la.eigvals(m)
r.sort()
return r

#
# polynomial class
# 
Example 72
def hermroots(c):
"""
Compute the roots of a Hermite series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * H_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, chebroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Hermite series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite import hermroots, hermfromroots
>>> coef = hermfromroots([-1, 0, 1])
>>> coef
array([ 0.   ,  0.25 ,  0.   ,  0.125])
>>> hermroots(coef)
array([ -1.00000000e+00,  -1.38777878e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-.5*c[0]/c[1]])

m = hermcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 73
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([ -4.44089210e-16,   1.00000000e+00,   2.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

m = lagcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 74
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([ 0.,  2.,  0.,  1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = hermecompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 75
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = chebcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 76
def polyroots(c):
"""
Compute the roots of a polynomial.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * x^i.

Parameters
----------
c : 1-D array_like
1-D array of polynomial coefficients.

Returns
-------
out : ndarray
Array of the roots of the polynomial. If all the roots are real,
then out is also real, otherwise it is complex.

--------
chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the power series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

Examples
--------
>>> import numpy.polynomial.polynomial as poly
>>> poly.polyroots(poly.polyfromroots((-1,0,1)))
array([-1.,  0.,  1.])
>>> poly.polyroots(poly.polyfromroots((-1,0,1))).dtype
dtype('float64')
>>> j = complex(0,1)
>>> poly.polyroots(poly.polyfromroots((-j,0,j)))
array([  0.00000000e+00+0.j,   0.00000000e+00+1.j,   2.77555756e-17-1.j])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = polycompanion(c)
r = la.eigvals(m)
r.sort()
return r

#
# polynomial class
# 
Example 77
def legroots(c):
"""
Compute the roots of a Legendre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, chebroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such values.
Roots with multiplicity greater than 1 will also show larger errors as
the value of the series near such points is relatively insensitive to
errors in the roots. Isolated roots near the origin can be improved by
a few iterations of Newton's method.

The Legendre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.legendre as leg
>>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0, all real roots
array([-0.85099543, -0.11407192,  0.51506735])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = legcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 78
def lagroots(c):
"""
Compute the roots of a Laguerre series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * L_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, chebroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Laguerre series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.laguerre import lagroots, lagfromroots
>>> coef = lagfromroots([0, 1, 2])
>>> coef
array([  2.,  -8.,  12.,  -6.])
>>> lagroots(coef)
array([ -4.44089210e-16,   1.00000000e+00,   2.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([1 + c[0]/c[1]])

m = lagcompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 79
def hermeroots(c):
"""
Compute the roots of a HermiteE series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * He_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, chebroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The HermiteE series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
>>> coef = hermefromroots([-1, 0, 1])
>>> coef
array([ 0.,  2.,  0.,  1.])
>>> hermeroots(coef)
array([-1.,  0.,  1.])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) <= 1:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = hermecompanion(c)
r = la.eigvals(m)
r.sort()
return r 
Example 80
def chebroots(c):
"""
Compute the roots of a Chebyshev series.

Return the roots (a.k.a. "zeros") of the polynomial

.. math:: p(x) = \\sum_i c[i] * T_i(x).

Parameters
----------
c : 1-D array_like
1-D array of coefficients.

Returns
-------
out : ndarray
Array of the roots of the series. If all the roots are real,
then out is also real, otherwise it is complex.

--------
polyroots, legroots, lagroots, hermroots, hermeroots

Notes
-----
The root estimates are obtained as the eigenvalues of the companion
matrix, Roots far from the origin of the complex plane may have large
errors due to the numerical instability of the series for such
values. Roots with multiplicity greater than 1 will also show larger
errors as the value of the series near such points is relatively
insensitive to errors in the roots. Isolated roots near the origin can
be improved by a few iterations of Newton's method.

The Chebyshev series basis polynomials aren't powers of x so the
results of this function may seem unintuitive.

Examples
--------
>>> import numpy.polynomial.chebyshev as cheb
>>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00])

"""
# c is a trimmed copy
[c] = pu.as_series([c])
if len(c) < 2:
return np.array([], dtype=c.dtype)
if len(c) == 2:
return np.array([-c[0]/c[1]])

m = chebcompanion(c)
r = la.eigvals(m)
r.sort()
return r