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

eig

Computes the eigenvalues and right eigenvectors of a square array.

eigh

Computes the eigenvalues and eigenvectors of a complex Hermitian or a real symmetric matrix.

eigvalsh

Computes the eigenvalues of a complex Hermitian or real symmetric matrix.

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 as A:

>>> 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 by Q.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