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 DoubleSymRangeEigServer and DoubleSymSomeEigServer. 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.h> #include <dsymmat.h> #include <rw/dseigsrv.h> main() { DoubleSymMat A; // 1 double a,b; cin >> A >> a >> b; DoubleSymRangeEigServer server; // 2 server.computeEigenVectors(FALSE); // 3 server.setRange(a,b); // 4 DoubleSymEigDecomp decomp = server(A); // 5 cout << decomp.eigenValues() << endl; }
//1 | First, the matrix and the range are read in from standard input. |
//2 | When the eigenvalue server is constructed, the algorithm parameters are all set to default values. |
//3 | Here we change the setting of a parameter so that only eigenvalues, and not eigenvectors, are computed. |
//4 | Here we set the range in which we are interested and ... |
//5 | We compute the decomposition. |
If instead of needing all the eigenvalues in a certain range, you need the ith through jth eigenvalues, you use a DoubleSymSomeEigServer object like this:
#include <iostream.h> #include <rw/dsymmat.h> #include <rw/dseigsrv.h> main() { DoubleSymMat A; int i,j; cin >> A >> i >> j; DoubleSymSomeEigServer server; server.computeEigenVectors(FALSE); server.setRange(RWRange(i,j)); // 1 DoubleSymEigDecomp decomp = server(A); cout << decomp.eigenValues() << endl; }
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 Math.h++ User's Guide and Reference Manual for more information on the subscripting objects.
>©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.