W3L2 Notes - Matrix Multiplication
W3L2 Notes - Matrix Multiplication
(i) Product of two matrices: Suppose that A = [aij ] and B = [bjk ] are matrices such that A
is m × n and B is n × p so that the number n of columns of A matches the number n of
rows of B. The matrix product AB is defined and is m × p, that is, has the same number
of rows as A and the same number of columns as B. The (i, k) entry of AB is defined to
be the dot product of the ith row of A with the kth column of B in the following sense:
if we put C = AB and write C = [cik ] then
n
X
cik = ai1 b1k + ai2 b2k + . . . + ain bnk = aij bjk ,
j=1
that is, we multiply corresponding entries of the ith row of A with corresponding entries
of the kth column of B, in order, and add up. Note that we get a sum with n products
of scalars, as there are n elements in the ith row of A and in the kth column of B. As
indicated above, this can be abbreviated using Sigma notation.
AB , BC , (AB)C , A(BC) .
(iii) Noncommutativity of matrix multiplication: The commutative law fails for matrix multipli-
cation. Usually it is the case that
AB 6= BA (2)
when both products AB and BA are defined, and we say that matrix multiplication is
noncommutative. If A is m × n and B is p × q and both AB and BA are defined then
n = p and q = m, so that B is n × m, AB is m × m and BA is n × n. In this case, both
AB and BA are square matrices, and will have different sizes if m does not equal n, so
that the inequality (2) holds automatically. Even when A and B are square matrices of
the same size, the inequality (2) holds most of the time. In rare, but important cases,
when AB = BA, we say that A and B commute. Note that matrix addition is always
commutative.
1
(iv) Distributivity of matrix multiplication over matrix addition: Suppose that A and B are
matrices of the same size, so that we can form A+B, and that C is a matrix of compatible
size such that the product (A + B)C exists. Then
(A + B)C = AC + BC , (3)
that is, we can expand brackets in the usual way, known as right distributivity. If, on the
other hand, C is of compatible size such that the product C(A + B) exists. Then
C(A + B) = CA + CB , (4)
again expanding brackets in the usual way, but on the other side, known as left distribu-
tivity. Collectively, (3) and (4) are referred to as distributivity of matrix multiplication
over matrix addition.
(v) Scalars can be brought to the front: If λ is a scalar from the underlying field and A and B
are matrices of compatible sizes such that the product AB exists then
that is, we can move the scalar λ anywhere we like in the expression, either multiplying the
entire product, or multiplying each individual matrix before creating a matrix product.
Equation (5) says that scalars move about freely and, in particular, can always be brought
to the front of any expression involving matrix multiplication.
(vi) Transposition respects matrix addition and scalar multiplication: If A and B are matrices of
the same size and λ is any scalar then
that is, taking the transpose of a sum of matrices is the sum of the transposes, and
transposing a scalar multiple of a matrix is the same as taking the same scalar multiple
of the transpose.
(vii) Transposition reverses order of matrix multiplication: If A and B are matrices whose sizes
are compatible with forming the matrix product AB, then
(AB)T = B T AT ,
that is, taking the transpose of a matrix product is the same as taking the product of the
transposes, but in reverse order.
which are both 2 × 2 so that both matrix products AB and BA exist and are 2 × 2. Put
C = AB. To form C we take the dot product of each of the two rows of A by each of the
2
two columns of B, forming the four entries of C in their respective positions. To get the
(1, 1)-entry of C we multiply the first row of A by the first column of B, that is, form
3
1 −2 = 1(3) + (−2)(−1) = 3 + 2 = 5 .
−1
To get the (1, 2)-entry of C we multiply the first row of A by the second column of B,
that is, form
4
1 −2 = 1(4) + (−2)(−2) = 4 + 4 = 8 .
−2
To get the (2, 1)-entry of C we multiply the second row of A by the first column of B,
that is, form
3
−1 3 = (−1)(3) + 3(−1) = −3 − 3 = −6 .
−1
To get the (2, 2)-entry of C we multiply the second row of A by the second column of B,
that is, form
4
−1 3 = (−1)(4) + 3(−2) = −4 − 6 = −10 .
−2
Thus
1 −2 3 4 5 8
C = AB = = .
−1 3 −1 −2 −6 −10
Reversing the order of multiplication, we get
3 4 1 −2 3 − 4 −6 + 12 −1 6
BA = = =
−1 −2 −1 3 −1 + 2 2−6 1 −4
which is clearly different from the matrix product AB, demonstrating an example of (2),
noncommutativity of matrix multiplication.
2. For example, consider now the following oblong matrices:
0 1
1 2 3
A = 1 −1 and B = .
3 2 1
−2 2
Then A is 3 × 2 and B is 2 × 3. Hence AB is defined and is 3 × 3:
0 1 0+3 0+2 0+1 3 2 1
1 2 3
AB = 1 −1 = 1−3 2−2 3 − 1 = −2 0 2 .
3 2 1
−2 2 −2 + 6 −4 + 4 −6 + 2 4 0 −4
Further BA is defined and is 2 × 2:
0 1
1 2 3 0 + 2 − 6 1 − 2 + 6 −4 5
BA = 1 −1 = = .
3 2 1 0+2−2 3−2+2 0 3
−2 2
Not only do AB and BA contain different entries, but they are of different sizes, so
certainly AB 6= BA, another (typical) instance of (2), noncommutativity of matrix mul-
tiplication.
3
3. In the next example we work over the field Z2 = {0, 1}, so that entries of our matrices
can be 0 or 1. Note that, in Z2 arithmetic,
1+1 = 0.
Then, even though the rows and columns of A and B have four entries each, the dot
product of each row of A with each column of B is formed by multiplying respective
entries and adding up, and we quickly get
0 1
1 0 1 1 1 1 0 + 0 + 1 + 0 1 + 0 + 0 + 0 1 1
AB = = = .
0 1 0 1 1 0 0+1+0+0 0+1+0+0 1 1
0 0
By contrast, we have
0 1 0+0 0+1 0+0 0+1 0 1 0 1
1 1 1 0 1 1
1+0 0+1 1+0 1+1 1
1 1 0
BA = 1 = = .
0 0 1 0 1 1+0 0+0 1+0 1+0 1 0 1 1
0 0 0+0 0+0 0+0 0+0 0 0 0 0
Note that
A(BC) = (AB)C ,
an instance of (1), associativity of matrix multiplication. This is rather surprising, as
each extended calculation was quite different, and even involved intermediate matrices of
different sizes.
0A = 0 = A0 , (6)
in which the zero symbol has to be read in context. The zero on the far left of (6) is the
usual zero scalar. The zero in the middle of (6) is a zero matrix with the same dimensions
4
as A. The zero on the far right of (6) is also a zero matrix (not a scalar, if interpreted
formally), in fact, a square matrix with the same number of rows and columns, coinciding
with the number of columns of A. If A is m×n, then a more notationally accurate version
of (6) would be
0A = Om×n = On×n . (7)
For example, an instance of (7) would be the following:
0 0 0
1 2 3 0 0 0 1 2 3 0 0 0 .
0 = =
4 5 6 0 0 0 4 5 6
0 0 0
Note that the matrix product AB is not defined, because the number of columns of A
does not equal the number of rows of B. However, the matrix product BA is defined,
and we see that
0 2 1 2 3 8 10 12
BA = = .
3 −1 4 5 6 −1 1 3
Hence
T 8 −1
8 10 12
(BA)T = = 10 1
−1 1 3
12 3
Observe that
T 1 4 T
T 1 2 3 T 0 2 0 3
A = = 2 5 and B = = .
4 5 6 3 −1 2 −1
3 6
The matrix product B T AT is not defined. However the matrix product AT B T is defined,
and we see that
1 4 8 −1
T T 0 3
A B = 2 5 = 10 1 = (BA)T ,
2 −1
3 6 12 3
Reference: Easdown, D. (2011). A First Course in Linear Algebra. 3rd Edition. Pearson
Australia, Frenchs Forest, New South Wales.