imsl.eigen.eig_gen¶
-
eig_gen
(a, vectors=False)¶ Compute the eigenexpansion of a general real or complex matrix.
Parameters: - a ((N,N) array_like) – Array containing the input matrix.
- vectors (bool, optional) –
Specifies if the eigenvectors should be returned.
Default: vectors = False
Returns: - A named tuple with the following fields
- eigenvalues ((N,) complex ndarray) – The eigenvalues of the matrix, each repeated according to its algebraic multiplicity.
- eigenvectors ((N,N) complex ndarray) – The eigenvectors of the matrix. Returned only if vectors = True.
Notes
Function eig_gen computes the eigenvalues of a real or complex matrix by a two-phase process. In the real case, the matrix is reduced to upper Hessenberg form by elementary orthogonal or Gauss similarity transformations. Then, eigenvalues are computed using a QR or combined LR-QR algorithm ([1], pp. 373 - 382, and [2]). The combined LR-QR algorithm is based on an implementation by Jeff Haag and David Watkins. Eigenvectors are then calculated as required. When eigenvectors are computed, the QR algorithm is used to compute the eigenexpansion. When only eigenvalues are required, the combined LR-QR algorithm is used. In the complex case, the matrix is reduced to upper Hessenberg form by elementary Gauss transformations. Then, the eigenvalues are computed using an explicitly shifted LR algorithm. Eigenvectors are calculated during the iterations for the eigenvalues ([3]).
References
[1] Golub, G.H., and C.F. Van Loan (1989), Matrix Computations, Second Edition, The Johns Hopkins University Press, Baltimore, Maryland. [2] Watkins, David S., and L. Elsner (1991), Convergence of algorithm of decomposition type for the eigenvalue problem, Linear Algebra Applications, 143, pp. 29-47. [3] Martin, R.S., and J.H. Wilkinson (1971), The modified LR Algorithm for Complex Hessenberg Matrices, Handbook, Volume II, Linear Algebra, Springer, New York. Examples
Example 1:
>>> import imsl.eigen as eig >>> import numpy as np >>> a = [[8.0, -1.0, -5.0], [-4.0, 4.0, -2.0], [18.0, -5.0, -7.0]] >>> result = eig.eig_gen(a, vectors=True) >>> print("Eigenvalues:\n"+str(result.eigenvalues)) ... Eigenvalues: [2.+4.j 2.-4.j 1.+0.j] >>> np.set_printoptions(precision=4, suppress=True) >>> print("Eigenvectors:\n"+str(result.eigenvectors)) Eigenvectors: [[ 0.3162-0.3162j 0.3162+0.3162j 0.4082+0.j ] [ 0.6325+0.j 0.6325+0.j 0.8165+0.j ] [ 0.0000-0.6325j 0.0000+0.6325j 0.4082+0.j ]] >>> # Put back the default options >>> np.set_printoptions()
Example 2:
>>> import imsl.eigen as eig >>> import numpy as np >>> a = [[5.0+9.0j, 5.0+5.0j, -6.0-6.0j, -7.0-7.0j], ... [3.0+3.0j, 6.0+10.0j, -5.0-5.0j, -6.0-6.0j], ... [2.0+2.0j, 3.0+3.0j, -1.0+3.0j, -5.0-5.0j], ... [1.0+1.0j, 2.0+2.0j, -3.0-3.0j, 4.0j]] >>> result = eig.eig_gen(a, vectors=True) >>> print("Eigenvalues:\n"+str(result.eigenvalues)) ... Eigenvalues: [4.+8.j 3.+7.j 2.+6.j 1.+5.j] >>> np.set_printoptions(precision=4, suppress=True) >>> print("Eigenvectors:\n"+str(result.eigenvectors)) Eigenvectors: [[ 0.5774+0.j 0.5774+0.j 0.3780+0.j 0.7559+0.j] [ 0.5774-0.j 0.5774-0.j 0.7559+0.j 0.3780+0.j] [ 0.5774-0.j 0.0000-0.j 0.3780+0.j 0.3780+0.j] [-0.0000+0.j 0.5774-0.j 0.3780+0.j 0.3780+0.j]] >>> # Put back the default options >>> np.set_printoptions()