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

  1. /**************************************************/
  2. /*    matspec.hpp header for matSpecFunc family   */
  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. #ifndef MATRIX_H
  17. #include "matrix.hpp"
  18. #endif
  19.  
  20. #ifndef MATSPEC_H
  21.  
  22. #define MATSPEC_H
  23.  
  24. #include <math.h>
  25.  
  26. class matSpecFunc : public matObject
  27. {
  28.    protected :
  29.  
  30.       matError  error ;
  31.       INDEX     maxIter ;
  32.       REAL      eps ;
  33.  
  34.    public :
  35.   
  36. #ifdef __cplusplus
  37.       static const REAL   zero,  half,  one,   two,    three,  
  38.                    four,  five,  six,   seven, eight,  nine,
  39.                    ten,   root2, pi;
  40. #else
  41.       static REAL  zero,  half,  one,   two,    three,  
  42.                    four,  five,  six,   seven, eight,  nine,
  43.                    ten,   root2, pi;
  44. #endif
  45.  
  46.       matSpecFunc( void ) ;
  47.       matSpecFunc( const matSpecFunc& fn ) ;
  48.  
  49.       ~matSpecFunc( void )  ;
  50.       void operator = ( matSpecFunc& fn ) 
  51.          { error = fn.error ; }
  52.  
  53.       INDEX ok ( void ) 
  54.          { return !error ; } 
  55.  
  56.       virtual outFile& info( outFile& f ) M_CONST ;
  57.       outFile& specInfo( outFile& f, const char* fName ) M_CONST ;
  58.  
  59.       // virtual class based on
  60.       virtual REAL value( REAL r ) ;
  61.       virtual REAL inv( REAL v ) ;
  62.       REAL operator () ( REAL r ) ;
  63.  
  64.       // iterators
  65.       matrix operator () ( const matrix& x ) ;
  66.       virtual matrix inv( const matrix& x ) ;
  67.       matrix& transform( matrix& z, const matrix& x ) ;
  68.       matrix& invTrans( matrix& z, const matrix& x ) ;
  69.  
  70.       INDEX setIter( INDEX newMax = 0 ) ;
  71.       REAL  setEps( REAL newEps = -1.0 ) ;
  72.  
  73. } ; // class matSpecFunc
  74.  
  75. class logGammaFunc : public matSpecFunc
  76. {
  77.       // logGamma function
  78.  
  79.    public:
  80.  
  81.       logGammaFunc( void ) ;
  82.       ~logGammaFunc( void ) ;
  83.       
  84.       REAL value( REAL r ) ;
  85.       outFile& info( outFile& f ) M_CONST ;
  86.  
  87. } ; // class logGammaFunc
  88.  
  89. extern logGammaFunc logGamma ;
  90.  
  91. extern REAL logBeta( REAL z, REAL w ) ;
  92.  
  93. class incBetaFunc : public matSpecFunc
  94. {
  95.       // parameters a,b with c = logBeta(a,b)
  96.  
  97.       REAL a, b, c ;
  98.  
  99.       REAL fraction( REAL x, REAL a, REAL b, REAL c ) ;
  100.  
  101.    public:
  102.  
  103.       incBetaFunc( void ) ;
  104.       ~incBetaFunc( void ) ;
  105.       incBetaFunc( incBetaFunc& fn ) ;
  106.       void operator = ( incBetaFunc& fn ) ;
  107.       
  108.       REAL value( REAL r ) ;
  109.       outFile& info( outFile& f ) M_CONST ;
  110.  
  111.       incBetaFunc& par( REAL newA, REAL newB ) ;
  112.  
  113.       matrix operator() ( const matrix& x, REAL newA, REAL newB ) ;
  114.       REAL operator() ( REAL r, REAL newA, REAL newB ) ;
  115.  
  116. } ; // class incBetaFunc
  117.  
  118. extern incBetaFunc incBeta ;
  119.  
  120. class incGammaFunc : public matSpecFunc
  121. {
  122.       // incomplete Gamma Function
  123.       // Parameter a with c = logGamma(a) ;
  124.  
  125.       REAL a, c ;
  126.  
  127.       REAL fraction( REAL x ) ;
  128.       // returns estimate of complement of incGamma
  129.  
  130.       REAL series( REAL x ) ;
  131.       // returns estimate of incGamma
  132.  
  133.    public:
  134.  
  135.       incGammaFunc( void ) ;
  136.       ~incGammaFunc( void ) ;
  137.       incGammaFunc( incGammaFunc& fn ) ;
  138.       void operator = ( incGammaFunc& fn ) ;
  139.       
  140.       REAL value( REAL r ) ;
  141.       outFile& info( outFile& f ) M_CONST ;
  142.  
  143.       incGammaFunc& par( REAL newA ) ;
  144.  
  145.       matrix operator() ( const matrix& x, REAL newA ) ;
  146.       REAL operator() ( REAL r, REAL newA ) ;
  147.  
  148. } ; // class incGammaFunc
  149.  
  150. extern incGammaFunc incGamma ;
  151.  
  152. class normalFunc : public matSpecFunc
  153. {
  154.       // Normal Distribution
  155.  
  156.       REAL  lower, upper ;
  157.       int   calcUpper ;
  158.  
  159.    public:
  160.  
  161.       normalFunc( void ) ;
  162.       ~normalFunc( void ) ;
  163.       normalFunc( normalFunc& fn ) ;
  164.       void operator = ( normalFunc& fn ) ;
  165.       
  166.       REAL value( REAL r ) ;
  167.       REAL inv( REAL p ) ;
  168.       outFile& info( outFile& f ) M_CONST ;
  169.  
  170.       normalFunc& par( REAL newLower, REAL newUpper ) ;
  171.       void upperTail( int l ) { calcUpper = l ; } 
  172.       matrix operator() ( const matrix& x ) ;
  173.       matrix inv( const matrix& x ) ;
  174.       REAL operator() ( REAL r ) ;
  175.  
  176. } ; // class normalFunc
  177.  
  178. extern normalFunc normal ;
  179.  
  180. extern REAL possionDist( REAL k, REAL mean ) ;
  181. extern REAL chi2Dist( REAL r, INDEX dof ) ;
  182. extern REAL studentDist( REAL r, INDEX dof ) ;
  183. extern REAL FDist( REAL r, INDEX dof1, INDEX dof2 ) ;
  184.  
  185. #ifndef __cplusplus
  186. extern matrix possionDistM( const matrix& x, REAL mean ) ;
  187. extern matrix chi2DistM( const matrix& x, INDEX dof ) ;
  188. extern matrix studentDistM( const matrix& x, INDEX dof ) ;
  189. extern matrix FDistM( const matrix& x, INDEX dof1, INDEX dof2 ) ;
  190. #else
  191. extern matrix possionDist( const matrix& x, REAL mean ) ;
  192. extern matrix chi2Dist( const matrix& x, INDEX dof ) ;
  193. extern matrix studentDist( const matrix& x, INDEX dof ) ;
  194. extern matrix FDist( const matrix& x, INDEX dof1, INDEX dof2 ) ;
  195. #endif 
  196.  
  197. #endif
  198.