nlcpy.linalg.eigh

nlcpy.linalg.eigh(a, UPLO='L')[source]

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

Returns two objects, a 1-D array containing the eigenvalues of a, and a 2-D square array or matrix (depending on the input type) of the corresponding eigenvectors (in columns).

Parameters:
a(…, M, M) array_like

Hermitian or real symmetric matrices whose eigenvalues and eigenvectors are to be computed.

UPLO{‘L’, ‘U’}, optional

Specifies whether the calculation is done with the lower triangular part of a (‘L’, default) or the upper triangular part (‘U’). Irrespective of this value only the real parts of the diagonal will be considered in the computation to preserve the notion of a Hermitian matrix. It therefore follows that the imaginary part of the diagonal will always be treated as zero.

Returns:
w(…, M) ndarray

The eigenvalues in ascending order, each repeated according to its multiplicity.

v(…, M, M) ndarray

The column v[:, i] is the normalized eigenvector corresponding to the eigenvalue w[i].

See also

eigvalsh

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

eig

Computes the eigenvalues and right eigenvectors of a square array.

eigvals

Computes the eigenvalues of a general matrix.

Note

The eigenvalues/eigenvectors are computed using LAPACK routines _syevd, _heevd.

The eigenvalues of real symmetric or complex Hermitian matrices are always real. The array v of (column) eigenvectors is unitary and a, w, and v satisfy the equations dot(a, v[:, i]) = w[i] * v[:, i].

Examples

>>> import nlcpy as vp
>>> a = vp.array([[1, -2j], [2j, 5]])
>>> a
array([[ 1.+0.j, -0.-2.j],
       [ 0.+2.j,  5.+0.j]])
>>> w, v = vp.linalg.eigh(a)
>>> w; v
array([0.17157288, 5.82842712])
array([[-0.92387953+0.j        , -0.38268343+0.j        ], # may vary
       [ 0.        +0.38268343j,  0.        -0.92387953j]])
>>> # demonstrate the treatment of the imaginary part of the diagonal
>>> a = vp.array([[5+2j, 9-2j], [0+2j, 2-1j]])
>>> a
array([[5.+2.j, 9.-2.j],
       [0.+2.j, 2.-1.j]])
>>> # with UPLO='L' this is numerically equivalent to using LA.eig() with:
>>> b = vp.array([[5.+0.j, 0.-2.j], [0.+2.j, 2.-0.j]])
>>> b
array([[5.+0.j, 0.-2.j],
       [0.+2.j, 2.+0.j]])
>>> wa, va = vp.linalg.eigh(a)
>>> wb, vb = vp.linalg.eig(b)
>>> wa; wb
array([1., 6.])
array([6.+0.j, 1.+0.j])
>>> va; vb
array([[-0.4472136 -0.j        , -0.89442719+0.j        ],
       [ 0.        +0.89442719j,  0.        -0.4472136j ]])
array([[ 0.89442719+0.j       ,  0.        +0.4472136j],
       [-0.        +0.4472136j,  0.89442719+0.j       ]])