Lesson 3The Dot Product and Matrix Multiplication
Math 20
September 24, 2007
Announcements
I Problem Set 1 is on the course web site. Due September 26.
I Problem Sessions: Sundays 6–7 (SC 221), Tuesdays 1–2 (SC116)
I My office hours: Mondays 1–2, Tuesdays 3–4, Wednesdays1–3 (SC 323)
The price of breakfast
Remember I eat two eggs, three slices of bacon, and two slices oftoast for breakfast. Then my breakfast can be summarized by theobject
b =
232
.
Suppose eggs cost $1.39 per dozen, bacon costs $2.49 per pound,and bread costs $1.99 per loaf. Assume a pound of bacon has 16slices, as does a loaf of bread. Then the price per “unit” ofbreakfast is
p =
1.39/122.49/161.99/16
=
0.120.160.12
QuestionHow much do I pay?
The price of breakfast
Remember I eat two eggs, three slices of bacon, and two slices oftoast for breakfast. Then my breakfast can be summarized by theobject
b =
232
.
Suppose eggs cost $1.39 per dozen, bacon costs $2.49 per pound,and bread costs $1.99 per loaf. Assume a pound of bacon has 16slices, as does a loaf of bread. Then the price per “unit” ofbreakfast is
p =
1.39/122.49/161.99/16
=
0.120.160.12
QuestionHow much do I pay?
Answer.The answer is
(0.12)(2) + (0.16)(3) + (0.12)(2) = 0.96.
My breakfast costs 96 cents.
In terms of the vectors
p =
0.120.160.12
b =
232
what have we done? We multiplied the components and addedthem.
Answer.The answer is
(0.12)(2) + (0.16)(3) + (0.12)(2) = 0.96.
My breakfast costs 96 cents.
In terms of the vectors
p =
0.120.160.12
b =
232
what have we done?
We multiplied the components and addedthem.
Answer.The answer is
(0.12)(2) + (0.16)(3) + (0.12)(2) = 0.96.
My breakfast costs 96 cents.
In terms of the vectors
p =
0.120.160.12
b =
232
what have we done? We multiplied the components and addedthem.
The dot product of vectors
DefinitionWe p, q be vectors in Rn. We define the dot product (or innerproduct) of p and q to be the scalar
p · q = p1q1 + p2q2 + · · ·+ pnqn.
Observations:
I The dot product of two vectors is a scalar.
I The vectors need to have the same length to multiply.
I The dot product is symmetric meaning p · q is always equalto q · p.
q·p = q1p1+q2p2+· · ·+qnpn = p1q1+p2q2+· · ·+pnqn = p·q
The dot product of vectors
DefinitionWe p, q be vectors in Rn. We define the dot product (or innerproduct) of p and q to be the scalar
p · q = p1q1 + p2q2 + · · ·+ pnqn.
Observations:
I The dot product of two vectors is a scalar.
I The vectors need to have the same length to multiply.
I The dot product is symmetric meaning p · q is always equalto q · p.
q·p = q1p1+q2p2+· · ·+qnpn = p1q1+p2q2+· · ·+pnqn = p·q
The dot product of vectors
DefinitionWe p, q be vectors in Rn. We define the dot product (or innerproduct) of p and q to be the scalar
p · q = p1q1 + p2q2 + · · ·+ pnqn.
Observations:
I The dot product of two vectors is a scalar.
I The vectors need to have the same length to multiply.
I The dot product is symmetric meaning p · q is always equalto q · p.
q·p = q1p1+q2p2+· · ·+qnpn = p1q1+p2q2+· · ·+pnqn = p·q
The dot product of vectors
DefinitionWe p, q be vectors in Rn. We define the dot product (or innerproduct) of p and q to be the scalar
p · q = p1q1 + p2q2 + · · ·+ pnqn.
Observations:
I The dot product of two vectors is a scalar.
I The vectors need to have the same length to multiply.
I The dot product is symmetric meaning p · q is always equalto q · p.
q·p = q1p1+q2p2+· · ·+qnpn = p1q1+p2q2+· · ·+pnqn = p·q
The dot product of vectors
DefinitionWe p, q be vectors in Rn. We define the dot product (or innerproduct) of p and q to be the scalar
p · q = p1q1 + p2q2 + · · ·+ pnqn.
Observations:
I The dot product of two vectors is a scalar.
I The vectors need to have the same length to multiply.
I The dot product is symmetric meaning p · q is always equalto q · p.
q·p = q1p1+q2p2+· · ·+qnpn = p1q1+p2q2+· · ·+pnqn = p·q
Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007
Page1of8
Another Example
Example
Let v =
1−14
and w =
220
. Then
v ·w
= 1 · 2 + (−1) · 2 + 4 · 0 = 0.
So vectors can have a zero inner product without either one beingzero.
Another Example
Example
Let v =
1−14
and w =
220
. Then
v ·w = 1 · 2 + (−1) · 2 + 4 · 0
= 0.
So vectors can have a zero inner product without either one beingzero.
Another Example
Example
Let v =
1−14
and w =
220
. Then
v ·w = 1 · 2 + (−1) · 2 + 4 · 0 = 0.
So vectors can have a zero inner product without either one beingzero.
Another Example
Example
Let v =
1−14
and w =
220
. Then
v ·w = 1 · 2 + (−1) · 2 + 4 · 0 = 0.
So vectors can have a zero inner product without either one beingzero.
Dot product and Length
If v =
(ab
), then
v · v
= a2 + b2 = ‖v‖2
Sometimes useful even if our vectors aren’t really physical innature.
Dot product and Length
If v =
(ab
), then
v · v = a2 + b2
= ‖v‖2
Sometimes useful even if our vectors aren’t really physical innature.
Dot product and Length
If v =
(ab
), then
v · v = a2 + b2 = ‖v‖2
Sometimes useful even if our vectors aren’t really physical innature.
Dot product and Length
If v =
(ab
), then
v · v = a2 + b2 = ‖v‖2
Sometimes useful even if our vectors aren’t really physical innature.
Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007
Page3of8
Orthogonality
v
w
v + w
If v and w make a right angle, then
‖v‖2 + ‖w‖2 = ‖v + w‖2
On the other hand,
‖v + w‖2 = (v + w) · (v + w)FOIL= v · v + 2v ·w + w ·w= ‖v‖2 + 2v ·w + ‖w‖2
So v and w are orthogonal (perpendicular) if v ·w = 0.
Sigma notation
p · q = p1q1 + p2q2 + · · ·+ pnqn =n∑
i=1
piqi
The symbol i is an index, a “variable” which takes all integervalues between 1 and n.
Who else could go for some flapjacks?
Ingredient Pancakes Crepes Blintzes
Flour (cups) 112
12 1
Water (cups) 0 14 0
Milk (cups) 112
14 0
Eggs 2 2 3Oil (Tbsp) 3 2 2
The yield for each recipe is 12.
Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007
Page6of8
Again, let’s look at the what we’ve done in terms of the matrix
A =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
and v =
abc
(whatever they are).
We essentially took the dot product of v with every row of A, thenformed the vectors whose components were that vector.
Again, let’s look at the what we’ve done in terms of the matrix
A =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
and v =
abc
(whatever they are).
We essentially took the dot product of v with every row of A, thenformed the vectors whose components were that vector.
Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007
Page7of8
The matrix-vector product
Definition
Let A = [aij ] be an m × n matrix and v =
v1
v2
. . .vn
a n-vector
(column vector). The matrix-vector product of A and v is the
vector Av =
w1
w2
. . .wm
, where
wk = ak1v1 + ak2v2 + · · ·+ aknvn =n∑
j=1
akjvj ,
the dots product of kth row of A with v.
Discussion
Dimensional considerations?
RemarkThe matrix-vector product Av is defined only when A is m × n andv is column vector in Rn. The result is in Rm.
Discussion
Dimensional considerations?
RemarkThe matrix-vector product Av is defined only when A is m × n andv is column vector in Rn. The result is in Rm.
Example
Let
A =
2 3−1 40 3
and v =
[2−1
]
Find Av.
Solution
Av =
2 · 2 + 3 · (−1)(−1) · 2 + 4 · (−1)
0 · 2 + 3 · (−1)
=
4− 1−2− 40− 3
=
1−6−3
.
Example
Let
A =
2 3−1 40 3
and v =
[2−1
]
Find Av.
Solution
Av =
2 · 2 + 3 · (−1)(−1) · 2 + 4 · (−1)
0 · 2 + 3 · (−1)
=
4− 1−2− 40− 3
=
1−6−3
.
Example
Let
A =
2 3−1 40 3
and v =
[2−1
]
Find Av.
Solution
Av =
2 · 2 + 3 · (−1)(−1) · 2 + 4 · (−1)
0 · 2 + 3 · (−1)
=
4− 1−2− 40− 3
=
1−6−3
.
Example
Let
A =
2 3−1 40 3
and v =
[2−1
]
Find Av.
Solution
Av =
2 · 2 + 3 · (−1)(−1) · 2 + 4 · (−1)
0 · 2 + 3 · (−1)
=
4− 1−2− 40− 3
=
1−6−3
.
Matrix product redefined
Another way to look at the product of a matrix and a vector isthis: The product of A and v is a linear combination of thecolumns of A using the components of v as coefficients.
(A linearcombination is a combination of scaling and adding vectors) So if
A =
2 3−1 40 3
and v =
[2−1
]
Av = a1v1 + a2v2
=
2−10
· 2 +
343
· (−1) =
4−20
+
−3−4−3
=
1−6−3
which is the same as above.
Matrix product redefined
Another way to look at the product of a matrix and a vector isthis: The product of A and v is a linear combination of thecolumns of A using the components of v as coefficients. (A linearcombination is a combination of scaling and adding vectors)
So if
A =
2 3−1 40 3
and v =
[2−1
]
Av = a1v1 + a2v2
=
2−10
· 2 +
343
· (−1) =
4−20
+
−3−4−3
=
1−6−3
which is the same as above.
Matrix product redefined
Another way to look at the product of a matrix and a vector isthis: The product of A and v is a linear combination of thecolumns of A using the components of v as coefficients. (A linearcombination is a combination of scaling and adding vectors) So if
A =
2 3−1 40 3
and v =
[2−1
]
Av = a1v1 + a2v2
=
2−10
· 2 +
343
· (−1) =
4−20
+
−3−4−3
=
1−6−3
which is the same as above.
Matrix product redefined
Another way to look at the product of a matrix and a vector isthis: The product of A and v is a linear combination of thecolumns of A using the components of v as coefficients. (A linearcombination is a combination of scaling and adding vectors) So if
A =
2 3−1 40 3
and v =
[2−1
]
Av = a1v1 + a2v2
=
2−10
· 2 +
343
· (−1) =
4−20
+
−3−4−3
=
1−6−3
which is the same as above.
Matrix product redefined
Another way to look at the product of a matrix and a vector isthis: The product of A and v is a linear combination of thecolumns of A using the components of v as coefficients. (A linearcombination is a combination of scaling and adding vectors) So if
A =
2 3−1 40 3
and v =
[2−1
]
Av = a1v1 + a2v2
=
2−10
· 2 +
343
· (−1) =
4−20
+
−3−4−3
=
1−6−3
which is the same as above.
Matrix Product
Suppose we are running HDS and we know that flat breakfast friedbatter concoction preferences change from house to house. Maybeit’s something like this:
Food Frosh Lowell Dunster Pforzheimer
Pancakes 70 60 50 40Crepes 20 30 30 30
Blintzes 10 10 20 30
Let B be the matrix above. Then we can get the house breakdownof ingredients for each class.
The amount of ingredients we need for the freshman class is
Ab1
=
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
The amount of ingredients we need for the freshman class is
Ab1 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
The amount of ingredients we need for the freshman class is
Ab1 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
The amount of ingredients we need for the freshman class is
Ab1 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2
=
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
The amount of ingredients we need for the freshman class is
Ab1 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
The amount of ingredients we need for the freshman class is
Ab1 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
The amount of ingredients we need for the freshman class is
Ab1 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70
2010
=
125
5110210270
That for the Lowell House is
Ab2 =
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
60
3010
=
1157.5
97.5210260
,
and so on.
Putting this together gives a matrix
[Ab1 Ab2 Ab3 Ab4
]=
125 115 110 105
5 7.5 7.5 7.5100 97.5 82.5 67.5210 210 220 230270 260 250 240
Matrix product, defined
DefinitionLet A be an m × n matrix and B a n × p matrix. Then the matrixproduct of A and B is the m × p matrix whose jth column is Abj .In other words, the (i , j)th entry of AB is the dot product of ithrow of A and the jth column of B. In symbols
(AB)ij =n∑
k=1
aikbkj .
Example
1.5 0.5 10 0.25 0
1.5 0.25 02 2 33 2 2
70 60 50 40
20 30 30 3010 10 20 30
=
125 115 110 105
5 7.5 7.5 7.5100 97.5 82.5 67.5210 210 220 230270 260 250 240
Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007
Page8of8
RemarkDimensional considerations again
: In order for A and B to bemultipliable, the number of columns of A has to be equal to thenumber of rows of B. The resulting matrix as the same number ofrows as A and the same number of columns as B.
Am×nBn×p = (AB)m×p
RemarkDimensional considerations again: In order for A and B to bemultipliable, the number of columns of A has to be equal to thenumber of rows of B. The resulting matrix as the same number ofrows as A and the same number of columns as B.
Am×nBn×p = (AB)m×p
RemarkDimensional considerations again: In order for A and B to bemultipliable, the number of columns of A has to be equal to thenumber of rows of B. The resulting matrix as the same number ofrows as A and the same number of columns as B.
Am×nBn×p = (AB)m×p
Example
Let
A =
2 3−1 40 3
and B =
[3 −11 2
]
Find AB.
Solution
2 3−1 40 3
[3 −11 2
]=
2 · 3 + 3 · 1 2 · (−1) + 3 · 2(−1) · 3 + 4 · 1 (−1) · (−1) + 4 · 2
0 · 3 + 3 · 1 0 · (−1) + 3 · 2
=
6 + 3 −2 + 6−3 + 4 1 + 80 + 3 0 + 6
=
9 41 93 6
Example
Let
A =
2 3−1 40 3
and B =
[3 −11 2
]
Find AB.
Solution
2 3−1 40 3
[3 −11 2
]=
2 · 3 + 3 · 1 2 · (−1) + 3 · 2(−1) · 3 + 4 · 1 (−1) · (−1) + 4 · 2
0 · 3 + 3 · 1 0 · (−1) + 3 · 2
=
6 + 3 −2 + 6−3 + 4 1 + 80 + 3 0 + 6
=
9 41 93 6
Conclusions
I The product of matrices and vectors have very usefulinterpretations in various models. That’s why they’re souseful.
I Next time we’ll make sure that certain manipulations we wantto do with these products are valid. In what ways are matrixproducts like the product of real numbers? Is it commutative?Associative? And so on.