Add simple example on how to compute Cholesky decomposition.

This commit is contained in:
Jitse Niesen 2011-11-07 17:14:06 +00:00
parent f422668d39
commit 45a6bb34c3
4 changed files with 23 additions and 3 deletions

View File

@ -31,7 +31,7 @@ namespace internal {
template<typename MatrixType, int UpLo> struct LDLT_Traits; template<typename MatrixType, int UpLo> struct LDLT_Traits;
} }
/** \ingroup cholesky_Module /** \ingroup Cholesky_Module
* *
* \class LDLT * \class LDLT
* *

View File

@ -29,7 +29,7 @@ namespace internal{
template<typename MatrixType, int UpLo> struct LLT_Traits; template<typename MatrixType, int UpLo> struct LLT_Traits;
} }
/** \ingroup cholesky_Module /** \ingroup Cholesky_Module
* *
* \class LLT * \class LLT
* *
@ -49,6 +49,9 @@ template<typename MatrixType, int UpLo> struct LLT_Traits;
* use LDLT instead for the semidefinite case. Also, do not use a Cholesky decomposition to determine whether a system of equations * use LDLT instead for the semidefinite case. Also, do not use a Cholesky decomposition to determine whether a system of equations
* has a solution. * has a solution.
* *
* Example: \include LLT_example.cpp
* Output: \verbinclude LLT_example.out
*
* \sa MatrixBase::llt(), class LDLT * \sa MatrixBase::llt(), class LDLT
*/ */
/* HEY THIS DOX IS DISABLED BECAUSE THERE's A BUG EITHER HERE OR IN LDLT ABOUT THAT (OR BOTH) /* HEY THIS DOX IS DISABLED BECAUSE THERE's A BUG EITHER HERE OR IN LDLT ABOUT THAT (OR BOTH)
@ -333,9 +336,11 @@ template<typename MatrixType> struct LLT_Traits<MatrixType,Upper>
} // end namespace internal } // end namespace internal
/** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix /** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix
*
* *
* \returns a reference to *this * \returns a reference to *this
*
* Example: \include TutorialLinAlgComputeTwice.cpp
* Output: \verbinclude TutorialLinAlgComputeTwice.out
*/ */
template<typename MatrixType, int _UpLo> template<typename MatrixType, int _UpLo>
LLT<MatrixType,_UpLo>& LLT<MatrixType,_UpLo>::compute(const MatrixType& a) LLT<MatrixType,_UpLo>& LLT<MatrixType,_UpLo>::compute(const MatrixType& a)

View File

@ -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 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. 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"> <table class="example">
<tr><th>Example:</th><th>Output:</th></tr> <tr><th>Example:</th><th>Output:</th></tr>
<tr> <tr>

View 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;