The most important object for the symmetric eigenvalue problem is the symmetric eigenvalue decomposition object DoubleSymEigDecomp. Here is a short program which reads a symmetric matrix from standard input, computes its eigenvalue decomposition, and prints out its eigenvalues and eigenvectors:
#include <iostream.h> #include <rw/dsymmat.h> #include <rw/dsymeig.h> main() { DoubleSymMat A; // 1 cin >> A; DoubleSymEigDecomp decomp(A); // 2 cout << decomp.eigenValues() << endl; // 3 cout << decomp.eigenVectors() << endl; // 4 }
//1 | A is defined to be a symmetric matrix, which is read in from standard input. |
//2 | Here we construct an eigenvalue decomposition object decomp from the matrix. The decomposition object contains all the eigenvalues and eigenvectors, as well as information about whether these quantities are fully accurate and were successfully computed. See the Class Reference for a complete description of the available member functions. |
//3 | We can access a vector containing all the eigenvalues as shown in this line. It is also possible to access one eigenvalue at a time, using the member function eigenValue(int). |
//4 | This line prints out a matrix whose columns are the eigenvectors. You can also access a vector containing just one eigenvector using the member function eigenVector(int). |
The most common variant on this basic problem is to compute only the eigenvectors, and no eigenvalues. This is so common that you can use an optional argument in the decomposition constructor to control computation of eigenvectors. Thus by replacing //2 in the above example with:
DoubleSymEigDecomp decomp(A,FALSE);
the decomposition is constructed without eigenvectors.
>©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.