Página principal | Lista de namespace | Lista de componentes | Lista de archivos | Miembros del Namespace  | Miembros de las clases | Archivos de los miembros

Matrix_Lib.h

Ir a la documentación de este archivo.
00001 // Matrix_Lib.h Copyright (C) 2004  adolfo@di-mare.com
00002 
00003 /** \file  Matrix_Lib.h
00004     \brief Algunas propiedades para la clase \c Matrix
00005 
00006     \author Adolfo Di Mare <adolfo@di-mare.com>
00007     \date   2004
00008 
00009     - Why English names??? ==> http://www.di-mare.com/adolfo/binder/c01.htm#sc04
00010 */
00011 
00012 #ifndef   Matrix_Lib_h
00013 #define   Matrix_Lib_h
00014 
00015 namespace Mx {
00016 
00017 /// Retorna \c "true" si la matriz \c M[][] es una matriz cuadrada
00018 template <class Mat>
00019 bool isSquare( const Mat& M ) {
00020     return M.rows() == M.cols();
00021 }
00022 
00023 /// Retorna \c "true" si la matriz \c M[][] es una matriz diagonal
00024 template <class Mat>
00025 bool isDiagonal( const Mat& M ) {
00026     assert( "This code has not been tested" );
00027     if (M.rows() != M.cols()) {
00028       return false;
00029     }
00030     typename Mat::value_type ZERO = 0;
00031     for (unsigned i=1; i < M.rows(); i++) {
00032         for (unsigned j=0; j < i; j++) {
00033             if (M(i,j) !=  ZERO) {
00034                 return false;
00035             } else if (M(j,i) !=  ZERO) {
00036                 return false;
00037             }
00038         }
00039     }
00040     return true;
00041 }
00042 
00043 /// Retorna \c "true" si la matriz \c M[][] es escalar
00044 template <class Mat>
00045 bool isScalar( const Mat& M ) {
00046     assert( "This code has not been tested" );
00047     if ( ! isDiagonal( M ) ) {
00048         return false;
00049     }
00050     typename Mat::value_type S = M(0,0);
00051     for (unsigned i=1; i < M.rows(); i++) {
00052         if (M(i,i) != S) {
00053             return false;
00054         }
00055     }
00056    return true;
00057 }
00058 
00059 /// Retorna \c "true" si la matriz \c M[][] es unitaria
00060 template <class Mat>
00061 inline bool isUnit( const Mat& M ) {
00062     assert( "This code has not been tested" );
00063     typename Mat::value_type ONE = 1;
00064     return ( ONE == M(0,0) ? isScalar( M ) : false );
00065 }
00066 
00067 /// Retorna \c "true" si la matriz \c M[][] es nula
00068 template <class Mat>
00069 bool isNull( const Mat& M ) {
00070     assert( "This code has not been tested" );
00071     typename Mat::value_type ZERO = 0;
00072     for (unsigned i=0; i < M.rows(); i++) {
00073         for (unsigned j=0; j < M.cols(); j++) {
00074             if (M(i,j) != ZERO) {
00075                 return false;
00076             }
00077         }
00078     }
00079     return true;
00080 }
00081 
00082 /// Retorna \c "true" si la matriz \c M[][] es simétrica
00083 template <class Mat>
00084 bool isSymmetric( const Mat& M ) {
00085     assert( "This code has not been tested" );
00086     if (M.rows() != M.cols()) {
00087         return false;
00088     }
00089     for (unsigned i=1; i < M.rows(); i++) {
00090         for (unsigned j=0; j < i; j++) {
00091             if (M(i,j) != M(j,i)) {
00092                 return false;
00093             }
00094         }
00095     }
00096     return true;
00097 }
00098 
00099 /// Retorna \c "true" si la matriz \c M[][] es triangular superior
00100 template <class Mat>
00101 bool isUpperTiangular( const Mat& M ) {
00102     assert( "This code has not been tested" );
00103     if (M.rows() != M.cols()) {
00104         return false;
00105     }
00106 
00107     typename Mat::value_type ZERO = 0;
00108     for (unsigned i=1; i < M.rows(); i++) {
00109         for (unsigned j=0; j < i; j++) {
00110             if (M(i,j) != ZERO) {
00111                 return false;
00112             }
00113         }
00114     }
00115     return true;
00116 }
00117 
00118 /// Retorna \c "true" si la matriz \c M[][] es triangular inferior
00119 template <class Mat>
00120 bool isLowerTiangular( const Mat& M ) {
00121     assert( "This code has not been tested" );
00122     if (M.rows() != M.cols()) {
00123         return false;
00124     }
00125 
00126     typename Mat::value_type ZERO = 0;
00127     for (unsigned j=1; j < M.cols(); j++) {
00128         for (unsigned i=0; i < j; i++) {
00129             if (M(i,j) != ZERO) {
00130                 return false;
00131             }
00132         }
00133     }
00134     return true;
00135 }
00136 
00137 } // namespace Mx
00138 
00139 #endif // Matrix_Lib_h
00140 
00141 // EOF: Matrix_Lib.h

Generado el Wed Nov 14 13:47:09 2007 para Uso de Mx::Matrix: por  doxygen 1.3.9.1