diff options
author | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2011-11-07 17:14:06 +0000 |
---|---|---|
committer | Jitse Niesen <jitse@maths.leeds.ac.uk> | 2011-11-07 17:14:06 +0000 |
commit | 45a6bb34c3e67c865b489518767eadf747d391d7 (patch) | |
tree | 2a27bfd03741e4e261fe6244740ffc7034fd37a1 /doc | |
parent | f422668d39c51a7281e55404cfed4a262747eb51 (diff) |
Add simple example on how to compute Cholesky decomposition.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/C06_TutorialLinearAlgebra.dox | 3 | ||||
-rw-r--r-- | doc/snippets/LLT_example.cpp | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/doc/C06_TutorialLinearAlgebra.dox b/doc/C06_TutorialLinearAlgebra.dox index 77f13f4a0..e8b3b7953 100644 --- a/doc/C06_TutorialLinearAlgebra.dox +++ b/doc/C06_TutorialLinearAlgebra.dox @@ -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> diff --git a/doc/snippets/LLT_example.cpp b/doc/snippets/LLT_example.cpp new file mode 100644 index 000000000..46fb40704 --- /dev/null +++ b/doc/snippets/LLT_example.cpp @@ -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; |