Prev | Up | Next

Binary operators

The following non-member binary operators are available for the matrix class objects. If the sizes of the matrices do not conform and range checking is enabled, i.e., the constant RANGE_CHECK_ is defined, these operators may throw invalid_argument exception; otherwise, the behavior is undefined.

1. matrix<T> operator+ (const matrix<T>& m1, const matrix<T>& m2);
2. matrix<T> operator- (const matrix<T>& m1, const matrix<T>& m2);

3. matrix<T> operator* (const matrix<T>& m1, const matrix<T>& m2);
4. matrix<T> operator* (const matrix<T>& m, const T& e);
5. matrix<T> operator* (const T& e, const matrix<T>& m);

6. matrix<T> operator/ (const matrix<T>& m1, const matrix<T>& m2);
7. matrix<T> operator/ (const matrix<T>& m, const T& e);
8. matrix<T> operator/ (const T& e, const matrix<T>& m);

9. valarray<T> operator* (const matrix<T>& m, const valarray<T>& v);
10. valarray<T> operator* (const valarray<T>& v, const matrix<T>& m);

11. valarray<T> operator/ (const matrix<T>& m, const valarray<T>& v);
12. valarray<T> operator/ (const valarray<T>& v, const matrix<T>& m);

  1. Adds the matrix m1 and m2 and returns the resultant matrix.


  2. Subtracts the matrix m2 from m1 and returns the resultant matrix.


  3. Multiplies the matrix m1 by m2 and returns the resultant matrix.


  4. Multiplies the matrix m by e and returns the resultant matrix.


  5. Multiplies the matrix m by e and returns the resultant matrix.


  6. Performs a simulated division by multiplying the matrix m1 by the inverse of matrix m2, and returns the resultant matrix.


  7. Divides the matrix m by e and returns the resultant matrix.


  8. Performs a simulated division by multiplying the inverse of matrix m by e, and returns the resultant matrix.


  9. Multiplies the matrix m by the vector v and returns the resultant vector.


  10. Multiplies the matrix m by the vector v and returns the resultant vector.


  11. Performs a simulated division by multiplying the matrix m by the inverse of vector v, and returns the resultant vector.


  12. Performs a simulated division by multiplying the inverse of matrix m by the vector v, and returns the resultant vector.

Examples
typedef techsoft::matrix<double> Matrix;
typedef std::valarray<double>    Vector;

Matrix A(5,5), B(5,5);

A.rand();
B = A;

A += B;
B -= A;
B *= A;         
B /= A;         // B *= !A;

A *= 1.234;
B /= 2.34;

Matrix C = A * B - B;

Vector V(5), V2(5);

V = B[0];
V2 = V * A;
V2 = B / V;