Saturday, May 22, 2010

I want a C++ code for displaying a matrix in simple?

1. Filling a matrix with an arbitrary double or with random doubles





MAT *m_fill( MAT *A, double x)


/* MAT *m_random_fill( MAT *A ) */


{


int i, j;


for ( i = 0; i %26lt; A-%26gt;m; i++ ) for ( j = 0; j %26lt; A-%26gt;n; j++ )


{ A-%26gt;me[i][j] = x ; }


/* { A-%26gt;me[i][j] = m_random ; } */


return A;


}





2. Constructing a matrix





CWMatrix A( rows, columns ) ;





3. Filling a matrix with random elements





#include %26lt;stdlib.h%26gt;


void random_fill( CWMatrix %26amp;M )


{


int SIZE = M.GetRows() ;


for ( int r=0; r%26lt;SIZE; r++ ) for ( int c=0; c%26lt;SIZE; c++ ) { M[r][c]= drand48(); }


}





not quite sure exactly what your looking for or what platform you chosse to run this on, but these are basic examples of a matrix using c++ in a linux enviroment


No comments:

Post a Comment