xref: /aosp_15_r20/external/eigen/doc/snippets/class_FullPivLU.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li typedef Matrix<double, 5, 3> Matrix5x3;
2*bf2c3715SXin Li typedef Matrix<double, 5, 5> Matrix5x5;
3*bf2c3715SXin Li Matrix5x3 m = Matrix5x3::Random();
4*bf2c3715SXin Li cout << "Here is the matrix m:" << endl << m << endl;
5*bf2c3715SXin Li Eigen::FullPivLU<Matrix5x3> lu(m);
6*bf2c3715SXin Li cout << "Here is, up to permutations, its LU decomposition matrix:"
7*bf2c3715SXin Li      << endl << lu.matrixLU() << endl;
8*bf2c3715SXin Li cout << "Here is the L part:" << endl;
9*bf2c3715SXin Li Matrix5x5 l = Matrix5x5::Identity();
10*bf2c3715SXin Li l.block<5,3>(0,0).triangularView<StrictlyLower>() = lu.matrixLU();
11*bf2c3715SXin Li cout << l << endl;
12*bf2c3715SXin Li cout << "Here is the U part:" << endl;
13*bf2c3715SXin Li Matrix5x3 u = lu.matrixLU().triangularView<Upper>();
14*bf2c3715SXin Li cout << u << endl;
15*bf2c3715SXin Li cout << "Let us now reconstruct the original matrix m:" << endl;
16*bf2c3715SXin Li cout << lu.permutationP().inverse() * l * u * lu.permutationQ().inverse() << endl;
17