Multiplying matrices and vectors
Vectors and matrices in arbitrary dimensions
We’ve dealt with two- and three-dimensional vectors (i.e., vectors in and ). We can generalize this concept to an arbitrary number of dimensions, say dimensions. We refer to an -dimensional vector as a vector in and write it as an n-tuple of numbers:
For example, is a vector in . (Don’t think there’s any practical use to dealing with dimensions higher than three? See this page for examples of why we often need to study for larger than 3.)
You can view a matrix simply as a generalization of a vector, where we arrange numbers in both rows and columns. Let’s keep the number of rows and columns arbitrary, letting be the number of rows and the number of columns. We refer to such a matrix as an matrix and write it as
You have seen example matrices earlier, such as a matrix.
Vectors as matrices
In many cases, we make our lives simpler by viewing a vectors as a special class of matrices. From looking at the above vector and matrix, the only apparent difference between vectors and matrices is that vectors have only one row while the matrices have multiple rows. However, there is one important twist (literally) that isn’t apparent above. When we view vectors as matrices, we actually view them as a rotated version of the standard form (equation (1)), writing an -dimensional vector as a column matrix
We often call an column vector, so use the terms “column vector” and “column matrix” synonymously. (Note that a column vector has many rows but only one column.)
Matrix-vector product
We define multiplication between a matrix and a vector (i.e., the matrix-vector product) only for the case when the number of columns in equals the number of rows in . So, if is an matrix (i.e., with column), then the product is defined for column vectors . If we let , then is an column vector. In other words, the number of rows in (which can be anything) determines the number of rows in the product .
The general formula for a matrix-vector product is
Although it may look confusing at first, the process of matrix-vector multiplication is actually quite simple. One takes the dot product of with each of the rows of . (This is why the number of columns in has to equal the number of components in .) The first component of the matrix-vector product is the dot product of with the first row of , etc. In fact, if has only one row, the matrix-vector product is really a dot product in disguise, as described here.
For example, if
and , then
Matrix-matrix product
Since we view vectors as column matrices, the matrix-vector product is simply a special case of the matrix-matrix product (i.e., a product between two matrices). Just like for the matrix-vector product, the product between matrices and is defined only if the number of columns in equals the number of rows in . In math terms, we say we can multiply an matrix by an matrix . (If happened to be 1, then would be an column vector and we’d be back to the matrix-vector product.)
The product is an matrix which we’ll call , i.e., . To calculate the product , we view as a bunch of column vectors lined up next to each other:
Then each column of is the matrix-vector product of with the respective column of . In other words, the component in the th row and th column of is the dot product between the th row of and the th column of . In math, we write this component of as .
I think an example makes the process clear. Let be the matrix
and be the matrix
Then,
Want more examples?