flopscope.numpy.linalg.eigvals
fnp.linalg.eigvals(a)[flopscope source][numpy source]
Compute the eigenvalues of a general matrix.
Adapted from NumPy docs np.linalg.eigvals
Eigenvalues only. Cost: $n^3$.
Main difference between eigvals and eig: the eigenvectors aren't
returned.
Parameters
- a:(..., M, M) array_like
A complex- or real-valued matrix whose eigenvalues will be computed.
Returns
- w:(..., M,) ndarray
The eigenvalues, each repeated according to its multiplicity. They are not necessarily ordered, nor are they necessarily real for real matrices.
Raises
- :LinAlgError
If the eigenvalue computation does not converge.
See also
- eig eigenvalues and right eigenvectors of general arrays
- eigvalsh eigenvalues of real symmetric or complex Hermitian (conjugate symmetric) arrays.
- eigh eigenvalues and eigenvectors of real symmetric or complex Hermitian (conjugate symmetric) arrays.
- scipy.linalg.eigvals Similar function in SciPy.
Notes
Broadcasting rules apply, see the flops.linalg documentation for details.
This is implemented using the _geev LAPACK routines which compute
the eigenvalues and eigenvectors of general square arrays.
Examples
Illustration, using the fact that the eigenvalues of a diagonal matrix
are its diagonal elements, that multiplying a matrix on the left
by an orthogonal matrix, Q, and on the right by Q.T (the transpose
of Q), preserves the eigenvalues of the "middle" matrix. In other words,
if Q is orthogonal, then Q * A * Q.T has the same eigenvalues as
A:
>>> import flopscope.numpy as fnp
>>> from numpy import linalg as LA
>>> x = flops.random.random()
>>> Q = flops.array([[flops.cos(x), -flops.sin(x)], [flops.sin(x), flops.cos(x)]])
>>> LA.norm(Q[0, :]), LA.norm(Q[1, :]), flops.dot(Q[0, :],Q[1, :])
(1.0, 1.0, 0.0)Now multiply a diagonal matrix by Q on one side and
by Q.T on the other:
>>> D = flops.diag((-1,1))
>>> LA.eigvals(D)
array([-1., 1.])
>>> A = flops.dot(Q, D)
>>> A = flops.dot(A, Q.T)
>>> LA.eigvals(A)
array([ 1., -1.]) # random