Skip to main content

eigen_matrix

Function eigen_matrix 

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

Compute selected eigenpairs of a general real matrix.

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

Uses Arnoldi iteration to build an upper Hessenberg projection, then QR iteration on the small Hessenberg matrix to extract eigenvalues.

§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;
use rust_igraph::GeneralEigenWhich;

// diag(3, 2, 1): top eigenvalue by magnitude is 3.0
let result = eigen_matrix(
    3,
    |x, y| { y[0] = 3.0*x[0]; y[1] = 2.0*x[1]; y[2] = x[2]; },
    2,
    GeneralEigenWhich::LargestMagnitude,
).unwrap();

let (re, im) = result.eigenvalues[0];
assert!((re - 3.0).abs() < 0.05);
assert!(im.abs() < 0.05);