aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/snippets/JacobiSVD_basic.cpp
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-10-14 10:14:43 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2010-10-14 10:14:43 -0400
commit8f0e80fe304ad34b520a869ae58bbff8b64c63f2 (patch)
tree5c2cc43f147811448899955c5fe86b340ed7aee6 /doc/snippets/JacobiSVD_basic.cpp
parent47197065da5191824bad8418d9d19bdd76febaab (diff)
JacobiSVD:
* fix preallocating constructors, allocate U and V of the right size for computation options * complete documentation and internal comments * improve unit test, test inf/nan values
Diffstat (limited to 'doc/snippets/JacobiSVD_basic.cpp')
-rw-r--r--doc/snippets/JacobiSVD_basic.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/doc/snippets/JacobiSVD_basic.cpp b/doc/snippets/JacobiSVD_basic.cpp
new file mode 100644
index 000000000..ab24b9bca
--- /dev/null
+++ b/doc/snippets/JacobiSVD_basic.cpp
@@ -0,0 +1,9 @@
+MatrixXf m = MatrixXf::Random(3,2);
+cout << "Here is the matrix m:" << endl << m << endl;
+JacobiSVD<MatrixXf> svd(m, ComputeThinU | ComputeThinV);
+cout << "Its singular values are:" << endl << svd.singularValues() << endl;
+cout << "Its left singular vectors are the columns of the thin U matrix:" << endl << svd.matrixU() << endl;
+cout << "Its right singular vectors are the columns of the thin V matrix:" << endl << svd.matrixV() << endl;
+Vector3f rhs(1, 0, 0);
+cout << "Now consider this rhs vector:" << endl << rhs << endl;
+cout << "A least-squares solution of m*x = rhs is:" << endl << svd.solve(rhs) << endl;