Prev | Up | Next

Constructors and destructor

The following constructors are available for the matrix class.

1. matrix ();
2. matrix (size_t nRow, size_t nCol);
3. matrix (size_t nRow, size_t nCol, const T& e);
4. matrix (size_t nRow, size_t nCol, const T* Array, MatArrayType aType = C_ARRAY);
5. matrix (size_t nRow, size_t nCol, const valarray<T>& vec);

6. matrix (const matrix<T>& m);
7. template <class X> matrix (const matrix<X>& m);

8. ~matrix ();

Constructs a matrix class object.

Parameter

nRow
Number of rows in the matrix.
nCol
Number of columns in the matrix.
e
Initialization value for all matrix elements.
Array
Address of an array of type T to initialize the elements of the matrix. The number of elements in the array must be at least equal to the number of elements in the matrix object, i.e., nRow X nCol.
aType
Memory layout of the array, i.e., it can be of "C" style (C_ARRAY) or Fortran style (FORTRAN_ARRAY). The default value for this parameter is C_ARRAY.
vec
Reference to a valarray class object to initialize the matrix elements. The size of the vec must be at least equal to the number of elements in the matrix object, i.e., nRow X nCol.
m
Reference to a matrix object to copy from.
m
Reference to a matrix object of type X to copy from.

  1. Constructs a matrix object with zero element. This constructor is provided only for constructing array of matrix objects. The size should always be provided for single matrix object because zero size matrix object can't be used any matrix operations except assignment operator.


  2. Constructs a matrix object of size nRow by nCol with uninitialized elements.


  3. Constructs a matrix object of size nRow by nCol with all elements initialized to the value of e.


  4. Constructs a matrix object of size nRow by nCol with elements initialized from the Array.


  5. Constructs a matrix object of size nRow by nCol with elements initialized from the valarray vec.


  6. Constructs a new matrix object by copying from an existing matrix object m.


  7. Constructs a matrix object from an existing matrix object of type X. The compiler must have support for member template for this constructor to work.


  8. Destroys a matrix object.


Examples
typedef techsoft::matrix<float>  fMatrix;
typedef techsoft::matrix<double> dMatrix;

typedef std::valarray<float>     fVector;
typedef std::complex<double>     dComplex;

typedef techsoft::matrix<dComplex> cdMatrix;

dMatrix m(3,3);                  // Constructs a 3 x 3 matrix
dMatrix m2(3,3,1.0);             // Constructs a 3 x 3 matrix with
                                 // elements initialized to 1.0
cdMatrix cm(4,4);                // Constructs a 4 x 4 matrix of type complex<double>

float fv[] = { 1.34f, 2.54f, 8.23f, 
               7.34f, -2.3f, 2.45f,
               -1.2f, 4.50f, 7.34f };

fMatrix mf( 3,3,fv);             // Constructs a matrix object from "C" array fv 
fMatrix mf2( 3,3,fv,techsoft::FORTRAN_ARRAY); // Constructs a matrix object from Fortran array fv 
fMatrix mf3 = mf;
fVector vf( fv,9);
fMatrix mf4( 3,3,vf);

dMatrix ma[5];                   // Constructs an array of matrix objects
for (size_t i=0; i < 5; i++)
{
   dMatrix temp( 4,4);           // Use a temporary matrix to read 
                                 // individual matrix elements in the array      
   temp.rand();                  // Initialize/read the matrix
   ma[i] = temp;                 // Copy it to a matrix element in the array
}
dMatrix md = mf;                 // Requires member template support
cdMatrix cm2 = m2;               // Requires member template support