TooN::LU< Size, Precision > Class Template Reference
[Matrix decompositions]

Performs LU decomposition and back substitutes to solve equations. More...

#include <LU.h>

List of all members.

Public Member Functions

template<int S1, int S2, class Base>
 LU (const Matrix< S1, S2, Precision, Base > &m)
template<int S1, int S2, class Base>
void compute (const Matrix< S1, S2, Precision, Base > &m)
template<int Rows, int NRHS, class Base>
Matrix< Size, NRHS,
Precision > 
backsub (const Matrix< Rows, NRHS, Precision, Base > &rhs)
template<int Rows, class Base>
Vector< Size, Precision > backsub (const Vector< Rows, Precision, Base > &rhs)
Matrix< Size, Size,
Precision > 
get_inverse ()
const Matrix< Size,
Size, Precision > & 
get_lu () const
int get_sign () const
Precision determinant () const
int get_info () const


Detailed Description

template<int Size = -1, class Precision = double>
class TooN::LU< Size, Precision >

Performs LU decomposition and back substitutes to solve equations.

The LU decomposition is the fastest way of solving the equation $M\underline{x} = \underline{c}$m, but it becomes unstable when $M$ is (nearly) singular (in which cases the SymEigen or SVD decompositions are better). It decomposes a matrix $M$ into

\[M = L \times U\]

where $L$ is a lower-diagonal matrix with unit diagonal and $U$ is an upper-diagonal matrix. The library only supports the decomposition of square matrices. It can be used as follows to solve the $M\underline{x} = \underline{c}$ problem as follows:

// construct M
double d1[][] = {{1,2,3},{4,5,6},{7,8,10}};
Matrix<3> M(d1);
// construct c
Vector<3> c = 2,3,4;
// create the LU decomposition of M
LU<3> luM(M);
// compute x = M^-1 * c
Vector<3> x = luM.backsub(c);
The convention LU<> (=LU<-1>) is used to create an LU decomposition whose size is determined at runtime.

Constructor & Destructor Documentation

template<int Size = -1, class Precision = double>
template<int S1, int S2, class Base>
TooN::LU< Size, Precision >::LU ( const Matrix< S1, S2, Precision, Base > &  m  ) 

Construct the LU decomposition of a matrix.

This initialises the class, and performs the decomposition immediately.


Member Function Documentation

template<int Size = -1, class Precision = double>
template<int S1, int S2, class Base>
void TooN::LU< Size, Precision >::compute ( const Matrix< S1, S2, Precision, Base > &  m  ) 

Perform the LU decompsition of another matrix.

template<int Size = -1, class Precision = double>
template<int Rows, int NRHS, class Base>
Matrix<Size,NRHS,Precision> TooN::LU< Size, Precision >::backsub ( const Matrix< Rows, NRHS, Precision, Base > &  rhs  ) 

Calculate result of multiplying the inverse of M by another matrix.

For a matrix $A$, this calculates $M^{-1}A$ by back substitution (i.e. without explictly calculating the inverse).

template<int Size = -1, class Precision = double>
template<int Rows, class Base>
Vector<Size,Precision> TooN::LU< Size, Precision >::backsub ( const Vector< Rows, Precision, Base > &  rhs  ) 

Calculate result of multiplying the inverse of M by a vector.

For a vector $b$, this calculates $M^{-1}b$ by back substitution (i.e. without explictly calculating the inverse).

template<int Size = -1, class Precision = double>
Matrix<Size,Size,Precision> TooN::LU< Size, Precision >::get_inverse (  ) 

Calculate inverse of the matrix.

This is not usually needed: if you need the inverse just to multiply it by a matrix or a vector, use one of the backsub() functions, which will be faster.

template<int Size = -1, class Precision = double>
const Matrix<Size,Size,Precision>& TooN::LU< Size, Precision >::get_lu (  )  const

Returns the L and U matrices.

The permutation matrix is not returned. Since L is lower-triangular (with unit diagonal) and U is upper-triangular, these are returned conflated into one matrix, where the diagonal and above parts of the matrix are U and the below-diagonal part, plus a unit diagonal, are L.

template<int Size = -1, class Precision = double>
Precision TooN::LU< Size, Precision >::determinant (  )  const

Calculate the determinant of the matrix.

template<int Size = -1, class Precision = double>
int TooN::LU< Size, Precision >::get_info (  )  const

Get the LAPACK info.


Generated on Thu May 7 20:28:41 2009 for TooN by  doxygen 1.5.3