Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

/magnus/back_end/Matrix/include/MatrixComputations.h

Go to the documentation of this file.
00001 /*
00002  *   $Id: 
00003  */
00004 
00005 // Copyright (C) 1996 The New York Group Theory Cooperative
00006 // See magnus/doc/COPYRIGHT for the full notice.
00007 //
00008 // Contents: Definition of class SquareMatrix.
00009 //
00010 // Principal Author: Alexey Myasnikov
00011 //
00012 // Status: In development
00013 //
00014 // Usage:
00015 //
00016 // Revision History:
00017 //
00018 //
00019 
00020 
00021 #ifndef _MATRIX_COMPUTATIONS_H_
00022 #define _MATRIX_COMPUTATIONS_H_
00023 
00024 #include "GaussTransformation.h"
00025 
00026 
00027 //------------------------------------------------------------------------//
00028 //------------------------- MatrixComputations ---------------------------//
00029 //------------------------------------------------------------------------//
00030 
00031 
00032 template <class R> class MatrixComputations {
00033 
00034 public:
00035 
00036 
00037   /////////////////////////////////////////////////////////////////////////
00038   //                                                                     //
00039   // Constructors:                                                       //
00040   //                                                                     //
00041   /////////////////////////////////////////////////////////////////////////
00042   MatrixComputations( const Matrix<R>& matrix) : 
00043     isInvertible(dontknow), 
00044     inverseMatrix(NULL)
00045   {
00046     if (matrix.height() != matrix.width())
00047       error ("Matrix is not quadratic");
00048     theMatrix = matrix;
00049     detKnown = false;
00050   }
00051 
00052   ~MatrixComputations()
00053   {
00054      if (inverseMatrix)
00055         delete inverseMatrix;
00056   }
00057 
00058 
00059   /////////////////////////////////////////////////////////////////////////
00060   //                                                                     //
00061   // Accessors:                                                          //
00062   //                                                                     //
00063   /////////////////////////////////////////////////////////////////////////
00064     const Matrix<R>& matrix() const { return theMatrix;}
00065 
00066   int size() const { return theMatrix.height();}
00067   // Returns the size of SquareMatrix
00068 
00069   bool isIdentity() const;
00070   // True if matrix is identical
00071 
00072   R getDeterminant();
00073   // Returns determinant if exists, if not then computes it.
00074 
00075   bool detKnow() const { return detKnown;}
00076   // true if determinant was computed
00077 
00078   Trichotomy isInvertibleMatrix() const { return isInvertible;}
00079   // Yes if matrix invertible
00080   
00081   void invertMatrix();
00082   // Makes inverse matrix if it exists
00083  
00084   const Matrix<R>& getInverseMatrix() const {
00085     #if SAFETY > 0
00086       if ( isInvertible != yes )
00087       error("Trichotomy SquareMatrix::getInverseMatrix( ) : "
00088             "tried to get result before the computation or this matrix is not Invertible.");
00089     #endif
00090     return *inverseMatrix;
00091   }
00092 
00093   R det() const {  return determinant;}
00094   // This function nedet only for constant acces to determinant
00095   /////////////////////////////////////////////////////////////////////////
00096   //                                                                     //
00097   //  IPC tools:                                                         //
00098   //                                                                     //
00099   /////////////////////////////////////////////////////////////////////////
00100   friend ostream& operator < ( ostream& ostr, const MatrixComputations& DA )
00101   {
00102     DA.write(ostr);
00103     return ostr;
00104   }
00105   
00106   friend istream& operator > ( istream& istr, MatrixComputations& DA)
00107   {
00108     DA.read(istr);
00109     return istr;
00110   }
00111 private:
00112   void write( ostream& ostr ) const{
00113      ostr < theMatrix;
00114      ostr < detKnown;
00115      ostr < isInvertible;
00116      ostr < determinant;
00117      if (isInvertible == yes) ostr < *inverseMatrix;
00118   };
00119  
00120   void read( istream& istr ){
00121      istr > theMatrix;
00122      istr > detKnown;
00123      istr > isInvertible;
00124      istr > determinant;
00125      delete inverseMatrix;
00126      if (isInvertible == yes){
00127       Matrix<R> tmpMatrix;
00128       istr > tmpMatrix;
00129       inverseMatrix  = new Matrix<R>(tmpMatrix);
00130      }
00131   }
00132 
00133   void abolishCoefficients(Matrix<R>& matrix );
00134 
00135   bool detKnown;
00136   // True if determinant was computed
00137 
00138   Trichotomy isInvertible;
00139   // Yes if inverse matrix was built, no if matrix couldn't be inverted, 
00140   // otherwize -  dontknow
00141 
00142   R determinant;
00143   // determinant
00144 
00145   Matrix<R>* inverseMatrix;
00146   // Holds inverse matrix, if it was built
00147 
00148   Matrix<R> theMatrix;
00149   // Holds the matrix.
00150 
00151   /////////////////////////////////////////////////////////////////////////
00152   //                                                                     //
00153   //  Debugging stuff:                                                   //
00154   //                                                                     //
00155   /////////////////////////////////////////////////////////////////////////
00156 
00157 #ifdef DEBUG
00158 
00159   //friend int main(...);
00160 
00161 #endif
00162 
00163 };
00164 
00165 
00166 #endif

Generated at Tue Jun 19 09:49:37 2001 for Magnus Classes by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001