1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
// Copyright (C) 1996 The New York Group Theory Cooperative
// See magnus/doc/COPYRIGHT for the full notice.
//
// Contents: Definition of class SquareMatrix.
//
// Principal Author: Alexey Myasnikov
//
// Status: In development
//
// Usage:
//
// Revision History:
//
//
#ifndef _MATRIX_COMPUTATIONS_H_
#define _MATRIX_COMPUTATIONS_H_
#include "GaussTransformation.h"
//------------------------------------------------------------------------//
//------------------------- MatrixComputations ---------------------------//
//------------------------------------------------------------------------//
template <class R> class MatrixComputations {
public:
/////////////////////////////////////////////////////////////////////////
// //
// Constructors: //
// //
/////////////////////////////////////////////////////////////////////////
MatrixComputations( const Matrix<R>& matrix) :
isInvertible(dontknow),
inverseMatrix(NULL)
{
if (matrix.height() != matrix.width())
error ("Matrix is not quadratic");
theMatrix = matrix;
detKnown = false;
}
~MatrixComputations()
{
if (inverseMatrix)
delete inverseMatrix;
}
/////////////////////////////////////////////////////////////////////////
// //
// Accessors: //
// //
/////////////////////////////////////////////////////////////////////////
const Matrix<R>& matrix() const { return theMatrix;}
int size() const { return theMatrix.height();}
// Returns the size of SquareMatrix
bool isIdentity() const;
// True if matrix is identical
R getDeterminant();
// Returns determinant if exists, if not then computes it.
bool detKnow() const { return detKnown;}
// true if determinant was computed
Trichotomy isInvertibleMatrix() const { return isInvertible;}
// Yes if matrix invertible
void invertMatrix();
// Makes inverse matrix if it exists
const Matrix<R>& getInverseMatrix() const {
#if SAFETY > 0
if ( isInvertible != yes )
error("Trichotomy SquareMatrix::getInverseMatrix( ) : "
"tried to get result before the computation or this matrix is not Invertible.");
#endif
return *inverseMatrix;
}
R det() const { return determinant;}
// This function nedet only for constant acces to determinant
/////////////////////////////////////////////////////////////////////////
// //
// IPC tools: //
// //
/////////////////////////////////////////////////////////////////////////
friend ostream& operator < ( ostream& ostr, const MatrixComputations& DA )
{
DA.write(ostr);
return ostr;
}
friend istream& operator > ( istream& istr, MatrixComputations& DA)
{
DA.read(istr);
return istr;
}
private:
void write( ostream& ostr ) const{
ostr < theMatrix;
ostr < detKnown;
ostr < isInvertible;
ostr < determinant;
if (isInvertible == yes) ostr < *inverseMatrix;
};
void read( istream& istr ){
istr > theMatrix;
istr > detKnown;
istr > isInvertible;
istr > determinant;
delete inverseMatrix;
if (isInvertible == yes){
Matrix<R> tmpMatrix;
istr > tmpMatrix;
inverseMatrix = new Matrix<R>(tmpMatrix);
}
}
void abolishCoefficients(Matrix<R>& matrix );
bool detKnown;
// True if determinant was computed
Trichotomy isInvertible;
// Yes if inverse matrix was built, no if matrix couldn't be inverted,
// otherwize - dontknow
R determinant;
// determinant
Matrix<R>* inverseMatrix;
// Holds inverse matrix, if it was built
Matrix<R> theMatrix;
// Holds the matrix.
/////////////////////////////////////////////////////////////////////////
// //
// Debugging stuff: //
// //
/////////////////////////////////////////////////////////////////////////
#ifdef DEBUG
//friend int main(...);
#endif
};
#endif
|