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

  1. /**************************************************/
  2. /*        qrhdec.c source for qrhDec 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 "qrhdec.hpp"
  17.  
  18. /*************************************************************/
  19. /*                      qrhDec methods                       */
  20. /*************************************************************/
  21.  
  22. void qrhDec::setNames( void )
  23. {
  24.    R.name( "decR" ) ;
  25.    w.name( "decW" ) ;
  26. } // qrhDec setNames
  27.  
  28. #ifdef __cplusplus
  29. qrhDec::qrhDec( void ) : matDec()
  30. #else
  31. qrhDec::qrhDec( void ) : ()
  32. #endif
  33. {
  34.    setNames() ;
  35. } // qrhDec
  36.  
  37.  
  38. #ifdef __cplusplus
  39. qrhDec::qrhDec( const qrhDec& qd ) : matDec(qd)
  40. #else
  41. qrhDec::qrhDec( const qrhDec& qd ) : (qd)
  42. #endif
  43. {
  44.    setNames() ;
  45.    R = qd.R ;
  46.    w = qd.w ;
  47. } // qrhDec
  48.  
  49.  
  50. #ifdef __cplusplus
  51. qrhDec::qrhDec( const matrix& x ) : matDec(x)
  52. #else
  53. qrhDec::qrhDec( const matrix& x ) : (x)
  54. #endif
  55. {
  56.    static char *mName = "qrhDec(x)" ;
  57.    matFunc func( mName ) ;
  58.    INDEX n = x.nCols() ;
  59.    R.reset( n, n ) ;
  60.    w.reset( n ) ;
  61.    setNames() ;
  62.    func.trace(TRUE) ; // debugInfo( func ) ;
  63. } // qrhDec( matrix& )
  64.  
  65. qrhDec::~qrhDec( void )
  66. {
  67.    static char *mName = "~qrhDec" ;
  68.    matFunc func( mName ) ; debugInfo( func ) ;
  69. } // ~qrhDec
  70.  
  71. void qrhDec::operator = ( const qrhDec& qd )
  72. {
  73.    static char *mName = "op =" ;
  74.    matFunc func( mName ) ; debugInfo( func ) ;
  75.    matDec::operator = ( qd ) ;
  76.    R = qd.R ;
  77.    w = qd.w ;
  78. } // qrhDec =
  79.  
  80. void qrhDec::clear( void )
  81. {
  82.    static char *mName = "clear" ;
  83.    matFunc func( mName ) ; debugInfo( func ) ;
  84.    matDec::clear() ;
  85.    R.clear() ;
  86.    w.clear() ;
  87. } // qrhDec clear
  88.  
  89. void qrhDec::assign( const matrix& x )
  90. {
  91.    static char *mName = "assign" ;
  92.    matFunc func( mName ) ; debugInfo( func ) ;
  93.    matDec::assign(x) ;
  94.    INDEX n = x.nCols() ;
  95.    R.reset( n, n ) ;
  96.    w.reset( n ) ;
  97. } // qrhDec::assign
  98.  
  99. void qrhDec::capture( matrix& x )
  100. {
  101.    static char *mName = "capture" ;
  102.    matFunc func( mName ) ; debugInfo( func ) ;
  103.    matDec::capture(x) ;
  104.    INDEX n = x.nCols() ;
  105.    R.reset( n, n ) ;
  106.    w.reset( n ) ;
  107. } // qrhDec::capture
  108.  
  109. void qrhDec::qr( matrix& x, matrix& b, matrix& dg )
  110. {
  111.    static char *mName = "capture" ;
  112.    matFunc func( mName ) ; debugInfo( func ) ;
  113.    if ( ok( mName ) ) {
  114.       x = m ; 
  115.       b = w ;
  116.       dg.diagOf( R ) ;
  117.    } // if
  118. } // qrhDec qr
  119.  
  120. void qrhDec::release( matrix& x, matrix& b, matrix& dg )
  121. {
  122.    static char *mName = "capture" ;
  123.    matFunc func( mName ) ; debugInfo( func ) ;
  124.    if ( ok( mName ) ) {
  125.       x.capture( m ) ; 
  126.       b.capture( w ) ;
  127.       dg.diagOf( R ) ;
  128.       clear() ;
  129.    } // if
  130. } // qrhDec qr
  131.  
  132. void qrhDec::decompose( void )
  133. {
  134.    static char *mName = "decompose" ;
  135.    matFunc func( mName ) ; debugInfo( func ) ;
  136.    if ( !( status & ASSIGNED ) )
  137.       errorExit( mName, UNASS ) ;
  138.    if ( !( status & DECOMPOSED ) ) {
  139.       INDEX n = m.nCols() ;
  140.       matrix diagR(n) ;
  141.       qrh( m, diagR, w, tol, error ) ;
  142.       if ( !error ) {
  143.          R.triuOf( m.sub( 1, n, 1, n ) ) ;
  144.          R.setDiag( diagR ) ;
  145.       } // if
  146.       status |= DECOMPOSED ;
  147.    } // if
  148. } // qrhDec::decompose
  149.  
  150. void qrhDec::solve( matrix& b )
  151. {
  152.    static char *mName = "solve" ;
  153.    matFunc func( mName ) ; debugInfo( func ) ;
  154.    if ( ok( mName ) ) {
  155.       qReflect( b, m, w, error ) ;
  156.       if ( error )
  157.          errorExit( mName, error ) ;
  158.       backSub( b, R, tol, error ) ;
  159.       if ( error )
  160.      errorExit( mName, error ) ;
  161.    } // else
  162. } // qrhDec::solve
  163.  
  164. void qrhDec::transSolve( matrix& b )
  165. {
  166.    static char *mName = "transSolve" ;
  167.    matFunc func( mName ) ; debugInfo( func ) ;
  168.    if ( ok( mName ) ) {
  169.       backSubT( b, R, tol, error ) ;
  170.       if ( error )
  171.      errorExit( mName, error ) ;
  172.       qTReflect( b, m, w, error ) ;
  173.       if ( error )
  174.          errorExit( mName, error ) ;
  175.    } // else
  176. } // qrhDec::transSolve
  177.  
  178. outFile& qrhDec::info( outFile& f ) M_CONST
  179. {
  180.    return matDec::decInfo( f, "qrhDec" ) ;
  181. } // qrhDec::info
  182.  
  183. inFile& qrhDec::get( inFile& f )
  184. {
  185.    static char *mName = "get" ;
  186.    matFunc func( mName ) ; debugInfo( func ) ;
  187.    matDec::get(f) ;
  188.    INDEX n = m.nCols() ;
  189.    R.reset( n, n ) ;
  190.    w.reset( n ) ;
  191.    R.get(f) ;
  192.    w.get(f) ;
  193.    return f ;
  194. } // qrhDec::get
  195.  
  196. outFile& qrhDec::put( outFile& f ) M_CONST
  197. {
  198.    static char *mName = "put" ;
  199.    matFunc func( mName ) ; debugInfo( func ) ;
  200.    matDec::put(f) ;
  201.    R.put(f) ;
  202.    w.put(f) ;
  203.    return f ;
  204. } // qrhDec::put
  205.  
  206. outFile& qrhDec::print( char* decName, outFile& f ) M_CONST
  207. {
  208.    static char *mName = "print" ;
  209.    matFunc func( mName ) ; debugInfo( func ) ;
  210.    f.write( "QR (Househiolder) Decomposition : " ) ;
  211.    if ( decName != 0 ) 
  212.       f.write( decName ) ;
  213.    f.newLine(2) ;
  214.    matDec::print( "QR", f ) ;
  215.    R.print( "R :" , f ) ;
  216.    w.print( "Householder `betas' : ", f ) ;
  217.    return f ;
  218. } // qrhDec::print
  219.  
  220. void qrhDec::det( REAL& d1, REAL& d2 )
  221. {
  222.    static char *mName = "det" ;
  223.    matFunc func( mName ) ; debugInfo( func ) ;
  224.    if ( !( status & DETERMINED ) ) {
  225.       decompose() ;
  226.       if ( error )
  227.          errorExit( mName, error ) ;
  228.       else {
  229.          dProduct( R.diag(), det1, det2, tol, error ) ;
  230.          if ( error )
  231.         errorExit( mName, error ) ;
  232.       } // else
  233.    } // if
  234.    d1 = det1 ;
  235.    d2 = det2 ;
  236. } // qrhDec::det
  237.