Most of the usual arithmetic operators are overloaded (for operators concerning comparisons, see page Max, Min, Sort, Find). Here we only consider the operations within the same class and with scalars and comment only if necessary:
- matrix = matrix
- matrix += matrix
- matrix -= matrix
- matrix *= matrix (not possible in all classes)
- matrix %= matrix (
- Attention
- : this operator is used here as the Hadamard or componentwise prodcut [A%=B means a_ij=a_ij*b_ij for all i,j])
- - matrix
- matrix + matrix
- matrix - matrix
- matrix * matrix (the result may be in a differen matrix class)
- matrix % matrix (rarely implemented)
- transpose() and transpose(matrix)
- matrix += scalar (add scalar to each element of the matrix)
- matrix -= scalar (subtract scalar from each element)
- matrix *= scalar
- matrix /= scalar (scalar is not checked against being zero)
- matrix + scalar and scalar + matrix (add scalar to each element)
- matrix - scalar and scalar - matrix (subtract elementwise)
- scalar * matrix and matrix * scalar
- matrix / scalar (scalar is not checke against being zero)
Note that for efficiency reasons the version "+=", "-=" are often to be preferred over "+" and "-", because the compiler will otherwise generate several automic temporary matrix variables, which needs more memory and often entails more time spent in copying.