The Parametric Pseudo-Manifold (PPS) Library 1.0
|
This class represents a linear system solver based on LU decomposition. More...
#include <ludcmp.h>
Public Member Functions | |
LUdcmp (double **mat, unsigned n) | |
Creates an instance of this class. | |
LUdcmp (const LUdcmp &lu) | |
Creates an instance of this class from another instance. | |
~LUdcmp () | |
Destroys an instance of this class. | |
void | solve (double *b, unsigned n) const |
Solves a linear system using LU decomposition. | |
Private Member Functions | |
double ** | allocate (unsigned n) const |
Allocates memory for a ( n x n ) matrix. | |
void | deallocate (double **mat, unsigned n) const |
Releases the memory held by a ( n x n ) matrix. | |
void | decomp () |
Carries out a LU decomposition of the matrix of stored in. | |
Private Attributes | |
double ** | _matA |
The coefficient matrix of the linear system. | |
unsigned | _nele |
The number of rows and columns of the matrix. | |
std::vector< unsigned > | _perm |
The permutation vector used by the LU decomposition algorithm. | |
int | _sign |
The sign flag used by the LU decomposition algorithm. |
This class represents a linear system solver based on LU decomposition.
pps::LUdcmp::LUdcmp | ( | double ** | mat, |
unsigned | n | ||
) |
Creates an instance of this class.
Creates an instance of this object.
mat | A ( n x n ) matrix. |
n | The number of rows and columns of matrix mat. |
Definition at line 63 of file ludcmp.cpp.
References _matA, _nele, _perm, _sign, allocate(), and decomp().
pps::LUdcmp::LUdcmp | ( | const LUdcmp & | lu | ) |
Creates an instance of this class from another instance.
lu | An instance of class LUdcmp. |
Definition at line 94 of file ludcmp.cpp.
References _matA, _nele, _perm, _sign, and allocate().
double ** pps::LUdcmp::allocate | ( | unsigned | n | ) | const [private] |
Allocates memory for a ( n x n ) matrix.
n | The number of rows and columns of the matrix. |
Definition at line 186 of file ludcmp.cpp.
Referenced by LUdcmp().
{ double** mat = (double **) new double*[n]; for ( unsigned i = 0 ; i < n ; i++ ) { mat[ i ] = ( double* ) new double[ n ] ; } return mat ; }
void pps::LUdcmp::deallocate | ( | double ** | mat, |
unsigned | n | ||
) | const [private] |
Releases the memory held by a ( n x n ) matrix.
mat | The address of the matrix. |
n | The number of rows and columns of the matrix. |
Definition at line 207 of file ludcmp.cpp.
Referenced by ~LUdcmp().
{ for ( unsigned i = 0 ; i < n ; i++ ) { delete[] mat[ i ] ; } delete mat ; return ; }
void pps::LUdcmp::solve | ( | double * | b, |
unsigned | n | ||
) | const |
Solves a linear system using LU decomposition.
b | The column (and solution) vector. |
n | The number of elements of the vector |
Definition at line 136 of file ludcmp.cpp.
References _matA, _nele, and _perm.
Referenced by pps::Bezier::Bezier().
{ assert( n == _nele ) ; int i, ii = 0, ip, j; double sum; for ( i = 0 ; i < (int) n ; i++ ) { ip = _perm[ i ] ; sum = b[ ip ] ; b[ ip ] = b[ i ] ; if ( ii != 0 ) { for ( j = ii - 1 ; j < i ; j++ ) { sum -= _matA[ i ][ j ] * b[ j ] ; } } else if ( sum != 0.0 ) { ii = i + 1 ; } b[ i ] = sum ; } for ( i = n - 1 ; i >= 0 ; i-- ) { sum = b[ i ] ; for ( j = i + 1 ; j < (int) n ; j++ ) { sum -= _matA[ i ][ j ] * b[ j ] ; } b[ i ] = sum / _matA[ i ][ i ] ; } return ; }