Benoit Jacob | f04c1cb | 2008-08-11 21:26:37 +0000 | [diff] [blame] | 1 | typedef Matrix<double, 5, 3> Matrix5x3; |
| 2 | typedef Matrix<double, 5, 5> Matrix5x5; |
| 3 | Matrix5x3 m = Matrix5x3::Random(); |
| 4 | cout << "Here is the matrix m:" << endl << m << endl; |
Benoit Jacob | 2840ac7 | 2009-10-28 18:19:29 -0400 | [diff] [blame^] | 5 | Eigen::FullPivLU<Matrix5x3> lu(m); |
Benoit Jacob | f04c1cb | 2008-08-11 21:26:37 +0000 | [diff] [blame] | 6 | cout << "Here is, up to permutations, its LU decomposition matrix:" |
| 7 | << endl << lu.matrixLU() << endl; |
Benoit Jacob | 414ee1d | 2009-01-25 16:33:06 +0000 | [diff] [blame] | 8 | cout << "Here is the L part:" << endl; |
Benoit Jacob | f04c1cb | 2008-08-11 21:26:37 +0000 | [diff] [blame] | 9 | Matrix5x5 l = Matrix5x5::Identity(); |
Benoit Jacob | 9e00d94 | 2008-12-20 13:36:12 +0000 | [diff] [blame] | 10 | l.block<5,3>(0,0).part<StrictlyLowerTriangular>() = lu.matrixLU(); |
Benoit Jacob | f04c1cb | 2008-08-11 21:26:37 +0000 | [diff] [blame] | 11 | cout << l << endl; |
Benoit Jacob | 414ee1d | 2009-01-25 16:33:06 +0000 | [diff] [blame] | 12 | cout << "Here is the U part:" << endl; |
| 13 | Matrix5x3 u = lu.matrixLU().part<UpperTriangular>(); |
| 14 | cout << u << endl; |
Benoit Jacob | f04c1cb | 2008-08-11 21:26:37 +0000 | [diff] [blame] | 15 | cout << "Let us now reconstruct the original matrix m:" << endl; |
Benoit Jacob | 414ee1d | 2009-01-25 16:33:06 +0000 | [diff] [blame] | 16 | Matrix5x3 x = l * u; |
Benoit Jacob | f04c1cb | 2008-08-11 21:26:37 +0000 | [diff] [blame] | 17 | Matrix5x3 y; |
| 18 | for(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 Jacob | 414ee1d | 2009-01-25 16:33:06 +0000 | [diff] [blame] | 20 | cout << y << endl; // should be equal to the original matrix m |