Search code examples
c++matrixeigen3numerical-analysis

Eigenvalues of sparse matrix using Eigen3


Is there a distinct and effective way of finding eigenvalues and eigenvectors of a real, symmetrical, very large, let's say 10000x10000, sparse matrix in Eigen3? There is an eigenvalue solver for dense matrices but that doesn't make use of the properties of the matrix e.g. it's symmetry. Furthermore I don't want to store the matrix in dense.

Or is there a better (+better documented) library to do that?


Solution

  • Assuming you're looking for a C++ library, check Armadillo.

    The eigs_sym() function seems to be what you want. Quoting the docs, it:

    Obtains a limited number of eigenvalues and eigenvectors of sparse symmetric real matrix X

    A minimal example from the docs adapted to your desired matrix size:

    // generate sparse matrix
    sp_mat A = sprandu<sp_mat>(10000, 10000, 0.1);
    sp_mat B = A.t()*A;
    
    vec eigval;
    mat eigvec;
    
    eigs_sym(eigval, eigvec, B, 5);  // find 5 eigenvalues/eigenvectors