 Eigen  3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae) Eigen::LLT< MatrixType_, UpLo_ > Class Template Reference

## Detailed Description

### template<typename MatrixType_, int UpLo_> class Eigen::LLT< MatrixType_, UpLo_ >

Standard Cholesky decomposition (LL^T) of a matrix and associated features.

Template Parameters
 MatrixType_ the type of the matrix of which we are computing the LL^T Cholesky decomposition UpLo_ the triangular part that will be used for the decomposition: Lower (default) or Upper. The other triangular part won't be read.

This class performs a LL^T Cholesky decomposition of a symmetric, positive definite matrix A such that A = LL^* = U^*U, where L is lower triangular.

While the Cholesky decomposition is particularly useful to solve selfadjoint problems like D^*D x = b, for that purpose, we recommend the Cholesky decomposition without square root which is more stable and even faster. Nevertheless, this standard Cholesky decomposition remains useful in many other situations like generalised eigen problems with hermitian matrices.

Remember that Cholesky decompositions are not rank-revealing. This LLT decomposition is only stable on positive definite matrices, use LDLT instead for the semidefinite case. Also, do not use a Cholesky decomposition to determine whether a system of equations has a solution.

Example:

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;
Matrix< double, Dynamic, Dynamic > MatrixXd
Dynamic×Dynamic matrix of type double.
Definition: Matrix.h:501

Output:

The matrix A is
4 -1  2
-1  6  0
2  0  5
The Cholesky factor L is
2     0     0
-0.5   2.4     0
1 0.209  1.99
To check this, let us compute L * L.transpose()
4 -1  2
-1  6  0
2  0  5
This should equal the matrix A


Performance: for best performance, it is recommended to use a column-major storage format with the Lower triangular part (the default), or, equivalently, a row-major storage format with the Upper triangular part. Otherwise, you might get a 20% slowdown for the full factorization step, and rank-updates can be up to 3 times slower.

This class supports the inplace decomposition mechanism.

Note that during the decomposition, only the lower (or upper, as defined by UpLo_) triangular part of A is considered. Therefore, the strict lower part does not have to store correct values. Inheritance diagram for Eigen::LLT< MatrixType_, UpLo_ >:

## Public Member Functions

template<typename InputType >
LLT< MatrixType, UpLo_ > & compute (const EigenBase< InputType > &a)

ComputationInfo info () const
Reports whether previous computation was successful. More...

LLT ()
Default Constructor. More...

template<typename InputType >
LLT (EigenBase< InputType > &matrix)
Constructs a LLT factorization from a given matrix. More...

LLT (Index size)
Default Constructor with memory preallocation. More...

Traits::MatrixL matrixL () const

const MatrixType & matrixLLT () const

Traits::MatrixU matrixU () const

template<typename VectorType >
LLT< MatrixType_, UpLo_ > & rankUpdate (const VectorType &v, const RealScalar &sigma)

RealScalar rcond () const

MatrixType reconstructedMatrix () const

template<typename Rhs >
const Solve< LLT, Rhs > solve (const MatrixBase< Rhs > &b) const Public Member Functions inherited from Eigen::SolverBase< LLT< MatrixType_, UpLo_ > >

LLT< MatrixType_, UpLo_ > & derived ()

const LLT< MatrixType_, UpLo_ > & derived () const

const Solve< LLT< MatrixType_, UpLo_ >, Rhs > solve (const MatrixBase< Rhs > &b) const

SolverBase ()

const ConstTransposeReturnType transpose () const Public Member Functions inherited from Eigen::EigenBase< Derived >
EIGEN_CONSTEXPR Index cols () const EIGEN_NOEXCEPT

Derived & derived ()

const Derived & derived () const

EIGEN_CONSTEXPR Index rows () const EIGEN_NOEXCEPT

EIGEN_CONSTEXPR Index size () const EIGEN_NOEXCEPT Public Types inherited from Eigen::EigenBase< Derived >
typedef Eigen::Index Index
The interface type of indices. More...

## ◆ LLT() [1/3]

template<typename MatrixType_ , int UpLo_>
 Eigen::LLT< MatrixType_, UpLo_ >::LLT ( )
inline

Default Constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via LLT::compute(const MatrixType&).

## ◆ LLT() [2/3]

template<typename MatrixType_ , int UpLo_>
 Eigen::LLT< MatrixType_, UpLo_ >::LLT ( Index size )
inlineexplicit

Default Constructor with memory preallocation.

Like the default constructor but with preallocation of the internal data according to the specified problem size.

LLT()

## ◆ LLT() [3/3]

template<typename MatrixType_ , int UpLo_>
template<typename InputType >
 Eigen::LLT< MatrixType_, UpLo_ >::LLT ( EigenBase< InputType > & matrix )
inlineexplicit

Constructs a LLT factorization from a given matrix.

This overloaded constructor is provided for inplace decomposition when MatrixType is a Eigen::Ref.

LLT(const EigenBase&)

## Member Function Documentation

template<typename MatrixType_ , int UpLo_>
 const LLT& Eigen::LLT< MatrixType_, UpLo_ >::adjoint ( ) const
inline
Returns
the adjoint of *this, that is, a const reference to the decomposition itself as the underlying matrix is self-adjoint.

This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as:

## ◆ compute()

template<typename MatrixType_ , int UpLo_>
template<typename InputType >
 LLT& Eigen::LLT< MatrixType_, UpLo_ >::compute ( const EigenBase< InputType > & a )

Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of matrix

Returns
a reference to *this

Example:

#include <iostream>
#include <Eigen/Dense>
int main()
{
A << 2, -1, -1, 3;
b << 1, 2, 3, 1;
std::cout << "Here is the matrix A:\n" << A << std::endl;
std::cout << "Here is the right hand side b:\n" << b << std::endl;
std::cout << "Computing LLT decomposition..." << std::endl;
llt.compute(A);
std::cout << "The solution is:\n" << llt.solve(b) << std::endl;
A(1,1)++;
std::cout << "The matrix A is now:\n" << A << std::endl;
std::cout << "Computing LLT decomposition..." << std::endl;
llt.compute(A);
std::cout << "The solution is now:\n" << llt.solve(b) << std::endl;
}
Standard Cholesky decomposition (LL^T) of a matrix and associated features.
Definition: LLT.h:70
const Solve< LLT, Rhs > solve(const MatrixBase< Rhs > &b) const
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182

Output:

Here is the matrix A:
2 -1
-1  3
Here is the right hand side b:
1 2
3 1
Computing LLT decomposition...
The solution is:
1.2 1.4
1.4 0.8
The matrix A is now:
2 -1
-1  4
Computing LLT decomposition...
The solution is now:
1  1.29
1 0.571


## ◆ info()

template<typename MatrixType_ , int UpLo_>
 ComputationInfo Eigen::LLT< MatrixType_, UpLo_ >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was successful, NumericalIssue if the matrix.appears not to be positive definite.

## ◆ matrixL()

template<typename MatrixType_ , int UpLo_>
 Traits::MatrixL Eigen::LLT< MatrixType_, UpLo_ >::matrixL ( ) const
inline
Returns
a view of the lower triangular matrix L

## ◆ matrixLLT()

template<typename MatrixType_ , int UpLo_>
 const MatrixType& Eigen::LLT< MatrixType_, UpLo_ >::matrixLLT ( ) const
inline
Returns
the LLT decomposition matrix

TODO: document the storage layout

## ◆ matrixU()

template<typename MatrixType_ , int UpLo_>
 Traits::MatrixU Eigen::LLT< MatrixType_, UpLo_ >::matrixU ( ) const
inline
Returns
a view of the upper triangular matrix U

## ◆ rankUpdate()

template<typename MatrixType_ , int UpLo_>
template<typename VectorType >
 LLT& Eigen::LLT< MatrixType_, UpLo_ >::rankUpdate ( const VectorType & v, const RealScalar & sigma )

Performs a rank one update (or dowdate) of the current decomposition. If A = LL^* before the rank one update, then after it we have LL^* = A + sigma * v v^* where v must be a vector of same dimension.

## ◆ rcond()

template<typename MatrixType_ , int UpLo_>
 RealScalar Eigen::LLT< MatrixType_, UpLo_ >::rcond ( ) const
inline
Returns
an estimate of the reciprocal condition number of the matrix of which *this is the Cholesky decomposition.

## ◆ reconstructedMatrix()

template<typename MatrixType , int UpLo_>
 MatrixType Eigen::LLT< MatrixType, UpLo_ >::reconstructedMatrix
Returns
the matrix represented by the decomposition, i.e., it returns the product: L L^*. This function is provided for debug purpose.

## ◆ solve()

template<typename MatrixType_ , int UpLo_>
template<typename Rhs >
 const Solve Eigen::LLT< MatrixType_, UpLo_ >::solve ( const MatrixBase< Rhs > & b ) const
inline
Returns
the solution x of $$A x = b$$ using the current decomposition of A.

Since this LLT class assumes anyway that the matrix A is invertible, the solution theoretically exists and is unique regardless of b.

Example:

typedef Matrix<float,Dynamic,2> DataMatrix;
// let's generate some samples on the 3D plane of equation z = 2x+3y (with some noise)
DataMatrix samples = DataMatrix::Random(12,2);
VectorXf elevations = 2*samples.col(0) + 3*samples.col(1) + VectorXf::Random(12)*0.1;
// and let's solve samples * [x y]^T = elevations in least square sense:
Matrix<float,2,1> xy
cout << xy << endl;
static const RandomReturnType Random()
Definition: Random.h:114
Matrix< float, Dynamic, 1 > VectorXf
Dynamic×1 vector of type float.
Definition: Matrix.h:500

Output:

2.02
2.97