Rev | Line | |
---|
[136] | 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 | MatrixXd A(3,3);
|
---|
| 11 | A << 4,-1,2, -1,6,0, 2,0,5;
|
---|
| 12 | cout << "The matrix A is" << endl << A << endl;
|
---|
| 13 |
|
---|
| 14 | LLT<MatrixXd> lltOfA(A); // compute the Cholesky decomposition of A
|
---|
| 15 | MatrixXd L = lltOfA.matrixL(); // retrieve factor L in the decomposition
|
---|
| 16 | // The previous two lines can also be written as "L = A.llt().matrixL()"
|
---|
| 17 |
|
---|
| 18 | cout << "The Cholesky factor L is" << endl << L << endl;
|
---|
| 19 | cout << "To check this, let us compute L * L.transpose()" << endl;
|
---|
| 20 | cout << L * L.transpose() << endl;
|
---|
| 21 | cout << "This should equal the matrix A" << endl;
|
---|
| 22 |
|
---|
| 23 | return 0;
|
---|
| 24 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.