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.
- Assigns the matrix m to the left-hand side matrix. The size of the matrices need not be equal.
- Assigns the value of e to all elements of the left-hand side matrix.
- 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.
- 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.
- 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.
- 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.
- 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.
- Multiplies all elements of the left-hand side matrix by e.
- 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;