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

test_Matrix.cpp

Ir a la documentación de este archivo.
00001 // test_Matrix.cpp  (C)  2004 adolfo@di-mare.com
00002 
00003 /** \file  test_Matrix.cpp
00004     \brief Este programita sirve para ver cómo funciona la matriz...
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 #include <iostream>  // cout
00013 #include <iomanip>   // setw(4)
00014 
00015 #if 1
00016     #include "Matrix.h"
00017 #else
00018     #include "Sparse_Matrix.h"
00019     #define Matrix Sparse_Matrix
00020 #endif
00021 
00022 using namespace Mx;
00023 using namespace std;
00024 
00025 /// Imprime por filas el valor de \c "M"
00026 template <class E>
00027 void print( const char* name, Matrix<E> & V ) {
00028     cout << endl << name << '[' << V.rows() << ',' << V.cols() << ']' << endl;
00029     for (unsigned i=0; i < V.rows(); ++i) {
00030         for (unsigned j=0; j < V.cols(); ++j) {
00031             cout << " " << setw(6) << V(i,j);
00032         }
00033         cout << endl;
00034     }
00035 }
00036 
00037 /// Programa que ejercita las principales funciones de las matrices
00038 int main() {
00039     const unsigned M = 5;
00040     const unsigned N = 8;
00041     unsigned i,j,k;
00042     char * above = new char [10];
00043     typedef Matrix<unsigned> Matrix_unsigned;
00044     Matrix<unsigned> V(M,N);
00045     char * below = new char [10];
00046 
00047     k = 0;
00048     for (i=0; i < V.rows(); ++i) {
00049         for (j=0; j < V.cols(); ++j) {
00050             V(i,j) = k++;        // V.operator() (i,j) = k++;
00051         }
00052     }
00053 
00054     Matrix<unsigned> A = V;
00055     assert( A == V );
00056     assert( A.same(A) );
00057     print("A", A);
00058 
00059     V.reSize(N,M);
00060     print("V", V);
00061 
00062     // k = 0;
00063     for (i=0; i < V.rows(); ++i) {
00064         for (j=0; j < V.cols(); ++j) {
00065             V(i,j) = k++;
00066         }
00067     }
00068 
00069     Matrix<unsigned> B;
00070     B = V;
00071     assert( B == V );
00072     print("B", B);
00073 
00074     Matrix_unsigned C = V;
00075     C = C + C;
00076     print("C", C);
00077 
00078     C = A - A;
00079     print("C", C);
00080     assert( isNull( C ) && ! isScalar( C ) );
00081     assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00082     assert( ! isSquare( C ) &&  ! isUnit( C ) );
00083     assert( ! isSymmetric( C ) );
00084 
00085     print("A", A);
00086 //  B.transpose();
00087     print("B", B);
00088     C = B * A;
00089     print("C", C);
00090     assert( ! isNull( C ) && isSquare( C ) );
00091     assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00092     assert( ! isUnit( C ) && ! isScalar( C ) );
00093     assert( ! isSymmetric( C ) );
00094 
00095     print("A", A);
00096     print("B", B);
00097     C = A * B;
00098     print("C", C);
00099     assert( ! isNull( C ) && isSquare( C ) );
00100     assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00101     assert( ! isUnit( C ) && ! isScalar( C ) );
00102     assert( ! isSymmetric( C ) );
00103 
00104     return 0;
00105 }
00106 
00107 // EOF: test_Matrix.cpp

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