Lesson 3: Matrix and array operations


The following matrix operations are available in MATLAB:
+ addition
- subtraction
* multiplication
^ power
' transpose
\ left division
/ right division

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

  • x = A\b is the solution of A*x = b
  • x = b/A is the solution of x*A = b
In left division, if A is square, then it is factored using Gaussian elimination and these factors are used to solve A*x = b. If A is not square, it is factored using Householder orthogonalization with column pivoting and the factors are used to solve the under- or over- determined system in the least squares sense. Right division is defined in terms of left division by b/A = (A'\b').

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] .^ 2
will yield [1,4,9,16]. Try it! This is particularly useful when using MATLAB graphics.