Matrix multiplication is performed by the operator %*%; for example, execute the command A%*%B. However, this will only work if the two matrices have matching dimensions. The dim command calculates the dimensions of a matrix, where the first number indicates the number of rows and the second indicates the number of columns:
Here, we see that matrix and matrix have a matching dimension and so we can execute the following matrix multiplication:
-
-
-
When the dimensions of the matrices do not match, for example B%*%C, RStudio reports the message Error in B%*%C: non-conformable arguments.
Quiz 1: Matrix multiplication
For and as defined by A,B,C,D and E at the start of this worksheet, find
The result is
-
(A)
-
(B)
-
(C)
-
(D)
-
(E)