Computing Selected Eigenvalues
Often you require only some of the eigenvalues: either all the eigenvalues in a range of real numbers (
a,b), or the
ith through
jth eigenvalues. You can solve these problems using the server objects
RWSymRangeEigServer<double> and
RWSymSomeEigServer<double>. In addition to showing how to solve this specific problem, this section demonstrates how to use a server object to adjust an algorithm's parameters.
This program computes the eigenvalues of the matrix A in the range (a,b). Eigenvectors are not computed.
#include <iostream>
#include <rw/lapack/symmat.h>
#include <rw/lapack/seigsrv.h>
int main()
{
RWSymMat<double> A; // 1
double a,b;
std::cin >> A >> a >> b;
RWSymRangeEigServer<double> server; // 2
server.computeEigenVectors(true); // 3
server.setRange(a,b); // 4
RWSymEigDecomp<double> decomp = server(A); // 5
std::cout << decomp.eigenValues() << std::endl;
return 0;
}
If instead of needing all the eigenvalues in a certain range, you need the
ith through
jth eigenvalues, you use a
RWSymSomeEigServer<double> object like this:
#include <iostream>
#include <rw/lapack/symmat.h>
#include <rw/lapack/seigsrv.h>
int main()
{
RWSymMat<double> A;
int i,j;
std::cin >> A >> i >> j;
RWSymSomeEigServer<double> server;
server.computeEigenVectors(true);
server.setRange(RWRange(i,j)); // 1
RWSymEigDecomp<double> decomp = server(A);
std::cout << decomp.eigenValues() << std::endl;
return 0;
}
The program is the same as the previous program except for
//1, where we set the range of interest. The range is set using one of the subscripting objects
RWSlice,
RWRange, or
RWToEnd. See the
Essential Math Module User’s Guide and the class descriptions in the
SourcePro API Reference Guide for more information on the subscripting objects.