Arithmetic Operators 3

  • It is worth reiterating that the rules of matrix algebra apply only when working with two or more matrices e.g. you would not be able to subtract or add two matrices unless they are of the same size.
  • However, the rules are somewhat different when dealing with scalars. A scalar is a parameter that MATLAB does not consider to be a matrix.

(NB: MATLAB classifies parameters declared as single numbers as 1-by-1 matrices making them vectors. As seen in the previous section, a scalar could be formed by declaring a parameter as a dimension of a matrix).

  • Multiplying, adding or subtracting a scalar from a two-by-two matrix (for example) would affect each of the individual elements of the matrix. For example:

1

  • Exponentiation is carried out using the ^ operator. It works with two scalars or a combination of a matrix and a scalar; it yields an error if used between two matrices. A^2 is equivalent to A*A while 2^A is carried out using the eigenvalues and eigenvectors of A (a bit complicated and will not be covered):

2       3

CHECKPOINT: Dot your matrIces and cross your…maTrices.

To find the dot and cross products of matrices (as you would a vector) use the dot and cross commands respectively. As with doing these by hand, the matrices have to be of the same size for the calculations to be possible. The use of the commands is exemplified using two row and two square matrices below:

4    5

For the row matrices, MATLAB does the calculation as you would by hand. For the 3-by-3 matrices, it breaks the matrix into three columnar vectors and carries repeated calculations using the corresponding vectors.