We present a program to compute eigenvalues and eigenvectors of a symetric dense matrix. The matrix is simply defined by its coefficients.
#include "OFELI.h" using namespace OFELI; int main(int argc, char *argv[]) { const int n = 6; |
DSMatrix<double> A(n); A = 0; A(1,1) = 2; A(1,2) = -1; for (size_t i=1; i<=n; i++) { A(i,i-1) = -1; A(i,i) = 2; A(i,i+1) = -1; } A(n,n-1) = -1; A(n,n) = 2; |
Vect<double> ev; EigenProblemSolver e(A,ev); |
Vect<double> v(n); for (int i=1; i<=n; i++) { cout << "Eigenvalue #" << i << ": " << ev(i) << endl; e.getEigenVector(i,v); cout << "Eigen vector:\n" << v; } |
cout << "Nb. of iterations: " << e.getNbIter() << endl; return 0; } |