Review of Matrix Multiplication
We want to define the product of two matrices.
• We have just defined the product of an m × n matrix and an n × 1 matrix.
If A is an m × n matrix and B is an n × p matrix, then the product AB is
defined and is an m × p matrix.
Write B as
B = [ b1 b2 · · · bp ]
where b1 , ..., bp are n × 1 vectors.
We define
AB = [ Ab1 Ab2 · · · Abp ]
m×n
n×p
⇝
m×p
1 / 34
Review of Matrix Multiplication
B = [b1 · · · bp ]
Example
1 −3 4 2
2 0
1
1
0 1 −2
−3
0 5 −1
−1
0
1
2
1
2
=
0
0
−13
1
=
7
8
4×3
⇒
AB = [Ab1 · · · Abp ]
−3
0
1
5
−3 4
2
0
1
1
1 −2
−3
5 −1
1
− 32
−1
1
−2
1
2
0
0
3×2
4×2
⇝
4
−1
1
0
−2 1
−1 2
2 / 34
Review of Matrix Multiplication
B = [b1 · · · bp ]
⇒
AB = [Ab1 · · · Abp ]
Example
"
−1
5
1
2
#1
2 2
3
0
2
1
−1
− 12
5 "
1
2 =
2
4
1 × 12 + (−1) × 3 + 2 × 2
2 × 12 + 5 × 3 + 0 × 2
"
#
3
1
11
= 2
16 −3 20
"
=
−1
5
#1 "
2 2 1
3
0 2
2
−1
5
1 × 1 + (−1) × (−1) + 2 × (− 21 )
2 × 1 + 5 × (−1) + 0 × (− 21 )
# 1 "
2 1
−1
0 1 2
−2
# 5
2
2
0
4
#
1 × 5 + (−1) × 2 + 2 × 4
2×5+5×2+0×4
−1
5
3 / 34
Review of Matrix Multiplication
Example
1
2
The product
0
0
−3
0
1
5
4 2 3 0
1 −1 0 1
is not defined.
−2 1 2 −1
−1 0 1 −1
4×3
4×3 ⇝
/
• The number of columns of the first matrix is NOT equal to the
number of rows of the second matrix.
Remember the Rule :
m×n
n×p
⇝
m×p
Example.
If A is 7 × 4 and B is 4 × 3 then AB is defined and is a 7 × 3 matrix.
However, if A is 3 × 2 and B is 5 × 2 then AB is not defined!
4 / 34
Another method of calculation of AB
Product of m × n and n × p
The (i, j)-entry of AB is the product of the i-th row of A with the j-th
column of B.
r1
r2 h
AB = . c1
..
rm
c2
···
r1 · c1
i r2 · c1
cp = .
..
rm · c 1
r1 · c 2
r2 · c 2
..
.
rm · c 2
···
···
···
r1 · cp
r2 · cp
..
.
rm · c p
In other words, if A = [aij ] is m × n and B = [bij ] is n × p then the
(i, j)-entry of AB is
cij = ai1 b1j + ai2 b2j + · · · + ain bnj
"
2
−2
#"
−1 0
3 4
# "
2(0) + (−1)4
1
=
(−2)(0) + 3(4)
1
# "
2(1) + (−1)(1)
−4
=
(−2)(1) + 3(1)
12
#
1
1
5 / 34
Another method of calculation of AB
Product of m × n and n × p
The (i, j)-entry of AB is the product of the i-th row of A with the j-th
column of B.
r1
r
2 h
AB = . c1
..
rm
c2
···
r1 · c1
i r2 · c1
cp = .
..
rm · c 1
r1 · c 2
r2 · c 2
..
.
rm · c 2
···
···
···
r1 · cp
r2 · cp
..
.
rm · c p
In other words, if A = [aij ] is m × n and B = [bij ] is n × p then the
(i, j)-entry of AB is
cij = ai1 b1j + ai2 b2j + · · · + ain bnj
3
2
−1
−1 "
0
5
−2
0
−1
1
# (3)(0) + (−1)(−2)
5
= (2)(0) + (5)(−2)
1
(−1)(0) + (0)(−2)
−4 14
2
−10
3
15
=
0
1
−5
(3)(−1) + (−1)(1)
(2)(−1) + (5)(1)
(−1)(−1) + (0)(1)
(3)(5) + (−1)(1)
(2)(5) + (5)(1)
(−1)(5) + (0)(1)
6 / 34
Example
1
−2 h
−2
0
3
3
−2
i 4
4 =
0
−6
3
−6
0
9
4
− 8
0
12
However,
h
−2
3
1
i −2
4 =
0
3
/
7 / 34
Some Warnings
Sometimes AB is defined, but BA is not.
For example, if A is 3 × 2 and B is 2 × 4, then AB is defined (and it
is 3 × 4) but BA is not defined.
∗
∗
∗
∗ "
∗
∗
∗
∗
∗
∗
∗
∗
∗
∗
#
"
vs.
∗
∗
∗
∗
∗
∗
# ∗
∗
∗
∗
∗
∗
∗
∗
Sometimes AB and BA are defined but have different sizes.
For example, if A is 3 × 2 and B is 2 × 3 then AB is 3 × 3 whereas
BA is 2 × 2, so AB , BA.
∗
∗
∗
∗ "
∗ ∗
∗
∗ ∗
∗
# ∗ ∗
∗
= ∗ ∗
∗
∗ ∗
"
∗
∗
∗ whereas
∗
∗
# ∗
∗ ∗
∗
∗ ∗
∗
∗ "
∗
∗ =
∗
∗
#
∗
∗
8 / 34
Some Warnings (cont.)
Even if both AB and BA are defined and have the same size, we
might have AB , BA.
Example
"
#
"
#
1 −1
1 0
If A =
and B =
0 1
1 1
then
"
#"
1 −1 1
AB =
0 1 1
but
"
1
BA =
1
#"
0 1
1 0
# "
0
0
=
1
1
−1
1
#
# "
−1
1
=
1
1
−1
0
#
so
AB , BA.
9 / 34
Summary of today
If A is an m × n matrix and B is an n × p matrix, then the product
AB can be defined and is an m × p matrix.
m×n
n×p
⇝
m×p
The (i, j)-entry of AB is equal to the product of i-th row of A with
the j-th column of B.
r1
r h
2
AB = . c1
..
rm
c2
···
r1 · c1
i r2 · c1
cp = .
..
rm · c1
r1 · c2
r2 · c2
..
.
···
···
rm · c 2
···
r 1 · cp
r2 · cp
..
.
rm · cp
Another way to compute AB is using the following relation:
B = [c1 c2 · · · cp ]
⇒
AB = [Ac1 Ac2 · · · Acp ]
10 / 34