power_iteration

Function power_iteration 

Source
pub fn power_iteration<T>(
    matrix: &SymCsrMatrix<T>,
    options: &PowerIterationOptions,
    initial_guess: Option<ArrayView1<'_, T>>,
) -> SparseResult<EigenResult<T>>
where T: Float + SparseElement + Debug + Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T> + Sum + SimdUnifiedOps + Send + Sync + 'static,
Expand description

Computes the largest eigenvalue and corresponding eigenvector of a symmetric matrix using the power iteration method.

§Arguments

  • matrix - The symmetric matrix
  • options - Configuration options
  • initial_guess - Initial guess for the eigenvector (optional)

§Returns

Result containing eigenvalue and eigenvector

§Example

use scirs2_core::ndarray::Array1;
use scirs2_sparse::{
    sym_csr::SymCsrMatrix,
    linalg::{power_iteration, PowerIterationOptions},
};

// Create a symmetric matrix
let data = vec![2.0, 1.0, 2.0, 3.0];
let indices = vec![0, 0, 1, 2];
let indptr = vec![0, 1, 3, 4];
let matrix = SymCsrMatrix::new(data, indptr, indices, (3, 3)).unwrap();

// Configure options
let options = PowerIterationOptions {
    max_iter: 100,
    tol: 1e-8,
    normalize: true,
};

// Compute the largest eigenvalue and eigenvector
let result = power_iteration(&matrix, &options, None).unwrap();

// Check the result
println!("Eigenvalue: {}", result.eigenvalues[0]);
println!("Converged in {} iterations", result.iterations);
println!("Final residual: {}", result.residuals[0]);
assert!(result.converged);