FlyoDoc_2011 Pisa 2011 by GmP --- 011

flyopunta/src/src_uti/gmatrix.cpp

00001 /***************************************************************************
00002                           GPmrg->h  -  description
00003                              -------------------
00004     begin                : Febbraio 2006
00005     copyright            : (C) 2000 by Giuseppe M Pierazzini
00006     email                : pierazzini@unipi.it
00007  ***************************************************************************/
00008 //----------------------   vector -----------------------------
00009 #define GVECTOR
00010 #include "parm.h"
00011 #include "gmatrix.h"
00012 #include "evento.h"
00013 #include "gvet.h"
00014 
00015 using namespace std;
00016 
00017 
00048 //--------------------  c o s t r u t t o r i
00049 // costruttore
00050 
00051 
00052 gmatrix::gmatrix()
00053 {
00054         // matrice vuota con dimensioni nulle
00055         Row =Col=Elem=0;
00056         ValM= 0;
00057         detrm=0.0;
00058         okflag=0;
00059 
00060 }
00061 
00062 
00063 
00064 
00065 gmatrix::gmatrix ( int r, int c )
00066 {
00067 // it generates an empty matrix of rXc dimension 
00068         Row = r;
00069         Col = c;
00070         Elem=Row*Col;
00071         ValM = new double *  [Row];
00072         for ( int i=0;i<Row;i++ )
00073                 ValM[i]=new double [Col];
00074         Reset();
00075 
00076 }
00077 
00078 gmatrix::gmatrix ( int r, double aa)
00079 {
00080  // it generates an empty matrix of rXr dimension with the diagonal terms  filled with aa
00081        
00082         Row = r;
00083         Col = r;
00084         Elem=Row*Col;
00085         ValM = new double *  [Row];
00086         for ( int i=0;i<Row;i++ )
00087                 ValM[i]=new double [Col];
00088         Reset();
00089         for ( int i=0;i<Row;i++ )ValM[i][i]=aa;
00090         Det();
00091 }
00092 
00093 
00094 
00095 
00096 gmatrix::gmatrix ( const gmatrix & m )
00097 {
00098 // generate a new matrix equal to m
00099         Row = m.Row;
00100         Col = m.Col;
00101         Elem=Row*Col;
00102         ValM = new double *  [Row];
00103         for ( int i=0;i<Row;i++ )
00104                 ValM[i]=new double [Col];
00105         for ( int i=0;i<Row;i++ )
00106                 for ( int j=0;j<Col;j++ )
00107                         ValM[i][j]=m.ValM[i][j];
00108         detrm=m.detrm;
00109         okflag=0;
00110 
00111 }
00112 
00113 gmatrix::gmatrix ( const gvet & v )
00114 {
00115 // genertes a matrix from the vector (gvet)  v    
00116    Elem=Row=Col=0;
00117   *this=v;  // see the "=" operator
00118 }
00119 
00120 
00121 inline void gmatrix::Clone ( const gmatrix & m )
00122 {
00123         // matrice copia di m ; Clone
00124         Row = m.Row;
00125         Col = m.Col;
00126         Elem=Row*Col;
00127         ValM = new double *  [Row];
00128         for ( int i=0;i<Row;i++ )
00129                 ValM[i]=new double [Col];
00130         for ( int i=0;i<Row;i++ )
00131                 for ( int j=0;j<Col;j++ )
00132                         ValM[i][j]=m.ValM[i][j];
00133         detrm=m.detrm;
00134   okflag=0;
00135 }
00138 gmatrix::~gmatrix()
00139 {
00140         for ( int i=0; i < Row; i++ ) delete [] ValM[i];
00141         delete [] ValM;
00142 }
00143 //===================================
00144 
00145 gmatrix   gmatrix::Proj(const gvet &v)
00146 { // definisce in this il  tensore (proiettore  |v><v| ) dal vettore gvet v;
00147 
00148    if ( Row != 3 || Col != 3 )
00149                 REPORT_ERROR ( 0,"gmatrix::operator+= : Inconsistent matrix sizes in addition!" ); 
00150    gmatrix gv(v);
00151    *this= gv*(~gv);
00152    return *this;
00153 }
00154 
00155 
00156 gmatrix gmatrix::operator= ( const gmatrix& m )
00157 {   // copies a matrix m into this
00158         if ( Elem==0 )  //Matrice vuota...appena nata
00159         {
00160                 Row = m.Row;
00161                 Col = m.Col;
00162                 Elem=Row*Col;
00163                 ValM = new double *  [Row];
00164                 for ( int i=0;i<Row;i++ )
00165                         ValM[i]=new double [Col];
00166         }
00167         else if ( Row != m.Row || Col != m.Col )
00168                 REPORT_ERROR ( 0,"gmatrix::operator = : Inconsistent matrix sizes !" );
00169         for ( int i=0;i<Row;i++ )
00170                 for ( int j=0;j<Col;j++ )
00171                         ValM[i][j]=m.ValM[i][j];
00172         detrm=m.detrm;
00173   okflag=m.okflag;
00174         return *this;
00175 }
00176 
00177 //   gmatrix da Gvet 
00178 
00179 gmatrix gmatrix::operator= ( const gvet & m )
00180 {
00181         if ( Elem==0 )  //Matrice vuota...appena nata
00182         {
00183                 Row = 3;
00184                 Col = 1;
00185                 Elem=3;
00186                 ValM = new double *  [Row];
00187                 for ( int i=0;i<Row;i++ )
00188                         ValM[i]=new double [Col];
00189         }
00190         else if ( Row != 3 || Col !=1 )
00191                 REPORT_ERROR ( 0,"gmatrix::operator = : Inconsistent matrix sizes !" );
00192         ValM[0][0]=m.x;ValM[1][0]=m.y;ValM[2][0]=m.z;
00193         detrm=0.0;
00194   okflag=0;
00195         return *this;
00196 }
00197 
00198 
00199  gvet   gmatrix::operator % (const gvet &v) 
00200  { // moltiplica un vettore per una matrice(3,3)
00201    // restituyisce un vettore gvet
00202    gmatrix Vg(v);
00203    gvet vout;
00204    Vg = (*this*Vg);
00205    vout=Vg;
00206    return vout;
00207    }
00208 
00209 
00210 
00211 
00212 //=====================================================
00213 // annulla la matrice eliminando  gli elementi! OK
00214 void gmatrix::Null()
00215 {
00216 for ( int i=0; i < Row; i++ )  delete [] ValM[i];
00217 delete [] ValM;
00218 Row =Col=Elem=0;
00219 ValM=0;
00220 detrm=0.0;
00221 okflag=0;
00222 
00223 }
00224 void gmatrix::Set_Size ( int r, int c )
00225 {
00226         if ( Row==r && Col==c )
00227                 {Reset(); return;} // nothing to do
00228         for ( int i=0; i < Row; i++ )  delete [] ValM[i];
00229         delete [] ValM;
00230         Row = r;
00231         Col = c;
00232         Elem=Row*Col;
00233         ValM = new double *  [Row];
00234         for ( int i=0;i<Row;i++ )
00235                 ValM[i]=new double [Col];
00236         Reset();
00237 }
00238 
00239 
00240 
00241 
00242 //printout OK
00243 void gmatrix::Print ( const char * title )
00244 {
00245 
00246         Gout<< " \n\nPrint < "<<title<<" >  di "<<Elem <<"  elementi e  dim:"
00247         <<" ( "<<Row<<"X"<<Col<<" ) Det "<<detrm<<endl;
00248 
00249         for ( int  i=0; i < Row; i++ )
00250         {
00251                 for ( int  j=0; j < Col; j++ )
00252                 {
00253       Gout.setf(ios::scientific);
00254                         Gout<<setw ( 11 ) <<setprecision ( 5 ) <<ValM[i][j]<< '\t';
00255                 }
00256                 Gout<<endl;
00257         }
00258   
00259 
00260         Gout<<"=== e n d  < "<<title<<" >\n "<<endl;
00261 
00262 }
00263 
00264 
00265 
00266 // Unary operators : cambio segno OK
00267 gmatrix  gmatrix::operator - ()
00268 {
00269         gmatrix temp ( Row,Col );
00270         for ( int i=0;i<Row;i++ )
00271                 for ( int j=0;j<Col;j++ )
00272                         temp.ValM[i][j]=-ValM[i][j];
00273         return temp;
00274 }
00275 
00276 
00277 // unary transpose operator OK
00278 gmatrix gmatrix::operator ~ ()
00279 {
00280         gmatrix temp ( Col,Row );
00281         for ( int i=0; i < Col; i++ )
00282         {
00283                 for ( int j=0; j < Row; j++ )
00284                 {
00285                         temp ( i,j ) =ValM[j][i];
00286                 }
00287                 temp.detrm=detrm;
00288         }
00289         return temp;
00290 }
00291 
00292 
00293 
00294 // combined addition and assignment operator  OK
00295 gmatrix & gmatrix ::operator+= ( const gmatrix & m )
00296 {
00297         if ( Row != m.Row || Col != m.Col )
00298                 REPORT_ERROR ( 0,"gmatrix::operator+= : Inconsistent matrix sizes in addition!" );
00299         for ( int i=0;i<Row;i++ )
00300                 for ( int j=0;j<Col;j++ )
00301                         ValM[i][j]+=m.ValM[i][j];
00302         detrm=0.0;
00303         return *this;
00304 }
00305 
00306 
00307 // combined subtraction and assignment operator   OK
00308 gmatrix & gmatrix ::operator-= ( const gmatrix & m )
00309 {
00310         if ( Row != m.Row || Col != m.Col )
00311         {
00312                 Gout<<"\n Dim: "<<Row<<"X"<<Col<<" "<<m.Row<<"X"<<m.Col<<endl;
00313                 REPORT_ERROR ( 0,"gmatrix::operator-= : Inconsistent matrix sizes in subctration!" );
00314         }
00315 
00316         for ( int i=0;i<Row;i++ )
00317                 for ( int j=0;j<Col;j++ )
00318                         ValM[i][j]-=m.ValM[i][j];
00319         detrm=0.0;
00320 
00321         return *this;
00322 }
00323 
00324 
00325 
00326 
00327 // combined product  and assignment operator for a double.OK
00328 gmatrix& gmatrix::operator*= ( const double & a )
00329 {
00330 
00331         for ( int i=0;i<Row;i++ )
00332         {
00333                 detrm*=a;
00334                 for ( int j=0;j<Col;j++ )
00335                         ValM[i][j]*=a;
00336         }
00337         return *this;
00338 }
00339 
00340 // combined matrix multiplication and assignment operator OK
00341 gmatrix& gmatrix::operator*= ( const gmatrix& m )
00342 {
00343         if ( Col != m.Row )
00344         {
00345                 Gout<<"\n Dim: "<<Row<<"X"<<Col<<" "<<m.Row<<"X"<<m.Col<<endl;
00346                 REPORT_ERROR ( 0, "gmatrix::operator*= : Inconsistent matrix sizes in multiplication!" );
00347         }
00348 
00349         gmatrix temp ( Row,m.Col );
00350 
00351         for ( int i=0; i < Row; i++ )
00352                 for ( int j=0; j < m.Col; j++ )
00353                 {
00354                         temp.ValM[i][j] = 0.0;
00355                         for ( int k=0; k < Col; k++ )
00356                                 temp.ValM[i][j] +=ValM[i][k] * m.ValM[k][j];
00357                 }
00358         temp.detrm= detrm*m.detrm;
00359         *this = temp;
00360         return *this;
00361 }
00362 
00363 // binary matrix multiplication operator  OK
00364 gmatrix  gmatrix::operator * ( const gmatrix& m )
00365 {
00366         if ( Col != m.Row )
00367         {
00368                 Gout<<"\n Dim: "<<Row<<"X"<<Col<<" "<<m.Row<<"X"<<m.Col<<endl;
00369                 REPORT_ERROR ( 0, "gmatrix::operator* : Inconsistent matrix sizes!" );
00370 
00371         }
00372         gmatrix temp ( Row,m.Col );
00373 
00374         for ( int i=0; i < Row; i++ )
00375                 for ( int j=0; j < m.Col; j++ )
00376                 {
00377                         temp.ValM[i][j] = 0.0;
00378                         for ( int k=0; k < Col; k++ )
00379                                 temp.ValM[i][j] +=ValM[i][k] * m.ValM[k][j];
00380                 }
00381         temp.detrm= detrm*m.detrm;
00382         return temp;
00383 }
00384 // prodotto con un vettore gvet 3x3 e stituisce un vettore
00385 
00386 
00387 
00388 // binary addition operator   OK
00389 gmatrix gmatrix::operator + ( const gmatrix& m )
00390 {
00391         gmatrix temp = *this;
00392         temp += m;
00393         return temp;
00394 }
00395 
00396 // binary subctration operator  OK
00397 gmatrix gmatrix::operator - ( const gmatrix& m )
00398 {
00399         gmatrix temp =*this;
00400         temp -= m;
00401         return temp;
00402 }
00403 
00404 // binary scalar multiplication operator OK
00405 gmatrix gmatrix::operator * ( const double &a )
00406 {
00407         gmatrix temp = *this;
00408         temp *= a;
00409         return temp;
00410 }
00411 
00412 // combined power and assignment operator OK
00413 gmatrix& gmatrix::operator ^= ( const int& pow )
00414 {
00415         gmatrix temp ( *this );
00416         for ( int i=2; i <= pow; i++ )
00417                 *this = ( *this * temp );
00418         return *this;
00419 }
00420 
00421 
00422 
00423 
00424 
00425 
00426 // unary inversion operator   OK
00427 gmatrix gmatrix::operator ! ()
00428 {
00429         gmatrix temp = *this;
00430 
00431         return temp.Inv();
00432 }
00433 
00434 
00435 
00436 gmatrix gmatrix::Inv ()
00437 {
00438         // attenzione cambia this...
00439         int i,j,k;
00440         double a1,a2,*rowptr;
00441         okflag=1;
00442         if ( Row != Col )
00443                 REPORT_ERROR ( 0, "gmatrix::operator!: Inversion of a non-square matrix" );
00444         gmatrix temp ( Row,Col );
00445         temp.Unit();
00446         for ( k=0; k < Row; k++ )
00447         {
00448                 int indx = pivot ( k );
00449                 if ( indx == -1 )
00450                 {
00451                         REPORT_ERROR ( 2,"gmatrix::Inversion of singular matrix!" );
00452       temp.Unit(); temp.okflag=-1;
00453       return temp;
00454                 }
00455 
00456                 if ( indx != 0 )
00457                 {
00458                         rowptr = temp.ValM[k];
00459                         temp.ValM[k] = temp.ValM[indx];
00460                         temp.ValM[indx] = rowptr;
00461                 }
00462                 a1 =ValM[k][k];
00463                 for ( j=0; j < Row; j++ )
00464                 {
00465                         ValM[k][j] /= a1;
00466                         temp.ValM[k][j] /= a1;
00467                 }
00468                 for ( i=0; i < Row; i++ )
00469                         if ( i != k )
00470                         {
00471                                 a2 =ValM[i][k];
00472                                 for ( j=0; j < Row; j++ )
00473                                 {
00474                                         ValM[i][j] -= a2 *ValM[k][j];
00475                                         temp.ValM[i][j] -= a2 * temp.ValM[k][j];
00476                                 }
00477                         }
00478         }
00479         if ( detrm!=0.0 ) temp.detrm=1./detrm; else temp.detrm=0.0;
00480         return temp;
00481 }
00482 
00483 
00484 // private partial pivoting method OK
00485 int gmatrix::pivot ( int  row )
00486 {
00487         int k = int ( row );
00488         double amax,temp;
00489         amax = -1.;
00490         for ( int  i=row; i < Row; i++ )
00491                 if ( ( temp = abs ( ValM[i][row] ) ) > amax && temp != 0.0 )
00492                 {
00493                         amax = temp;
00494                         k = i;
00495                 }
00496 
00497         if ( ValM[k][row] == 0.0 )
00498                 return -1;
00499         if ( k != int ( row ) )
00500         {
00501                 double* rowptr =ValM[k];
00502                 ValM[k] =ValM[row];
00503                 ValM[row] = rowptr;
00504                 return k;
00505         }
00506         return 0;
00507 }
00508 
00509 // calculate the determinant of a matrix
00510 double gmatrix::Det ()
00511 {
00512         int  i,j,k;
00513         double piv,detVal = 1.0;
00514         if ( Row != Col )
00515                 REPORT_ERROR ( 0, "gmatrix::Det(): Determinant a non-square matrix!" );
00516 
00517         gmatrix temp ( *this );
00518         for ( k=0; k < Row; k++ )
00519         {
00520                 int indx = temp.pivot ( k );
00521                 if ( indx == -1 )
00522                         return 0;
00523                 if ( indx != 0 )
00524                         detVal = - detVal;
00525                 detVal = temp.ValM[k][k]*detVal ;
00526                 for ( i=k+1; i < Row; i++ )
00527                 {
00528                         piv = temp.ValM[i][k] / temp.ValM[k][k];
00529                         for ( j=k+1; j < Row; j++ )
00530                                 temp.ValM[i][j] -= piv * temp.ValM[k][j];
00531                 }
00532         }
00533         detrm=detVal;
00534         return detVal;
00535 }
00536 
00537 
00538 // solve simultaneous equation  OK
00539 gmatrix gmatrix::Solve ( const gmatrix& v ) const
00540 {
00541         int i,j,k;
00542         double a1;
00543 
00544         if ( ! ( Row == Col && Col == v.Row ) )
00545                 REPORT_ERROR ( 0, "gmatrix::Solve():Inconsistent matrices!" );
00546 
00547         gmatrix temp ( Row,Col+v.Col );
00548         for ( i=0; i < Row; i++ )
00549         {
00550                 for ( j=0; j < Col; j++ )
00551                         temp.ValM[i][j] =ValM[i][j];
00552                 for ( k=0; k < v.Col; k++ )
00553                         temp.ValM[i][Col+k] = v.ValM[i][k];
00554         }
00555         for ( k=0; k < Row; k++ )
00556         {
00557                 int indx = temp.pivot ( k );
00558                 if ( indx == -1 )
00559                         REPORT_ERROR ( 0, "gmatrix::Solve(): Singular matrix!" );
00560 
00561                 a1 = temp.ValM[k][k];
00562                 for ( j=k; j < temp.Col; j++ )
00563                         temp.ValM[k][j] /= a1;
00564 
00565                 for ( i=k+1; i < Row; i++ )
00566                 {
00567                         a1 = temp.ValM[i][k];
00568                         for ( j=k; j < temp.Col; j++ )
00569                                 temp.ValM[i][j] -= a1 * temp.ValM[k][j];
00570                 }
00571         }
00572         gmatrix s ( v.Row,v.Col );
00573         for ( k=0; k < v.Col; k++ )
00574                 for ( int m=int ( Row )-1; m >= 0; m-- )
00575                 {
00576                         s.ValM[m][k] = temp.ValM[m][Col+k];
00577                         for ( j=m+1; j < Col; j++ )
00578                                 s.ValM[m][k] -= temp.ValM[m][j] * s.ValM[j][k];
00579                 }
00580         return s;
00581 }
00582 // ================================
00583 
00584 
00585  gvet & gmatrix::Get_Vcol(gvet &V)
00586  {  // restituisce il vettore V definito come la colonna 0 della matrice this.
00587  if ( Row < 3 )REPORT_ERROR ( 0, "gmatrix::Get_Vcol: Less than 3 rows!" );
00588   V.x= ValM[0][0];
00589   V.y= ValM[1][0];
00590   V.z= ValM[2][0];
00591  return V; 
00592  }
00593 //===================================================================
00594 // set this matrix to unity
00595 void gmatrix::Unit ()
00596 {
00597         if ( Row != Col )
00598                 REPORT_ERROR ( 0, "gmatrix::Unit: Non-square matrix!" );
00599 
00600         for ( int i=0; i < Row; i++ )
00601                 for ( int j=0; j < Col; j++ )
00602                         ValM[i][j] = i == j ? 1.0 : 0.0;
00603                 detrm=1.;
00604         return;
00605 }
00606 
00607 // calculate the norm of a matrix
00608 inline double gmatrix::Norm ()
00609 {
00610         double retVal = 0.0;
00611 
00612         for ( int  i=0; i < Row; i++ )
00613                 for ( int  j=0; j < Col; j++ )
00614                         retVal +=ValM[i][j] *ValM[i][j];
00615         retVal = sqrt ( retVal );
00616 
00617         return retVal;
00618 }
00619 //    private.............
00620 // calculate the condition number of a matrix
00621 inline double gmatrix::Cond ()
00622 {
00623         gmatrix inv = ! ( *this );
00624         return ( Norm() * inv.Norm() );
00625 }
00626 
00627 // Determine if the matrix is upper triangular
00628 inline bool gmatrix::IsUpperTriangular ()
00629 {
00630         if ( Row != Col )
00631                 return false;
00632         for ( int  i=1; i < Row; i++ )
00633                 for ( int  j=0; j < i-1; j++ )
00634                         if ( ValM[i][j] != 0.0 )
00635                                 return false;
00636         return true;
00637 }
00638 
00639 // Determine if the matrix is lower triangular
00640 inline bool gmatrix::IsLowerTriangular ()
00641 {
00642         if ( Row != Col )
00643                 return false;
00644 
00645         for ( int  j=1; j < Col; j++ )
00646                 for ( int  i=0; i < j-1; i++ )
00647                         if ( ValM[i][j] != 0.0 )
00648                                 return false;
00649 
00650         return true;
00651 }
00652 
00653 // Determine if the matrix is symmetric
00654 inline bool gmatrix::IsSymmetric ()
00655 {
00656         if ( Row != Col )
00657                 return false;
00658         for ( int i=0; i < Row; i++ )
00659                 for ( int j=0; j < Col; j++ )
00660                         if ( ValM[i][j] !=ValM[j][i] )
00661                                 return false;
00662         return true;
00663 }
00664 
00665 // Determine if the matrix is skew-symmetric
00666 inline bool gmatrix::IsSkewSymmetric ()
00667 {
00668         if ( Row != Col )
00669                 return false;
00670         for ( int i=0; i < Row; i++ )
00671                 for ( int j=0; j < Col; j++ )
00672                         if ( ValM[i][j] != -ValM[j][i] )
00673                                 return false;
00674         return true;
00675 }
00676 // Determine if the matrix is a unit matrix
00677 inline bool gmatrix::IsUnit ()
00678 {
00679         if ( IsScalar() &&ValM[0][0] == 1.0 )
00680                 return true;
00681         return false;
00682 }
00683 
00684 // Determine if this is a null matrix
00685 inline bool gmatrix::IsNull ()
00686 {
00687         for ( int i=0; i < Row; i++ )
00688                 for ( int j=0; j < Col; j++ )
00689                         if ( ValM[i][j] != 0.0 )
00690                                 return false;
00691         return true;
00692 }
00693 
00694 // calculate adjoin of a matrix
00695 inline gmatrix gmatrix::Adj ()
00696 {
00697         if ( Row != Col )
00698                 REPORT_ERROR ( 0, "gmatrix::Adj(): Adjoin of a non-square matrix." );
00699 
00700         gmatrix temp ( Row,Col );
00701 
00702         for ( int i=0; i < Row; i++ )
00703                 for ( int j=0; j < Col; j++ )
00704                         temp.ValM[j][i] = Cofact ( i,j );
00705         return temp;
00706 }
00707 
00708 // calculate the cofactor of a matrix for a given element
00709 inline double gmatrix::Cofact ( int row, int col )
00710 {
00711         int i,i1,j,j1;
00712 
00713         if ( Row != Col )
00714                 REPORT_ERROR ( 0, "gmatrix::Cofact(): Cofactor of a non-square matrix!" );
00715 
00716         if ( row > Row || col > Col )
00717                 REPORT_ERROR ( 0, "gmatrix::Cofact(): Index out of range!" );
00718 
00719         gmatrix temp ( Row-1,Col-1 );
00720 
00721         for ( i=i1=0; i < Row; i++ )
00722         {
00723                 if ( i == row )
00724                         continue;
00725                 for ( j=j1=0; j < Col; j++ )
00726                 {
00727                         if ( j == col )
00728                                 continue;
00729                         temp.ValM[i1][j1] =ValM[i][j];
00730                         j1++;
00731                 }
00732                 i1++;
00733         }
00734         double   cof = temp.Det();
00735         if ( ( row+col ) %2 == 1 )
00736                 cof = -cof;
00737 
00738         return cof;
00739 }
00740 
00741 // Determine if the matrix is singular
00742 inline bool gmatrix::IsSingular ()
00743 {
00744         if ( Row != Col )
00745                 return false;
00746         return ( Det() == 0.0 );
00747 }
00748 
00749 // Determine if the matrix is diagonal
00750 inline bool gmatrix::IsDiagonal ()
00751 {
00752         if ( Row != Col )
00753                 return false;
00754         for ( int i=0; i < Row; i++ )
00755                 for ( int j=0; j < Col; j++ )
00756                         if ( i != j &&ValM[i][j] != 0.0 )
00757                                 return false;
00758         return true;
00759 }
00760 
00761 // Determine if the matrix is scalar
00762 inline bool gmatrix::IsScalar ()
00763 {
00764         if ( !IsDiagonal() )
00765                 return false;
00766         double v =ValM[0][0];
00767         for ( int i=1; i < Row; i++ )
00768                 if ( ValM[i][i] != v )
00769                         return false;
00770         return true;
00771 }
00772 
00773 // =====
00774 void REPORT_ERROR ( int ko, const char * tit )
00775 {
00776         Gout<< "\nEv "<<evento_.Gen.Event<<" ERRORE: "<<tit<<endl;
00777         
00778         if ( ko<1 )  exit ( 0 );
00779 }
00780 
00781 
00782 
00783 
00784 
00785 
00786 
00787 
00788 
 All Classes Namespaces Files Functions Variables