Multiplying matrices and vectors
Vectors and matrices in arbitrary dimensions
We’ve dealt with two- and three-dimensional vectors (i.e., vectors in R2 and R3). We can generalize this concept to an arbitrary number of dimensions, say n dimensions. We refer to an n-dimensional vector as a vector in Rn and write it as an n-tuple of numbers:
![]() | (1) |
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 m be the number of rows and n the number of columns. We refer to such a matrix as an m × n matrix and write it as
A = . |
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 n-dimensional vector as a n × 1 column matrix
x = . |
Matrix-vector product
We define multiplication between a matrix A and a vector x (i.e., the matrix-vector product) only for the case when the number of columns in A equals the number of rows in x. So, if A is an m × n matrix (i.e., with n column), then the product Ax is defined for n × 1 column vectors x. If we let Ax = b, then b is an m × 1 column vector. In other words, the number of rows in A (which can be anything) determines the number of rows in the product b.
The general formula for a matrix-vector product is
Ax = ![]() = . |
For example, if
A = ![]() |
| Ax | = ![]() ![]() | ||
= ![]() | |||
= . |
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 AB between matrices A and B is defined only if the number of columns in A equals the number of rows in B. In math terms, we say we can multiply an m × n matrix A by an n × p matrix B. (If p happened to be 1, then B would be an n × 1 column vector and we’d be back to the matrix-vector product.)
The product AB is an m×p matrix which we’ll call C, i.e., AB = C. To calculate the product B, we view B as a bunch of n × 1 column vectors lined up next to each other:
= ![]() |
+ ainbnj.
I think an example makes the process clear. Let A be the 2 × 3 matrix
A = ![]() |
B = . |
| AB | = ![]() ![]() | ||
= ![]() | |||
= ![]() | |||
= . |
Want more examples?




= 
![[ ]
1 - 1 2
0 - 3 1](matvecmult6x.png)
![[ ]
1 - 1 2
0 - 3 1](matvecmult7x.png)

![[ ]
2 ⋅ 1 - 1 ⋅ 1 + 0 ⋅ 2
2 ⋅ 0 - 1 ⋅ 3 + 0 ⋅ 1](matvecmult9x.png)
![[ ]
1
- 3](matvecmult10x.png)
= 
![[ ]
0 4 - 2
- 4 - 3 0](matvecmult14x.png)

![[ ]
0 4 - 2
- 4 - 3 0](matvecmult16x.png)

![[ ]
0 ⋅ 0 + 4 ⋅ 1 - 2 ⋅ 2 0 ⋅ 1 + 4 ⋅ (- 1) - 2 ⋅ 3
- 4 ⋅ 0 - 3 ⋅ 1 + 0 ⋅ 2 - 4 ⋅ 1 - 3 ⋅ (- 1) + 0 ⋅ 3](matvecmult18x.png)
![[ ]
0 + 4 - 4 0 - 4 - 6
0 - 3 + 0 - 4 + 3 + 0](matvecmult19x.png)
![[ 0 - 10 ]
- 3 - 1](matvecmult20x.png)