|
1 |
| -//! Eigenvalue decomposition for Hermite matrices |
| 1 | +//! Eigendecomposition for Hermitian matrices. |
| 2 | +//! |
| 3 | +//! For a Hermitian matrix `A`, this solves the eigenvalue problem `A V = V D` |
| 4 | +//! for `D` and `V`, where `D` is the diagonal matrix of eigenvalues in |
| 5 | +//! ascending order and `V` is the orthonormal matrix of corresponding |
| 6 | +//! eigenvectors. |
| 7 | +//! |
| 8 | +//! For a pair of Hermitian matrices `A` and `B` where `B` is also positive |
| 9 | +//! definite, this solves the generalized eigenvalue problem `A V = B V D`, |
| 10 | +//! where `D` is the diagonal matrix of generalized eigenvalues in ascending |
| 11 | +//! order and `V` is the matrix of corresponding generalized eigenvectors. The |
| 12 | +//! matrix `V` is normalized such that `V^H B V = I`. |
| 13 | +//! |
| 14 | +//! # Example |
| 15 | +//! |
| 16 | +//! Find the eigendecomposition of a Hermitian (or real symmetric) matrix. |
| 17 | +//! |
| 18 | +//! ``` |
| 19 | +//! use approx::assert_abs_diff_eq; |
| 20 | +//! use ndarray::{array, Array2}; |
| 21 | +//! use ndarray_linalg::{Eigh, UPLO}; |
| 22 | +//! |
| 23 | +//! let a: Array2<f64> = array![ |
| 24 | +//! [2., 1.], |
| 25 | +//! [1., 2.], |
| 26 | +//! ]; |
| 27 | +//! let (eigvals, eigvecs) = a.eigh(UPLO::Lower)?; |
| 28 | +//! assert_abs_diff_eq!(eigvals, array![1., 3.]); |
| 29 | +//! assert_abs_diff_eq!( |
| 30 | +//! a.dot(&eigvecs), |
| 31 | +//! eigvecs.dot(&Array2::from_diag(&eigvals)), |
| 32 | +//! ); |
| 33 | +//! # Ok::<(), Box<dyn std::error::Error>>(()) |
| 34 | +//! ``` |
2 | 35 |
|
3 | 36 | use ndarray::*;
|
4 | 37 |
|
|
0 commit comments