home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / DRMATRIX.ZIP / DRMATRIX.HPP next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  2.9 KB  |  107 lines

  1. // DrMatrix.hpp
  2. // Include this file in all modules that use DrMatrix classes
  3.  
  4. #ifndef __STDLIB_H
  5. #include <stdlib.h>
  6. #endif
  7.  
  8. #ifndef __IOSTREAM_H
  9. #include <iostream.h>
  10. #endif
  11.  
  12.  
  13. // Enum data types
  14. enum V_ALIGN {V_HORIZ,V_VERT};
  15. enum BOOL    {FALSE,TRUE};
  16.  
  17.  
  18. // Vector template class definition
  19. template <class Type> class Vector
  20. {
  21.     friend ostream& operator<<(ostream&,Vector&);
  22.     friend istream& operator>>(istream&,Vector&);
  23.     friend Vector   operator* (Type,Vector&);
  24.  
  25.     public:
  26.         // Constructors and desctructor
  27.         Vector(int n,V_ALIGN vtype=V_HORIZ);
  28.         Vector(const Vector&);
  29.         ~Vector() {delete [] data;};
  30.  
  31.         // Member operators
  32.         Type&  operator()(int k);
  33.         Vector operator+(Vector& b);
  34.         Vector operator-(Vector& b);
  35.         Vector operator-();
  36.         Type   operator*(Vector& b);
  37.         Vector& operator=(Vector& b);
  38.         BOOL   operator==(Vector& b);
  39.  
  40.         // Member functions
  41.         Vector T();  // transpose
  42.         int lead();  // leading element
  43.         V_ALIGN align() {return _vtype;};
  44.         int len() {return _len;};
  45.         Type abs();     // absolute value (distance from origin)
  46.  
  47.     private:
  48.         Type *data;
  49.         int _len;
  50.         V_ALIGN _vtype;
  51. };
  52.  
  53.  
  54. // Matrix template class definition
  55. template <class Type> class Matrix
  56. {
  57.     friend ostream& operator<<(ostream&,Matrix&);
  58.     friend istream& operator>>(istream&,Matrix&);
  59.     friend Matrix   operator* (Type a,  Matrix&);
  60.  
  61.     public:
  62.         // Constructors and destructor
  63.         Matrix(int n,int m);
  64.         Matrix(const Matrix&);
  65.         ~Matrix() {delete [] data;};
  66.  
  67.         // Member operators
  68.         inline Type& operator()(int i,int j);
  69.         Matrix operator+(Matrix& b);
  70.         Matrix operator-(Matrix& b);
  71.         Matrix operator-();
  72.         Matrix operator*(Matrix& b);
  73.         Matrix& operator=(Matrix& b);
  74.         BOOL operator==(Matrix& b);
  75.  
  76.         // Mathematical functions
  77.         Matrix T();                // transpose
  78.         Type tr();                // trace
  79.         Type det();                // determinant
  80.         int lead(int n);        // leading element of nth row
  81.         Matrix step();            // return equivalent, stepped matrix
  82.         Matrix canon();            // return the equivalent canonized matrix
  83.         int rank();                // return the rank of the matrix
  84.         Matrix inv();            // return the inverse matrix
  85.  
  86.         // Property functions - return true if matrix satisfies property
  87.         BOOL diag();            // diagonal matrix
  88.         BOOL iden();            // identity matrix
  89.         BOOL scalar();            // scalar matrix (equal to kI, for real k)
  90.         BOOL sym();                // symmetric matrix (m(i,j)==m(j,i))
  91.         BOOL antisym();            // antisymmetric matrix (m(i,j)==-m(j,i))
  92.         BOOL square();            // square matrix (nrows==ncols)
  93.         BOOL stepped();            // stepped matrix
  94.         BOOL reg();                // regular (reversible) matrix
  95.         BOOL sing();            // singular (non-reversible) matrix
  96.  
  97.         // Organizational functions
  98.         Vector<Type> row(int n); // returns nth row in matrix
  99.         Vector<Type> col(int m); // returns mth column in matrix
  100.         int nrows() {return _nrows;};
  101.         int ncols() {return _ncols;};
  102.  
  103.     private:
  104.         int _nrows,_ncols;
  105.         Type* data;
  106. };
  107.