The Parametric Pseudo-Manifold (PPS) Library 1.0
pps::LUdcmp Class Reference

This class represents a linear system solver based on LU decomposition. More...

#include <ludcmp.h>

List of all members.

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.

Detailed Description

This class represents a linear system solver based on LU decomposition.

Definition at line 62 of file ludcmp.h.


Constructor & Destructor Documentation

pps::LUdcmp::LUdcmp ( double **  mat,
unsigned  n 
)

Creates an instance of this class.

Creates an instance of this object.

Parameters:
matA ( n x n ) matrix.
nThe number of rows and columns of matrix mat.

Definition at line 63 of file ludcmp.cpp.

References _matA, _nele, _perm, _sign, allocate(), and decomp().

  {
    _nele = n;
    _matA = allocate( _nele ) ;

    for ( unsigned i = 0 ; i < _nele ; i++ ) {
      for ( unsigned j = 0 ; j < _nele ; j++ ) {
        _matA[ i ][ j ] = mat[ i ][ j ] ;       
      }
    }

    _perm.resize( _nele ) ;
    _sign = 1 ;

    decomp() ;

    return ;
  }
pps::LUdcmp::LUdcmp ( const LUdcmp lu)

Creates an instance of this class from another instance.

Parameters:
luAn instance of class LUdcmp.

Definition at line 94 of file ludcmp.cpp.

References _matA, _nele, _perm, _sign, and allocate().

                                   : _nele( lu._nele )
  {
    _matA = allocate( _nele ) ;

    _perm.resize( _nele ) ;
    _sign = lu._sign ;

    for ( unsigned i = 0 ; i < _nele; i++ ) {
      _perm[ i ] = lu._perm[ i ] ;

      for ( unsigned j = 0 ; j < _nele ; j++ ) {
        _matA[ i ][ j ] = lu._matA[ i ][ j ] ;        
      }
    }

    return ;
  }

Member Function Documentation

double ** pps::LUdcmp::allocate ( unsigned  n) const [private]

Allocates memory for a ( n x n ) matrix.

Parameters:
nThe number of rows and columns of the matrix.
Returns:
The address 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.

Parameters:
matThe address of the matrix.
nThe 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.

Parameters:
bThe column (and solution) vector.
nThe 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 ;
  }

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