Prev | Up | Next

Assignment and computed assignment operators

The following assignment and computed assignment operators are available for the matrix class objects.

1. matrix<T>& operator= (const matrix<T>& m);
2. matrix<T>& operator= (const T& e);
3. template <class X> matrix<T>& operator= (const matrix<X>& m);

4. matrix<T>& operator+= (const matrix<T>& m);
5. matrix<T>& operator-= (const matrix<T>& m);
6. matrix<T>& operator*= (const matrix<T>& m);
7. matrix<T>& operator/= (const matrix<T>& m);
8. matrix<T>& operator*= (const T& e);
9. matrix<T>& operator/= (const T& e);

Parameter

m
A matrix object.
e
A number of type T.

  1. Assigns the matrix m to the left-hand side matrix. The size of the matrices need not be equal.


  2. Assigns the value of e to all elements of the left-hand side matrix.


  3. Assigns the matrix m of type X to the left hand-side matrix. The compiler must have member template support for this operator to work.


  4. Adds the matrix m to the left-hand side matrix. The matrices must be equal in row and column size, otherwise this operator throws invalid_argument exception if range checking is enabled.


  5. Subtracts the matrix m from the left-hand side matrix. The matrices must be equal in row and column size, otherwise, this operator throws invalid_argument exception if range checking is enabled.


  6. Multiply the matrix m to the left-hand side matrix. The column number of left-hand side matrix must be equal to row number of right-hand side matrix, otherwise, this operator throws invalid_argument exception if range checking is enabled.


  7. Performs a simulated division by multiplying the inverse of the matrix m to the left-hand side matrix. The column number of left-hand side matrix must be equal to row number of right-hand side matrix, and the right-hand side matrix must be non-singular. This operator may throw invalid_argument or runtime_error exception.


  8. Multiplies all elements of the left-hand side matrix by e.


  9. Divides all elements of the left-hand side matrix by e.


Examples
typedef techsoft::matrix<double>    dMatrix;
typedef std::complex<double>        dComplex;
typedef techsoft::matrix<dComplex>  cdMatrix;

dMatrix A, B(3,3);
cdMatrix CA(3,3);

B.rand();
A = B;
A = 0.0;

CA = A;		// Requires member template support

CA += CA;

A *= 3.0;
A /= 2;

A -= B;
A *= B;
A /= B;