57
Lesson 3 The 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 (SC 116) I My office hours: Mondays 1–2, Tuesdays 3–4, Wednesdays 1–3 (SC 323)

Lesson03 Dot Product And Matrix Multiplication Slides Notes

Embed Size (px)

Citation preview

Page 1: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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)

Page 2: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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?

Page 3: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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?

Page 4: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 5: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 6: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 7: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 8: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 9: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 10: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 11: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 12: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007

Page1of8

Page 13: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 14: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 15: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 16: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 17: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 18: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 19: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 20: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 21: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007

Page3of8

Page 22: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 23: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 24: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 25: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007

Page6of8

Page 26: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 27: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 28: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007

Page7of8

Page 29: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 30: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 31: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 32: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

.

Page 33: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

.

Page 34: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

.

Page 35: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

.

Page 36: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 37: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 38: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 39: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 40: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 41: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 42: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 43: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 44: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 45: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 46: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 47: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 48: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.

Page 49: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 50: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 51: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

Math 20 - September 24, 2007.GWBMonday, Sep 24, 2007

Page8of8

Page 52: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 53: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 54: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 55: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 56: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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

Page 57: Lesson03    Dot  Product And  Matrix  Multiplication Slides Notes

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.