I'm trying to calculate the Cholesky factor of a matrix in C++ (for a given matrix P find L such that LL^T=P). My objective is NOT to solve a linear system P*x=b, as such matrix decompositions are often used for, but to actually obtain the matrix L. (I'm trying to calculate "sigma points" as is done in the unscented transform.)
The library Eigen supposedly calculates Cholesky decompositions, but I can't figure out how to get it to give me the values in matrix L. When I attempt the following lines of code
Eigen::MatrixXd P(3,3);
P << 6, 0, 0, 0, 4, 0, 0, 0, 7;
std::cout << P.llt().matrixL().col(0) << std::endl;
I get compiler error
error: ‘Eigen::internal::LLT_Traits<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, 1>::MatrixL’ has no member named ‘col’
The documentation says that LLT.matrixL() returns type Traits::MatrixL. What is that and how do I get the values of L?
You can look up what the Trait is in the LLT.h header file. Its a TriangularView like the documentation says. The triangular view does not have a col
member, so that is why you get the error. Copying the triangular view into a dense matrix like so:
Eigen::MatrixXd P(3,3);
P << 6, 0, 0, 0, 4, 0, 0, 0, 7;
Eigen::MatrixXd L( P.llt().matrixL() );
std::cout << L.col(0) << std::endl;
will get you what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With