xref: /aosp_15_r20/external/eigen/doc/snippets/JacobiSVD_basic.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li MatrixXf m = MatrixXf::Random(3,2);
2*bf2c3715SXin Li cout << "Here is the matrix m:" << endl << m << endl;
3*bf2c3715SXin Li JacobiSVD<MatrixXf> svd(m, ComputeThinU | ComputeThinV);
4*bf2c3715SXin Li cout << "Its singular values are:" << endl << svd.singularValues() << endl;
5*bf2c3715SXin Li cout << "Its left singular vectors are the columns of the thin U matrix:" << endl << svd.matrixU() << endl;
6*bf2c3715SXin Li cout << "Its right singular vectors are the columns of the thin V matrix:" << endl << svd.matrixV() << endl;
7*bf2c3715SXin Li Vector3f rhs(1, 0, 0);
8*bf2c3715SXin Li cout << "Now consider this rhs vector:" << endl << rhs << endl;
9*bf2c3715SXin Li cout << "A least-squares solution of m*x = rhs is:" << endl << svd.solve(rhs) << endl;
10