xref: /aosp_15_r20/external/eigen/doc/snippets/LLT_example.cpp (revision bf2c37156dfe67e5dfebd6d394bad8b2ab5804d4)
1*bf2c3715SXin Li MatrixXd A(3,3);
2*bf2c3715SXin Li A << 4,-1,2, -1,6,0, 2,0,5;
3*bf2c3715SXin Li cout << "The matrix A is" << endl << A << endl;
4*bf2c3715SXin Li 
5*bf2c3715SXin Li LLT<MatrixXd> lltOfA(A); // compute the Cholesky decomposition of A
6*bf2c3715SXin Li MatrixXd L = lltOfA.matrixL(); // retrieve factor L  in the decomposition
7*bf2c3715SXin Li // The previous two lines can also be written as "L = A.llt().matrixL()"
8*bf2c3715SXin Li 
9*bf2c3715SXin Li cout << "The Cholesky factor L is" << endl << L << endl;
10*bf2c3715SXin Li cout << "To check this, let us compute L * L.transpose()" << endl;
11*bf2c3715SXin Li cout << L * L.transpose() << endl;
12*bf2c3715SXin Li cout << "This should equal the matrix A" << endl;
13