mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Add simple example on how to compute Cholesky decomposition.
This commit is contained in:
@@ -144,6 +144,9 @@ You need an eigendecomposition here, see available such decompositions on \ref T
|
||||
Make sure to check if your matrix is self-adjoint, as is often the case in these problems. Here's an example using
|
||||
SelfAdjointEigenSolver, it could easily be adapted to general matrices using EigenSolver or ComplexEigenSolver.
|
||||
|
||||
The computation of eigenvalues and eigenvectors does not necessarily converge, but such failure to converge is
|
||||
very rare. The call to info() is to check for this possibility.
|
||||
|
||||
<table class="example">
|
||||
<tr><th>Example:</th><th>Output:</th></tr>
|
||||
<tr>
|
||||
|
||||
12
doc/snippets/LLT_example.cpp
Normal file
12
doc/snippets/LLT_example.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
MatrixXd A(3,3);
|
||||
A << 4,-1,2, -1,6,0, 2,0,5;
|
||||
cout << "The matrix A is" << endl << A << endl;
|
||||
|
||||
LLT<MatrixXd> lltOfA(A); // compute the Cholesky decomposition of A
|
||||
MatrixXd L = lltOfA.matrixL(); // retrieve factor L in the decomposition
|
||||
// The previous two lines can also be written as "L = A.llt().matrixL()"
|
||||
|
||||
cout << "The Cholesky factor L is" << endl << L << endl;
|
||||
cout << "To check this, let us compute L * L.transpose()" << endl;
|
||||
cout << L * L.transpose() << endl;
|
||||
cout << "This should equal the matrix A" << endl;
|
||||
Reference in New Issue
Block a user