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 36 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 161 of file LUDecomposition.h.

References bpp::LUDecomposition< Real >::LU, bpp::LUDecomposition< Real >::m, bpp::LUDecomposition< Real >::n, 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 279 of file LUDecomposition.h.

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

◆ 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 268 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 244 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

Definition at line 48 of file LUDecomposition.h.

References bpp::Matrix< Scalar >::resize().

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

◆ 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 63 of file LUDecomposition.h.

◆ 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 304 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(), and bpp::NumConstants::SMALL().

◆ 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 378 of file LUDecomposition.h.

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

Member Data Documentation

◆ L_

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

Definition at line 41 of file LUDecomposition.h.

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

◆ LU

◆ m

◆ n

◆ piv

template<class Real >
std::vector<size_t> bpp::LUDecomposition< Real >::piv
private

Definition at line 45 of file LUDecomposition.h.

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

◆ pivsign

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

Definition at line 44 of file LUDecomposition.h.

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

◆ U_

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

Definition at line 42 of file LUDecomposition.h.

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


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