LU decomposition of a matrix with complete pivoting, and related features. More...
#include <LU.h>
Public Types | |
enum | { MaxSmallDimAtCompileTime } |
typedef Matrix< Scalar, MatrixType::RowsAtCompileTime, 1, MatrixType::Options, MatrixType::MaxRowsAtCompileTime, 1 > | ColVectorType |
typedef Matrix< typename MatrixType::Scalar, MatrixType::RowsAtCompileTime, Dynamic, MatrixType::Options, MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime > | ImageResultType |
typedef Matrix< int, MatrixType::RowsAtCompileTime, 1, MatrixType::Options, MatrixType::MaxRowsAtCompileTime, 1 > | IntColVectorType |
typedef Matrix< int, 1, MatrixType::ColsAtCompileTime, MatrixType::Options, 1, MatrixType::MaxColsAtCompileTime > | IntRowVectorType |
typedef Matrix< typename MatrixType::Scalar, MatrixType::ColsAtCompileTime, Dynamic, MatrixType::Options, MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime > | KernelResultType |
typedef NumTraits< typename MatrixType::Scalar >::Real | RealScalar |
typedef Matrix< Scalar, 1, MatrixType::ColsAtCompileTime, MatrixType::Options, 1, MatrixType::MaxColsAtCompileTime > | RowVectorType |
typedef MatrixType::Scalar | Scalar |
Public Member Functions | |
template<typename ImageMatrixType > | |
void | computeImage (ImageMatrixType *result) const |
template<typename ResultType > | |
void | computeInverse (ResultType *result) const |
template<typename KernelMatrixType > | |
void | computeKernel (KernelMatrixType *result) const |
ei_traits< MatrixType >::Scalar | determinant () const |
int | dimensionOfKernel () const |
const ImageResultType | image () const |
MatrixType | inverse () const |
bool | isInjective () const |
bool | isInvertible () const |
bool | isSurjective () const |
const KernelResultType | kernel () const |
LU (const MatrixType &matrix) | |
const MatrixType & | matrixLU () const |
const IntColVectorType & | permutationP () const |
const IntRowVectorType & | permutationQ () const |
int | rank () const |
template<typename OtherDerived , typename ResultType > | |
bool | solve (const MatrixBase< OtherDerived > &b, ResultType *result) const |
Protected Attributes | |
int | m_det_pq |
MatrixType | m_lu |
const MatrixType & | m_originalMatrix |
IntColVectorType | m_p |
RealScalar | m_precision |
IntRowVectorType | m_q |
int | m_rank |
LU decomposition of a matrix with complete pivoting, and related features.
MatrixType | the type of the matrix of which we are computing the LU decomposition |
This class represents a LU decomposition of any matrix, with complete pivoting: the matrix A is decomposed as A = PLUQ where L is unit-lower-triangular, U is upper-triangular, and P and Q are permutation matrices. This is a rank-revealing LU decomposition. The eigenvalues (diagonal coefficients) of U are sorted in such a way that any zeros are at the end, so that the rank of A is the index of the first zero on the diagonal of U (with indices starting at 0) if any.
This decomposition provides the generic approach to solving systems of linear equations, computing the rank, invertibility, inverse, kernel, and determinant.
This LU decomposition is very stable and well tested with large matrices. Even exact rank computation works at sizes larger than 1000x1000. However there are use cases where the SVD decomposition is inherently more stable when dealing with numerically damaged input. For example, computing the kernel is more stable with SVD because the SVD can determine which singular values are negligible while LU has to work at the level of matrix coefficients that are less meaningful in this respect.
The data of the LU decomposition can be directly accessed through the methods matrixLU(), permutationP(), permutationQ().
As an exemple, here is how the original matrix can be retrieved:
Output:
Definition at line 60 of file LU.h.
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1, MatrixType::Options, MatrixType::MaxRowsAtCompileTime, 1> LU< MatrixType >::ColVectorType |
typedef Matrix<typename MatrixType::Scalar, MatrixType::RowsAtCompileTime, Dynamic, MatrixType::Options, MatrixType::MaxRowsAtCompileTime, MatrixType::MaxColsAtCompileTime > LU< MatrixType >::ImageResultType |
typedef Matrix<int, MatrixType::RowsAtCompileTime, 1, MatrixType::Options, MatrixType::MaxRowsAtCompileTime, 1> LU< MatrixType >::IntColVectorType |
typedef Matrix<int, 1, MatrixType::ColsAtCompileTime, MatrixType::Options, 1, MatrixType::MaxColsAtCompileTime> LU< MatrixType >::IntRowVectorType |
typedef Matrix<typename MatrixType::Scalar, MatrixType::ColsAtCompileTime, Dynamic, MatrixType::Options, MatrixType::MaxColsAtCompileTime, MatrixType::MaxColsAtCompileTime > LU< MatrixType >::KernelResultType |
typedef NumTraits<typename MatrixType::Scalar>::Real LU< MatrixType >::RealScalar |
typedef Matrix<Scalar, 1, MatrixType::ColsAtCompileTime, MatrixType::Options, 1, MatrixType::MaxColsAtCompileTime> LU< MatrixType >::RowVectorType |
anonymous enum |
void LU< MatrixType >::computeImage | ( | ImageMatrixType * | result | ) | const [inline] |
Computes a basis of the image of the matrix, also called the column-space or range of he matrix.
result | a pointer to the matrix in which to store the image. The columns of this matrix will be set to form a basis of the image (it will be resized if necessary). |
Example:
Output:
void LU< MatrixType >::computeInverse | ( | ResultType * | result | ) | const [inline] |
Computes the inverse of the matrix of which *this is the LU decomposition.
result | a pointer to the matrix into which to store the inverse. Resized if needed. |
void LU< MatrixType >::computeKernel | ( | KernelMatrixType * | result | ) | const [inline] |
Computes a basis of the kernel of the matrix, also called the null-space of the matrix.
result | a pointer to the matrix in which to store the kernel. The columns of this matrix will be set to form a basis of the kernel (it will be resized if necessary). |
Example:
Output:
ei_traits< MatrixType >::Scalar LU< MatrixType >::determinant | ( | ) | const [inline] |
int LU< MatrixType >::dimensionOfKernel | ( | ) | const [inline] |
const LU< MatrixType >::ImageResultType LU< MatrixType >::image | ( | ) | const [inline] |
Example:
Output:
MatrixType LU< MatrixType >::inverse | ( | void | ) | const [inline] |
bool LU< MatrixType >::isInjective | ( | ) | const [inline] |
bool LU< MatrixType >::isInvertible | ( | ) | const [inline] |
bool LU< MatrixType >::isSurjective | ( | ) | const [inline] |
const LU< MatrixType >::KernelResultType LU< MatrixType >::kernel | ( | ) | const [inline] |
Example:
Output:
const MatrixType& LU< MatrixType >::matrixLU | ( | ) | const [inline] |
const IntColVectorType& LU< MatrixType >::permutationP | ( | ) | const [inline] |
const IntRowVectorType& LU< MatrixType >::permutationQ | ( | ) | const [inline] |
int LU< MatrixType >::rank | ( | ) | const [inline] |
bool LU< MatrixType >::solve | ( | const MatrixBase< OtherDerived > & | b, | |
ResultType * | result | |||
) | const [inline] |
This method finds a solution x to the equation Ax=b, where A is the matrix of which *this is the LU decomposition, if any exists.
b | the right-hand-side of the equation to solve. Can be a vector or a matrix, the only requirement in order for the equation to make sense is that b.rows()==A.rows(), where A is the matrix of which *this is the LU decomposition. | |
result | a pointer to the vector or matrix in which to store the solution, if any exists. Resized if necessary, so that result->rows()==A.cols() and result->cols()==b.cols(). If no solution exists, *result is left with undefined coefficients. |
Example:
Output:
const MatrixType& LU< MatrixType >::m_originalMatrix [protected] |
IntColVectorType LU< MatrixType >::m_p [protected] |
RealScalar LU< MatrixType >::m_precision [protected] |
IntRowVectorType LU< MatrixType >::m_q [protected] |