pydiodon.mat_evd

pydiodon.mat_evd(mat, k=- 1)[source]

Computes the eigenvalues and eigenvectors of a matrix

Parameters
mata numpy array, n x n (a matrix)
kan integer

the number of eigenvalues/vectors to be computed

Returns
Va 2D numpy array

of size n x k: the k eigenvectors

La 1D numpy array

a vector ; the first k eigenvalues

Notes

if k=-1, all eigenvalues and eigenvectors are returned.

This simply uses numpy.linalg.eigh(), and adds some features like

  • sorts eigenvalues in decreasing order

  • sorts eigenvectors in corresponding order

  • sets to zero the imaginary parts (numerical approximation)

Example

>>> import pydiodon as dio
>>> import numpy as np
>>> # building a symmetric matrix
>>> n = 5
>>> A = np.random.random((n,n))
>>> A = (A + A.T)/2
>>> # computing eigenvalues and eigenvectors
>>> V, L = dio.mat_evd(A)

version 21.03.21, 22.09.21, 22.10.13, 22.10.25