Line | |
---|
1 | #include <Eigen/Dense>
|
---|
2 | #include <iostream>
|
---|
3 |
|
---|
4 | using namespace Eigen;
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | int main(int, char**)
|
---|
8 | {
|
---|
9 | cout.precision(3);
|
---|
10 | typedef Matrix<double, 5, 3> Matrix5x3;
|
---|
11 | typedef Matrix<double, 5, 5> Matrix5x5;
|
---|
12 | Matrix5x3 m = Matrix5x3::Random();
|
---|
13 | cout << "Here is the matrix m:" << endl << m << endl;
|
---|
14 | Eigen::FullPivLU<Matrix5x3> lu(m);
|
---|
15 | cout << "Here is, up to permutations, its LU decomposition matrix:"
|
---|
16 | << endl << lu.matrixLU() << endl;
|
---|
17 | cout << "Here is the L part:" << endl;
|
---|
18 | Matrix5x5 l = Matrix5x5::Identity();
|
---|
19 | l.block<5,3>(0,0).triangularView<StrictlyLower>() = lu.matrixLU();
|
---|
20 | cout << l << endl;
|
---|
21 | cout << "Here is the U part:" << endl;
|
---|
22 | Matrix5x3 u = lu.matrixLU().triangularView<Upper>();
|
---|
23 | cout << u << endl;
|
---|
24 | cout << "Let us now reconstruct the original matrix m:" << endl;
|
---|
25 | cout << lu.permutationP().inverse() * l * u * lu.permutationQ().inverse() << endl;
|
---|
26 |
|
---|
27 | return 0;
|
---|
28 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.