There are two relatively convenient options for calculating
selected (e.g. a few largest or smallest) eigenvalues using Eigen.
The first is Spectra, a header-only C++ library based on Eigen
that uses algorithms similar to ARPACK (implicitly-restarted
Arnoldi) to calculate a few eigensolutions.
Since it is header-only, you simply download and include the
appropriate header files. The site contains several example problems to
get you started.
A second option, if your matrix is symmetric, is an
interface to a subset of ARPACK, that is part of the standard Eigen distribution, and is very easy to use. Here is a small snippet of
code to give you the basic idea of how to use this interface
typedef Eigen::SparseMatrix<double> SparseMat;
typedef Eigen::SimplicialLDLT<SparseMat> SparseChol;
typedef Eigen::ArpackGeneralizedSelfAdjointEigenSolver <SparseMat, SparseChol> Arpack;
// define sparse matrix A
// calculate the two smallest eigenvalues
int nbrEigenvalues = 2;
arpack.compute(A, nbrEigenvalues, "SM");
cout << "arpack eigenvalues\n" << arpack.eigenvalues().transpose() << endl;
The downside of this approach is that you need to have an ARPACK library
built for your particular system. If you need to build ARPACK yourself, I
suggest this version, ARPACK-NG, because it has many bug fixes compared with the
original and more support for building on different platforms.