Line | |
---|
1 | #include <Eigen/Dense>
|
---|
2 | #include <iostream>
|
---|
3 |
|
---|
4 | using namespace Eigen;
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | int main(int, char**)
|
---|
8 | {
|
---|
9 | cout.precision(3);
|
---|
10 | MatrixXf m = MatrixXf::Random(3,2);
|
---|
11 | cout << "Here is the matrix m:" << endl << m << endl;
|
---|
12 | JacobiSVD<MatrixXf> svd(m, ComputeThinU | ComputeThinV);
|
---|
13 | cout << "Its singular values are:" << endl << svd.singularValues() << endl;
|
---|
14 | cout << "Its left singular vectors are the columns of the thin U matrix:" << endl << svd.matrixU() << endl;
|
---|
15 | cout << "Its right singular vectors are the columns of the thin V matrix:" << endl << svd.matrixV() << endl;
|
---|
16 | Vector3f rhs(1, 0, 0);
|
---|
17 | cout << "Now consider this rhs vector:" << endl << rhs << endl;
|
---|
18 | cout << "A least-squares solution of m*x = rhs is:" << endl << svd.solve(rhs) << endl;
|
---|
19 |
|
---|
20 | return 0;
|
---|
21 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.