home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / c / math_classes.lha / math_classes / matrix / libmatrix / Matrix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-05  |  2.6 KB  |  115 lines

  1. #ifndef _MATRIX_H
  2. #define _MATRIX_H
  3.  
  4.  
  5.  
  6. typedef float mtrxtype;
  7. class LUmatrix;
  8. class Pmatrix;
  9. class Matrix;
  10.  
  11. double abs(double a);
  12.  
  13. void error(char *);
  14.  
  15.  
  16. class Matrix
  17. {
  18.     unsigned int r;
  19.     unsigned int c;
  20.     mtrxtype *vals;
  21. public:
  22.     Matrix();
  23.     Matrix(unsigned int,unsigned int);
  24.     Matrix(const Matrix&);
  25.     Matrix(unsigned int,unsigned int,mtrxtype *);
  26.     Matrix(const Pmatrix&);
  27.     ~Matrix();
  28.     unsigned int rows() const
  29.         {
  30.         return r;
  31.         }
  32.     unsigned int cols() const
  33.         {
  34.         return c;
  35.         }
  36.     mtrxtype& operator()(unsigned int i,unsigned int j) const
  37.         {
  38. #ifdef CHECKRANGE
  39.         if(i>rows() || i==0 || j>cols() || j==0)error("bad subscript");
  40. #endif
  41.         return vals[(i-1)*cols()+j-1];
  42.         }
  43.     void rowexchange(unsigned int,unsigned int);
  44.     void setrow(unsigned int,Matrix);
  45.     Matrix getrow(unsigned int) const;
  46.     void setcol(unsigned int,Matrix);
  47.     Matrix getcol (unsigned int) const;    
  48.     friend void swap(Matrix& m1,Matrix& m2);
  49.     Matrix& operator= (const Matrix&);
  50.     Matrix& operator+=(const Matrix&);
  51.     Matrix& operator-=(const Matrix&);
  52.     Matrix& operator*=(mtrxtype);
  53.     friend Matrix operator+ (const Matrix&,const Matrix&);
  54.     friend Matrix operator- (const Matrix&,const Matrix&);
  55.     friend Matrix operator* (const Matrix&,const Matrix&);
  56.     friend Matrix operator* (const Matrix&,mtrxtype);
  57.     friend Matrix operator* (mtrxtype,const Matrix&);
  58.     friend int operator==(const Matrix&,const Matrix&);
  59.     friend int operator!=(const Matrix&,const Matrix&);
  60.     void setunity();
  61. };
  62.  
  63. mtrxtype determinant(const Matrix&);
  64. Matrix inverse(const Matrix&);
  65. Matrix transpose(const Matrix&);
  66. Matrix solve(const Matrix&,const Matrix&);
  67. Matrix solve(const LUmatrix&,const Matrix&);
  68. LUmatrix LUdecompose(const Matrix&);
  69. Matrix unity(unsigned int);
  70. void print(const Matrix&);
  71.  
  72. class Pmatrix
  73.     {
  74.     // Permutation matrix
  75.     friend class LUmatrix;
  76.     friend class Matrix;
  77.     unsigned int rws;
  78.     unsigned int *r;
  79. public:
  80.     Pmatrix();
  81.     Pmatrix(unsigned int);
  82.     Pmatrix(const Pmatrix&);
  83.     ~Pmatrix();
  84.     unsigned int rows() const
  85.         {
  86.         return rws;
  87.         }
  88.     Pmatrix& operator= (const Pmatrix&);
  89.     friend Pmatrix inverse(const Pmatrix&);
  90.     friend Pmatrix transpose(const Pmatrix&);
  91.     friend Matrix operator* (const Pmatrix&,const Matrix&);
  92.     friend Pmatrix operator* (const Pmatrix&,const Pmatrix&);
  93.     unsigned int& operator[](unsigned int) const;
  94.     mtrxtype operator()(unsigned int,unsigned int) const;
  95.     };
  96.  
  97.  
  98. class LUmatrix
  99.     {
  100.     friend class Matrix;
  101.     friend class Pmatrix;
  102.     Matrix lu;
  103.     Pmatrix p;
  104. public:
  105.     LUmatrix& operator= (const LUmatrix&);
  106.     friend LUmatrix LUdecompose(const Matrix&);
  107.     friend Matrix LUsolve(const LUmatrix&,const Matrix&);
  108.     friend Matrix getl(const LUmatrix&);
  109.     friend Matrix getu(const LUmatrix&);
  110.     friend Matrix getp(const LUmatrix&);
  111.     };
  112.  
  113.  
  114. #endif /* _MATRIX_H */
  115.