Skip to content

Commit ab4cc02

Browse files
committed
Add example to eigh module
1 parent 3c4df76 commit ab4cc02

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ndarray-linalg/src/eigh.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@
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
1436
use ndarray::*;
1537

0 commit comments

Comments
 (0)