bpp-core3  3.0.0
bpp::LUDecomposition< Real > Class Template Reference

LU Decomposition. More...

#include <Bpp/Numeric/Matrix/LUDecomposition.h>

+ Collaboration diagram for bpp::LUDecomposition< Real >:

Public Member Functions

 LUDecomposition (const Matrix< Real > &A)
 LU Decomposition. More...
 
const RowMatrix< Real > & getL ()
 Return lower triangular factor. More...
 
const RowMatrix< Real > & getU ()
 Return upper triangular factor. More...
 
std::vector< size_t > getPivot () const
 Return pivot permutation vector. More...
 
Real det () const
 Compute determinant using LU factors. More...
 
Real solve (const Matrix< Real > &B, Matrix< Real > &X) const
 Solve A*X = B. More...
 
Real solve (const std::vector< Real > &b, std::vector< Real > &x) const
 Solve A*x = b, where x and b are vectors of length equal to the number of rows in A. More...
 

Static Private Member Functions

static void permuteCopy (const Matrix< Real > &A, const std::vector< size_t > &piv, size_t j0, size_t j1, Matrix< Real > &X)
 
static void permuteCopy (const std::vector< Real > &A, const std::vector< size_t > &piv, std::vector< Real > &X)
 

Private Attributes

RowMatrix< Real > LU
 
RowMatrix< Real > L_
 
RowMatrix< Real > U_
 
size_t m
 
size_t n
 
int pivsign
 
std::vector< size_t > piv
 

Detailed Description

template<class Real>
class bpp::LUDecomposition< Real >

LU Decomposition.

[This class and its documentation is adpated from the C++ port of the JAMA library.]

For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n unit lower triangular matrix L, an n-by-n upper triangular matrix U, and a permutation vector piv of length m so that A(piv,:) = L*U. If m < n, then L is m-by-m and U is m-by-n.

The LU decompostion with pivoting always exists, even if the matrix is singular, so the constructor will never fail. The primary use of the LU decomposition is in the solution of square systems of simultaneous linear equations. This will fail if isNonsingular() returns false.

Definition at line 72 of file LUDecomposition.h.

Constructor & Destructor Documentation

◆ LUDecomposition()

template<class Real >
bpp::LUDecomposition< Real >::LUDecomposition ( const Matrix< Real > &  A)
inline

LU Decomposition.

Parameters
ARectangular matrix
Returns
LU Decomposition object to access L, U and piv.

Definition at line 197 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::LU, bpp::LUDecomposition< Real >::m, bpp::LUDecomposition< Real >::n, bpp::LUDecomposition< Real >::piv, and bpp::LUDecomposition< Real >::pivsign.

Member Function Documentation

◆ det()

template<class Real >
Real bpp::LUDecomposition< Real >::det ( ) const
inline

Compute determinant using LU factors.

Returns
determinant of A, or 0 if A is not square.

Definition at line 315 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::LU, bpp::LUDecomposition< Real >::m, bpp::LUDecomposition< Real >::n, and bpp::LUDecomposition< Real >::pivsign.

Referenced by bpp::MatrixTools::det().

◆ getL()

template<class Real >
const RowMatrix<Real>& bpp::LUDecomposition< Real >::getL ( )
inline

◆ getPivot()

template<class Real >
std::vector<size_t> bpp::LUDecomposition< Real >::getPivot ( ) const
inline

Return pivot permutation vector.

Returns
piv

Definition at line 304 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::piv.

◆ getU()

template<class Real >
const RowMatrix<Real>& bpp::LUDecomposition< Real >::getU ( )
inline

Return upper triangular factor.

Returns
U portion of LU factorization.

Definition at line 280 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::LU, bpp::LUDecomposition< Real >::n, and bpp::LUDecomposition< Real >::U_.

◆ permuteCopy() [1/2]

template<class Real >
static void bpp::LUDecomposition< Real >::permuteCopy ( const Matrix< Real > &  A,
const std::vector< size_t > &  piv,
size_t  j0,
size_t  j1,
Matrix< Real > &  X 
)
inlinestaticprivate

◆ permuteCopy() [2/2]

template<class Real >
static void bpp::LUDecomposition< Real >::permuteCopy ( const std::vector< Real > &  A,
const std::vector< size_t > &  piv,
std::vector< Real > &  X 
)
inlinestaticprivate

Definition at line 99 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::piv.

◆ solve() [1/2]

template<class Real >
Real bpp::LUDecomposition< Real >::solve ( const Matrix< Real > &  B,
Matrix< Real > &  X 
) const
inline

Solve A*X = B.

Parameters
B[in] A Matrix with as many rows as A and any number of columns.
X[out] A RowMatrix that will be changed such that L*U*X = B(piv,:).
Returns
the lowest diagonal term (in absolute value), for further checkings of non-singularity of LU.

If B is nonconformant or LU is singular, an Exception is raised.

Definition at line 340 of file LUDecomposition.h.

References bpp::Matrix< Scalar >::getNumberOfColumns(), bpp::Matrix< Scalar >::getNumberOfRows(), bpp::LUDecomposition< Real >::LU, bpp::LUDecomposition< Real >::m, bpp::LUDecomposition< Real >::n, bpp::LUDecomposition< Real >::permuteCopy(), bpp::LUDecomposition< Real >::piv, and bpp::NumConstants::SMALL().

Referenced by bpp::MatrixTools::inv().

◆ solve() [2/2]

template<class Real >
Real bpp::LUDecomposition< Real >::solve ( const std::vector< Real > &  b,
std::vector< Real > &  x 
) const
inline

Solve A*x = b, where x and b are vectors of length equal to the number of rows in A.

Parameters
b[in] a vector (Array1D> of length equal to the first dimension of A.
x[out] a vector that will be changed so that so that L*U*x = b(piv).
Returns
the lowest diagonal term (in absolute value), for further checkings of non-singularity of LU.

If B is nonconformant or LU is singular, an Exception is raised.

Definition at line 414 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::LU, bpp::LUDecomposition< Real >::m, bpp::LUDecomposition< Real >::n, bpp::LUDecomposition< Real >::permuteCopy(), bpp::LUDecomposition< Real >::piv, and bpp::NumConstants::SMALL().

Member Data Documentation

◆ L_

template<class Real >
RowMatrix<Real> bpp::LUDecomposition< Real >::L_
private

Definition at line 77 of file LUDecomposition.h.

Referenced by bpp::LUDecomposition< Real >::getL().

◆ LU

◆ m

◆ n

◆ piv

◆ pivsign

template<class Real >
int bpp::LUDecomposition< Real >::pivsign
private

◆ U_

template<class Real >
RowMatrix<Real> bpp::LUDecomposition< Real >::U_
private

Definition at line 78 of file LUDecomposition.h.

Referenced by bpp::LUDecomposition< Real >::getU().


The documentation for this class was generated from the following file: