Skip to main content

eigen_matrix_symmetric

Function eigen_matrix_symmetric 

Source
pub fn eigen_matrix_symmetric<F>(
    n: usize,
    matvec: F,
    nev: usize,
    which: EigenWhich,
) -> IgraphResult<EigenDecomposition>
where F: Fn(&[f64], &mut [f64]),
Expand description

Compute selected eigenpairs of a real symmetric matrix.

The matrix is defined implicitly: matvec(x, y) must compute y = A * x where both slices have length n.

§Arguments

  • n — matrix dimension
  • matvec — closure computing the matrix-vector product y = A x
  • nev — number of eigenvalues to compute (clamped to n)
  • which — which part of the spectrum to target

§Errors

Returns IgraphError::InvalidArgument if n == 0.

§Examples

use rust_igraph::{eigen_matrix_symmetric, EigenWhich};

// diag(5, 3, 1): top-2 eigenvalues are 5.0 and 3.0.
let result = eigen_matrix_symmetric(
    3,
    |x, y| { y[0] = 5.0*x[0]; y[1] = 3.0*x[1]; y[2] = x[2]; },
    2,
    EigenWhich::LargestAlgebraic,
).unwrap();
assert!((result.eigenvalues[0] - 5.0).abs() < 1e-6);
assert!((result.eigenvalues[1] - 3.0).abs() < 1e-6);