home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 21 / IOPROG_21.ISO / SOFT / LIBMAT.ZIP / CHOLDEC.CPP next >
Encoding:
C/C++ Source or Header  |  1992-10-16  |  3.1 KB  |  122 lines

  1. /**************************************************/
  2. /*     choldec.c source for cholDec class         */
  3. /**************************************************/
  4.  
  5.  
  6. /**************************************************/
  7. /*            MatClass Source File                */
  8. /*       Copyright of C. R. Birchenhall           */
  9. /*       University of Manchester, UK.            */
  10. /*   MatClass is freeware. This file should be    */
  11. /* made freely available to users of any software */
  12. /* whose creation is wholly or partly dependent   */
  13. /*                on this file.                   */
  14. /**************************************************/
  15.  
  16. #include "choldec.hpp"
  17.  
  18. /***************************************************/
  19. /*                  cholDec methods                */
  20. /***************************************************/
  21.  
  22. #ifdef __cplusplus
  23. cholDec::cholDec( void ) : matDec()
  24. #else
  25. cholDec::cholDec( void ) : ()
  26. #endif
  27. {} // cholDec( void )
  28.  
  29.  
  30. #ifdef __cplusplus
  31. cholDec::cholDec( const matrix& x ) : matDec(x)
  32. #else
  33. cholDec::cholDec( const matrix& x ) : (x)
  34. #endif
  35. {} // cholDec( matrix )
  36.  
  37.  
  38. #ifdef __cplusplus
  39. cholDec::cholDec( const cholDec& cd ) : matDec( cd )
  40. #else
  41. cholDec::cholDec( const cholDec& cd ) : ( cd )
  42. #endif
  43. {} // cholDec( cholDec& )
  44.  
  45. cholDec::~cholDec( void ) {} // ~cholDec
  46.  
  47. cholDec& cholDec::operator = ( const cholDec& cd )
  48. {
  49.    matDec::operator = ( cd ) ;
  50.    return *this ;
  51. } // cholDec& =
  52.  
  53. void cholDec::chol( matrix& x )
  54. {
  55.    x = m ;
  56. } // cholDec::chol
  57.  
  58. void cholDec::release( matrix& x )
  59. {
  60.    x.refer( m ) ;
  61.    clear() ;
  62. } // cholDec::chol
  63.  
  64. void cholDec::decompose( void )
  65. {
  66.    static char *mName = "decompose" ;
  67.    matFunc func( mName ) ; debugInfo( func ) ;
  68.    if ( !( status & ASSIGNED ) )
  69.       errorExit( mName, UNASS ) ;
  70.    if ( !( status & DECOMPOSED ) ) {
  71.       cholesky( m, error ) ;
  72.       status |= DECOMPOSED ;
  73.    } // if
  74. } // cholDec::decompose
  75.  
  76. void cholDec::solve( matrix& b )
  77. {
  78.    static char *mName = "solve" ;
  79.    matFunc func( mName ) ; debugInfo( func ) ;
  80.    if ( ok( mName ) ) {
  81.       cholSolve( m, b, tol, error ) ;
  82.       if ( error )
  83.          errorExit( mName, error ) ;
  84.    } // else
  85. } // cholDec::solve
  86.  
  87. void cholDec::transSolve( matrix& b )
  88. {
  89.    solve(b) ;
  90. } // cholDec::transSolve
  91.  
  92. void cholDec::det( REAL& d1, REAL& d2 )
  93. {
  94.    // determinant is square of diagProd of cholesky factor
  95.    static char *mName = "det" ;
  96.    matFunc func( mName ) ; debugInfo( func ) ;
  97.    if ( !( status & DETERMINED ) ) {
  98.       matDec::det(d1,d2) ;
  99.       // square det as calculated by above
  100.       det1 *= det1 ;
  101.       det2 += det2 ;
  102.    } // if
  103.    d1 = det1 ;
  104.    d2 = det2 ;
  105. } // cholDec::det
  106.  
  107. outFile& cholDec::info( outFile& f ) M_CONST
  108. {
  109.    return matDec::decInfo( f, "cholDec" ) ;
  110. } // cholDec::info
  111.  
  112. outFile& cholDec::print( char* decName, outFile& f ) M_CONST
  113. {
  114.    static char *mName = "print" ;
  115.    matFunc func( mName ) ; debugInfo( func ) ;
  116.    f.write( "Cholesky Decomposition : " ) ;
  117.    if ( decName != 0 )
  118.       f.write( decName ) ;
  119.    f.newLine(2) ;
  120.    return matDec::print( "cholDec", f ) ;
  121. } // cholDec::print
  122.