8.2 Matrix & Vector Multiplication

If \(\mathbf{A}\) is a (\(r \times q\)) matrix and \(\mathbf{B}\) is a (\(q \times c\)) matrix (Note: ncol(A) = nrow(B)!), then \(\mathbf{AB}\) is a (\(r \times c\)) matrix with \((i, j)\)th element \[(\mathbf{AB})_{ij} = \sum^q_{k=1}a_{ik}b_{kj}\] where \(a_{ik}\) is the element in the \(i\)th row and \(k\)th column of \(\mathbf{A}\) and \(b_{kj}\) is the element in the \(k\)th row and \(j\)th column of \(\mathbf{B}\).

Here, we say that \(\mathbf{A}\) is postmultiplied by \(\mathbf{B}\) and, equivalently, that \(\mathbf{B}\) is premultiplied by \(\mathbf{A}\). Here, the order matters!

A = matrix(c(1,2,3,4),nrow=2,ncol=2)
B = matrix(c(5,6,7,8),nrow=2,ncol=2)

A * B #element wise multiplication (not what you want....)
A %*% B #matrix multiplication

8.2.1 Properties

Here are some useful properties of matrices:

  1. Associative Property

\[ \mathbf{A}(\mathbf{B}\mathbf{C}) = (\mathbf{AB})\mathbf{C}\]

  1. Distributive Property

\[ \mathbf{A}(\mathbf{B} + \mathbf{C}) = \mathbf{AB} + \mathbf{AC}, (\mathbf{A} + \mathbf{B})\mathbf{C} = \mathbf{AC} + \mathbf{BC}\]

  1. Multiplicative Identity \[\mathbf{I_r A} = \mathbf{AI_c } = \mathbf{A}\] where \(\mathbf{I_r}\) is a \(r\times r\) matrix with 1’s along the diagonal and 0’s otherwise. Generally, we’ll drop the subscript and we’ll assume the dimension by its context.