Class lanczos (o2scl_linalg)¶
-
template<class vec_t = boost::numeric::ublas::vector<double>, class mat_t = boost::numeric::ublas::matrix<double>>
class lanczos¶ Lanczos diagonalization.
This class approximates the largest eigenvalues of a symmetric matrix.
The vector and matrix types can be any type which provides access via
operator
[] oroperator()
, given a suitable vector allocation type.The tridiagonalization routine was rewritten from the EISPACK routines
imtql1.f
(but usesstd::hypot()
instead ofpythag.f
).- Idea for Future:
The function eigen_tdiag() automatically sorts the eigenvalues, which may not be necessary.
- Idea for Future:
Do something better than the simple matrix-vector product. For example, use dgemm() and allow user to specify column or row-major.
- Idea for Future:
Rework memory allocation to perform as needed.
Public Functions
-
inline lanczos()¶
-
inline int eigenvalues(size_t size, mat_t &mat, size_t n_iter, vec_t &eigen, vec_t &diag, vec_t &off_diag)¶
Approximate the largest eigenvalues of a symmetric matrix
mat
using the Lanczos method.Given a square matrix
mat
with sizesize
, this function appliesn_iter
iterations of the Lanczos algorithm to producen_iter
approximate eigenvalues stored ineigen
. As a by-product, this function also partially tridiagonalizes the matrix placing the result indiag
andoff_diag
. Before calling this function, space must have already been allocated foreigen
,diag
, andoff_diag
. All three of these arrays must have at least enough space forn_iter
elements.Choosing /c n_iter =
size
will produce all of the exact eigenvalues and the corresponding tridiagonal matrix, but this may be slower than diagonalizing the matrix directly.
-
inline int eigen_tdiag(size_t n, vec_t &diag, vec_t &off_diag)¶
In-place diagonalization of a tridiagonal matrix.
On input, the vectors
diag
andoff_diag
should both be vectors of sizen
. The diagonal entries stored indiag
, and the \( n-1 \) off-diagonal entries should be stored inoff_diag
, starting withoff_diag
[1]. The value inoff_diag
[0] is unused. The vectoroff_diag
is destroyed by the computation.This uses an implict QL method from the EISPACK routine
imtql1
. The value ofierr
from the original Fortran routine is stored in td_lasteval.