nlcpy.linalg.eigvals
- nlcpy.linalg.eigvals(a)[source]
Computes the eigenvalues of a general matrix.
Main difference from
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.
See also
Note
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 asA
:>>> import nlcpy as vp >>> x = vp.random.random() >>> Q = vp.array([[vp.cos(x), -vp.sin(x)], [vp.sin(x), vp.cos(x)]]) >>> vp.linalg.norm(Q[0, :]), vp.linalg.norm(Q[1, :]), vp.dot(Q[0, :],Q[1, :]) (array(1.), array(1.), array(0.))
Now multiply a diagonal matrix by
Q
on one side and byQ.T
on the other:>>> D = vp.diag((-1,1)) >>> vp.linalg.eigvals(D) array([-1., 1.]) >>> A = vp.dot(Q, D) >>> A = vp.dot(A, Q.T) >>> vp.linalg.eigvals(A) array([ 1., -1.]) # random