The following matrix operations are available in MATLAB:
These matrix operations apply to scalars (1-by-1 matrices) as well. If the sizes of the matrices are incompatible for the matrix operation, an error message will be generated, except in the case of scalar-matrix operations (for addition, subtraction, multiplication and division) in which case each entry of the matrix is operated on by the scalar.
The "matrix division" operations deserve special comment. If A is an invertible square matrix and b is a compatible column, respectively row vector, then
The matrix operations of addition and subtraction already operate entry-wise but the other matrix operations given above do not, they are matrix operations. It is important to observe that these other operations: *, ^, \, /, can be made to operate entry-wise by preceding them by a period. For example, either
[1,2,3,4] .* [1,2,3,4]or
[1,2,3,4] .^ 2will yield [1,4,9,16]. Try it! This is particularly useful when using MATLAB graphics.