blob: 40d76e8e6d8d49f9b16a19ac0b4d04ef46b88da9 [file] [log] [blame]
Benoit Jacobf04c1cb2008-08-11 21:26:37 +00001typedef Matrix<double, 5, 3> Matrix5x3;
2typedef Matrix<double, 5, 5> Matrix5x5;
3Matrix5x3 m = Matrix5x3::Random();
4cout << "Here is the matrix m:" << endl << m << endl;
Benoit Jacob2840ac72009-10-28 18:19:29 -04005Eigen::FullPivLU<Matrix5x3> lu(m);
Benoit Jacobf04c1cb2008-08-11 21:26:37 +00006cout << "Here is, up to permutations, its LU decomposition matrix:"
7 << endl << lu.matrixLU() << endl;
Benoit Jacob414ee1d2009-01-25 16:33:06 +00008cout << "Here is the L part:" << endl;
Benoit Jacobf04c1cb2008-08-11 21:26:37 +00009Matrix5x5 l = Matrix5x5::Identity();
Benoit Jacob9e00d942008-12-20 13:36:12 +000010l.block<5,3>(0,0).part<StrictlyLowerTriangular>() = lu.matrixLU();
Benoit Jacobf04c1cb2008-08-11 21:26:37 +000011cout << l << endl;
Benoit Jacob414ee1d2009-01-25 16:33:06 +000012cout << "Here is the U part:" << endl;
13Matrix5x3 u = lu.matrixLU().part<UpperTriangular>();
14cout << u << endl;
Benoit Jacobf04c1cb2008-08-11 21:26:37 +000015cout << "Let us now reconstruct the original matrix m:" << endl;
Benoit Jacob414ee1d2009-01-25 16:33:06 +000016Matrix5x3 x = l * u;
Benoit Jacobf04c1cb2008-08-11 21:26:37 +000017Matrix5x3 y;
18for(int i = 0; i < 5; i++) for(int j = 0; j < 3; j++)
19 y(i, lu.permutationQ()[j]) = x(lu.permutationP()[i], j);
Benoit Jacob414ee1d2009-01-25 16:33:06 +000020cout << y << endl; // should be equal to the original matrix m