FlyoDoc_2011 Pisa 2011 by GmP --- 011
|
00001 /*************************************************************************** 00002 gmatrix.h - description 00003 ------------------- 00004 begin : Febbraio 2006 00005 copyright : (C) 2000 by Giuseppe M Pierazzini 00006 email : pierazzini@unipi.it 00007 ***************************************************************************/ 00013 #ifndef GMATR_H 00014 #define GMATR_H 00015 00016 #include <cmath> 00017 void REPORT_ERROR(int, const char * tit); 00018 00019 //#include "gvet.h" 00049 class gvet; 00050 class gmatrix 00051 { 00052 protected: 00053 int Col,Row,Elem; 00054 double **ValM; 00055 00056 public: 00057 00058 double detrm; // determinante 00059 int okflag; 00060 00061 // constructor 00062 gmatrix(); // Matrice vuota di dimesioni nulle 00063 gmatrix(int ,int); // Matrice vuota di dimesioni intXint 00064 gmatrix(int ,double); // Matrice diagonale di dimesioni intXint e diagonale con double 00065 gmatrix(const gmatrix & m); // make a new matrix like m 00066 gmatrix(const gvet & gv); // crea una matrice(3,1) da un vettore tridimensionale gvet 00067 ~gmatrix(); 00068 00069 void Set_Size(int,int); //resizes the matrix 00070 gmatrix Proj(const gvet & ); //definisce in this il tensore (proiettore |v><v| ) dal vettore gvet v; 00071 gvet & Get_Vcol(gvet &); // restituisce un vettore definito come la colonna 0 della matrice "this". 00072 void Reset(); // matrix clearing 00073 void Null (); // annulla la matrice 00074 void Unit (); // 1. on the diagonal, 0, off diagonal. 00075 00076 00077 // Assignment operators 00078 00079 gmatrix operator = (const gmatrix& ); // copy of the matrix into new matrix 00080 gmatrix operator = (const gvet & ); // fills a (3,1) matrix with a gvet values 00081 00082 gmatrix operator ~ (); //transpose 00083 gmatrix operator ! (); // makes matrix inversion 00084 00085 // Unary operators 00086 gmatrix operator + (); 00087 gmatrix operator - (); 00088 gvet operator % (const gvet &); // moltiplica una matrice (3,3) per un vettore gvet e restituisce un vettore gvet; 00089 00090 00091 00092 00093 // Combined assignment - calculation operators 00094 gmatrix& operator += (const gmatrix& m); 00095 gmatrix& operator -= (const gmatrix& m); 00096 gmatrix& operator *= (const gmatrix& m); 00097 gmatrix& operator *= (const double& c); 00098 00099 00100 00101 gmatrix& operator ^= (const int& pow); // matrix power 00102 00103 friend gmatrix operator ^ (const gmatrix& m, const int & pow) 00104 { 00105 gmatrix temp = m; 00106 temp ^= pow; 00107 return temp; 00108 }; 00109 00110 00111 // Value extraction method 00112 double& operator () (int row, int col); // Subscript operator 00113 int RowNo () const { return Row; } 00114 int ColNo () const { return Col; } 00115 00116 // dual operators 00117 00118 gmatrix operator * (const gmatrix& m); 00119 gmatrix operator * (const double& a); 00120 friend gmatrix operator * (const double& a, gmatrix& m){return m*a;}; 00121 gmatrix operator + (const gmatrix& m); 00122 gmatrix operator - (const gmatrix& m); 00123 gmatrix& operator /= (const double& c){return *this*=(1./c);}; 00124 gmatrix& operator /= (gmatrix& m){gmatrix temp= *this * !m;*this=temp; 00125 return *this;}; 00126 00127 gmatrix operator / (gmatrix& m){return *this * !m;}; 00128 gmatrix operator / (const double& a) {return *this*(1./a);}; 00129 friend gmatrix operator / (const double& a, gmatrix& m) 00130 {gmatrix temp= !m*a; return temp;}; 00131 00132 //======================== operator end ======================================== 00133 00134 // Utility methods 00135 void Print(const char *); 00136 gmatrix Solve (const gmatrix& v) const; 00137 00138 gmatrix Adj (); 00139 gmatrix Inv (); 00140 double Det () ; 00141 00142 00143 private: 00144 double Norm (); 00145 // Type of matrices solo per sevizi interno...??(sonoi definite inline 00146 double Cofact (int row, int col); 00147 double Cond (); 00148 void Clone (const gmatrix&); 00149 int pivot (int row); 00150 00151 bool IsSquare () { return (Row == Col); } 00152 bool IsSingular (); 00153 bool IsDiagonal (); 00154 bool IsScalar (); 00155 bool IsUnit (); 00156 bool IsNull (); 00157 bool IsSymmetric (); 00158 bool IsSkewSymmetric (); 00159 bool IsUpperTriangular (); 00160 bool IsLowerTriangular (); 00161 }; 00162 00163 // subscript operator to get/set individual elements 00164 inline double & gmatrix::operator () (int r, int c) 00165 { 00166 if (r >= Row|| c >= Col) 00167 REPORT_ERROR(0,"gmatrix::operator(): Index out of range!"); 00168 // cout<<"\n S/R "<<r<<" "<<c<<" "<<Elem<<endl; 00169 00170 return ValM[r][c]; 00171 } 00172 inline void gmatrix::Reset() 00173 {detrm=0.0; 00174 okflag=0; 00175 for (int i=0;i<Row;i++) 00176 for (int j=0;j<Col;j++) 00177 ValM[i][j]=0.0; 00178 } 00179 00180 00181 #endif