File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1010//! where `D` is the diagonal matrix of generalized eigenvalues in ascending
1111//! order and `V` is the matrix of corresponding generalized eigenvectors. The
1212//! 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+ //! ```
1335
1436use ndarray:: * ;
1537
You can’t perform that action at this time.
0 commit comments