26 #include <Eigen/Sparse> 33 using Sparse = Eigen::SparseMatrix<double>;
57 template <
class Operator>
79 const std::optional<Vector> initial = {})
80 :
A_(A), dim_(A.rows()), nrIterations_(0) {
82 x0 = initial ? *initial : Vector::Random(dim_);
114 const Vector x = ritzVector_;
116 const double ritzValue = x.dot(A_ * x);
117 const double error = (A_ * x - ritzValue * x).norm();
130 bool compute(
size_t maxIterations,
double tol) {
132 bool isConverged =
false;
134 for (
size_t i = 0; i < maxIterations && !isConverged; i++) {
139 ritzValue_ = ritzVector_.dot(A_ * ritzVector_);
const Operator & A_
Definition: PowerMethod.h:64
bool compute(size_t maxIterations, double tol)
Definition: PowerMethod.h:130
Vector powerIteration(const Vector &x) const
Definition: PowerMethod.h:96
Compute maximum Eigenpair with power method.
Definition: PowerMethod.h:58
typedef and functions to augment Eigen's MatrixXd
PowerMethod(const Operator &A, const std::optional< Vector > initial={})
Construct from the aim matrix and intial ritz vector.
Definition: PowerMethod.h:78
Definition: chartTesting.h:28
typedef and functions to augment Eigen's VectorXd
double eigenvalue() const
Return the eigenvalue.
Definition: PowerMethod.h:147
bool converged(double tol) const
Definition: PowerMethod.h:113
Vector eigenvector() const
Return the eigenvector.
Definition: PowerMethod.h:150
Vector powerIteration() const
Definition: PowerMethod.h:106
size_t nrIterations() const
Return the number of iterations.
Definition: PowerMethod.h:122