LU decomposition of a matrix with partial pivoting, and related features. More...
#include <PartialPivLU.h>
Public Types | |
enum | { RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, Options = MatrixType::Options, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime } |
typedef MatrixType::Index | Index |
typedef _MatrixType | MatrixType |
typedef PermutationMatrix < RowsAtCompileTime, MaxRowsAtCompileTime > | PermutationType |
typedef NumTraits< typename MatrixType::Scalar >::Real | RealScalar |
typedef MatrixType::Scalar | Scalar |
typedef internal::traits < MatrixType >::StorageKind | StorageKind |
typedef Transpositions < RowsAtCompileTime, MaxRowsAtCompileTime > | TranspositionType |
Public Member Functions | |
Index | cols () const |
PartialPivLU & | compute (const MatrixType &matrix) |
internal::traits< MatrixType > ::Scalar | determinant () const |
const internal::solve_retval < PartialPivLU, typename MatrixType::IdentityReturnType > | inverse () const |
const MatrixType & | matrixLU () const |
PartialPivLU () | |
Default Constructor. | |
PartialPivLU (Index size) | |
Default Constructor with memory preallocation. | |
PartialPivLU (const MatrixType &matrix) | |
const PermutationType & | permutationP () const |
MatrixType | reconstructedMatrix () const |
Index | rows () const |
template<typename Rhs > | |
const internal::solve_retval < PartialPivLU, Rhs > | solve (const MatrixBase< Rhs > &b) const |
Protected Attributes | |
Index | m_det_p |
bool | m_isInitialized |
MatrixType | m_lu |
PermutationType | m_p |
TranspositionType | m_rowsTranspositions |
LU decomposition of a matrix with partial 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 a square invertible matrix, with partial pivoting: the matrix A is decomposed as A = PLU where L is unit-lower-triangular, U is upper-triangular, and P is a permutation matrix.
Typically, partial pivoting LU decomposition is only considered numerically stable for square invertible matrices. Thus LAPACK's dgesv and dgesvx require the matrix to be square and invertible. The present class does the same. It will assert that the matrix is square, but it won't (actually it can't) check that the matrix is invertible: it is your task to check that you only use this decomposition on invertible matrices.
The guaranteed safe alternative, working for all matrices, is the full pivoting LU decomposition, provided by class FullPivLU.
This is not a rank-revealing LU decomposition. Many features are intentionally absent from this class, such as rank computation. If you need these features, use class FullPivLU.
This LU decomposition is suitable to invert invertible matrices. It is what MatrixBase::inverse() uses in the general case. On the other hand, it is not suitable to determine whether a given matrix is invertible.
The data of the LU decomposition can be directly accessed through the methods matrixLU(), permutationP().
Definition at line 60 of file PartialPivLU.h.
typedef MatrixType::Index PartialPivLU< _MatrixType >::Index |
Definition at line 75 of file PartialPivLU.h.
typedef _MatrixType PartialPivLU< _MatrixType >::MatrixType |
Definition at line 64 of file PartialPivLU.h.
typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PartialPivLU< _MatrixType >::PermutationType |
Definition at line 76 of file PartialPivLU.h.
typedef NumTraits<typename MatrixType::Scalar>::Real PartialPivLU< _MatrixType >::RealScalar |
Definition at line 73 of file PartialPivLU.h.
typedef MatrixType::Scalar PartialPivLU< _MatrixType >::Scalar |
Definition at line 72 of file PartialPivLU.h.
typedef internal::traits<MatrixType>::StorageKind PartialPivLU< _MatrixType >::StorageKind |
Definition at line 74 of file PartialPivLU.h.
typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> PartialPivLU< _MatrixType >::TranspositionType |
Definition at line 77 of file PartialPivLU.h.
anonymous enum |
Definition at line 65 of file PartialPivLU.h.
PartialPivLU< MatrixType >::PartialPivLU | ( | ) |
Default Constructor.
The default constructor is useful in cases in which the user intends to perform decompositions via PartialPivLU::compute(const MatrixType&).
Definition at line 195 of file PartialPivLU.h.
PartialPivLU< MatrixType >::PartialPivLU | ( | Index | size | ) |
Default Constructor with memory preallocation.
Like the default constructor but with preallocation of the internal data according to the specified problem size.
Definition at line 205 of file PartialPivLU.h.
PartialPivLU< MatrixType >::PartialPivLU | ( | const MatrixType & | matrix | ) |
Constructor.
matrix | the matrix of which to compute the LU decomposition. |
Definition at line 215 of file PartialPivLU.h.
Index PartialPivLU< _MatrixType >::cols | ( | void | ) | const [inline] |
Definition at line 184 of file PartialPivLU.h.
PartialPivLU< MatrixType > & PartialPivLU< MatrixType >::compute | ( | const MatrixType & | matrix | ) |
Definition at line 400 of file PartialPivLU.h.
internal::traits< MatrixType >::Scalar PartialPivLU< MatrixType >::determinant | ( | ) | const |
Definition at line 420 of file PartialPivLU.h.
const internal::solve_retval<PartialPivLU,typename MatrixType::IdentityReturnType> PartialPivLU< _MatrixType >::inverse | ( | void | ) | const [inline] |
Definition at line 159 of file PartialPivLU.h.
const MatrixType& PartialPivLU< _MatrixType >::matrixLU | ( | ) | const [inline] |
Definition at line 113 of file PartialPivLU.h.
const PermutationType& PartialPivLU< _MatrixType >::permutationP | ( | ) | const [inline] |
Definition at line 121 of file PartialPivLU.h.
MatrixType PartialPivLU< MatrixType >::reconstructedMatrix | ( | ) | const |
Definition at line 430 of file PartialPivLU.h.
Index PartialPivLU< _MatrixType >::rows | ( | void | ) | const [inline] |
Definition at line 183 of file PartialPivLU.h.
const internal::solve_retval<PartialPivLU, Rhs> PartialPivLU< _MatrixType >::solve | ( | const MatrixBase< Rhs > & | b | ) | const [inline] |
This method returns the solution x to the equation Ax=b, where A is the matrix of which *this is the LU decomposition.
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. |
Example:
MatrixXd A = MatrixXd::Random(3,3); MatrixXd B = MatrixXd::Random(3,2); cout << "Here is the invertible matrix A:" << endl << A << endl; cout << "Here is the matrix B:" << endl << B << endl; MatrixXd X = A.lu().solve(B); cout << "Here is the (unique) solution X to the equation AX=B:" << endl << X << endl; cout << "Relative error: " << (A*X-B).norm() / B.norm() << endl;
Output:
Since this PartialPivLU class assumes anyway that the matrix A is invertible, the solution theoretically exists and is unique regardless of b.
Definition at line 146 of file PartialPivLU.h.
Index PartialPivLU< _MatrixType >::m_det_p [protected] |
Definition at line 190 of file PartialPivLU.h.
bool PartialPivLU< _MatrixType >::m_isInitialized [protected] |
Definition at line 191 of file PartialPivLU.h.
MatrixType PartialPivLU< _MatrixType >::m_lu [protected] |
Definition at line 187 of file PartialPivLU.h.
PermutationType PartialPivLU< _MatrixType >::m_p [protected] |
Definition at line 188 of file PartialPivLU.h.
TranspositionType PartialPivLU< _MatrixType >::m_rowsTranspositions [protected] |
Definition at line 189 of file PartialPivLU.h.