Linear Algebra, Live
Strang §1.2 · Lengths and dot products

Length and the dot product

Slide 1 built vectors by stretching and adding. Now we measure them. The dot product takes two vectors and gives back one number: multiply the matching parts, then add. For 21 and 34 that is 2·3 + 1·4 = 10. This one number answers two everyday questions: how long is an arrow, and do two arrows meet at a right angle? It is also the small calculation inside multiplying a matrix by a vector (a matrix is a table of numbers; that is the next slide).

Lesson 1 · slide 2Dot product
v · w = v₁w₁ + v₂w₂     length ‖v‖ = √(v · v)
Key ideas
  1. v · w: multiply matching parts and add. The answer is a number, not a vector.
  2. Length: ‖v‖ = √(v · v). For 34 it is √25 = 5.
  3. v · w = 0 means v and w meet at a right angle (they are perpendicular).
  4. A unit vector has length 1. Divide any vector by its length to get one.

Multiply matching parts, then add

Line the two vectors up. Multiply the first parts, multiply the second parts, and add the results:

v = 21,   w = 34  →  v · w = 2·3 + 1·4 = 6 + 4 = 10

The order doesn't matter: w · v is also 10. Vectors with more parts work the same way, with more products to add:

123 · 456 = 1·4 + 2·5 + 3·6 = 4 + 10 + 18 = 32

Length

Dot a vector with itself. For v = 34, v · v = 3·3 + 4·4 = 25. That is the length squared. Why? The arrow is the long side of a right triangle whose other sides are 3 and 4, and Pythagoras says 3² + 4² = 5². So the length is

‖v‖ = √(v · v) = √25 = 5
Walk 3 across and 4 up. The straight arrow from start to end has length √(9 + 16) = 5.

In 3D, add one more square: ‖122‖ = √(1 + 4 + 4) = √9 = 3. A vector with length 1 is called a unit vector. To make one, divide v by its length: 34 / 5 = 0.60.8 (dividing by 5 means multiplying by 1/5).

Zero means a right angle

21 · −12 = −2 + 2 = 0. Draw the two arrows and they meet at a right angle. That is always true: v · w = 0 exactly when v and w are perpendicular.

w turns all the way around v. The dot product is positive while w points to the same side as v, zero at the two right angles, and negative while w points away.

The sign tells you more. Positive: the arrows point roughly the same way (angle under 90°). Negative: they point roughly opposite ways (angle over 90°). Strang turns this into an exact rule for the angle, v · w = ‖v‖ ‖w‖ cos θ (θ is the angle between the arrows), which lesson 5 uses.

A bigger example: a shopping bill

Bread costs 2 euros, milk 1 and apples 3. You buy 1 bread, 4 milk and 2 apples. Prices p = 213 and amounts q = 142. The bill is one dot product:

p · q = 2·1 + 1·4 + 3·2 = 2 + 4 + 6 = 12 euros

A shop with 5,000 products does exactly the same thing, with 5,000 products to add.

Next: A matrix is a table of numbers (next slide). Each row of a matrix, dotted with a vector, gives one number. Do that for every row and you have multiplied a matrix by a vector.

Examples

Example 1 · A negative dot product

Find 1−2 · 34. What does the sign say?

Show solutionHide solution
1·3 + (−2)·4 = 3 − 8 = −5

Negative, so the angle between the arrows is more than 90°.

Example 2 · Length and unit vector

Find the length of v = 68 and the unit vector in its direction.

Show solutionHide solution
‖v‖ = √(36 + 64) = √100 = 10
v / 10 = 0.60.8, and √(0.36 + 0.64) = 1 ✓

Example 3 · Make a right angle

Find c so that 1c is perpendicular to 42.

Show solutionHide solution
1c · 42 = 4 + 2c = 0  →  c = −2

So 1−2 meets 42 at a right angle.

Example 4

Are 123 and 30−1 perpendicular?

Show solutionHide solution

1·3 + 2·0 + 3·(−1) = 3 + 0 − 3 = 0. Yes, they meet at a right angle.

Example 5

Show that 34 and 4−3 are perpendicular and have the same length.

Show solutionHide solution

34 · 4−3 = 12 − 12 = 0, so they are perpendicular. Both lengths are √(9 + 16) = 5.

Exercise Change w to a nonzero vector that makes a right angle with v = (2, 1). The readout under the picture should show v · w = 0. Edit the code and press Run.
slide_2.py Loading Python…
1
Output · Ctrl+Enter runs
Press Run to execute this slide's code. Ctrl+Enter works too.

Enjoying lesson 1? Get the full course: all 8 lessons through the SVD and PCA, your progress saved lesson by lesson, every solution and 5 extra problems per lesson. $20 once, yours for life.

Questions and comments

Stuck on something, or found a mistake? Ask here and I'll answer. You sign in with GitHub.

The full course

From Ax = b to PCA, by running it

Lessons 1 to 3 are free. Finish all eight and you will be able to:

You get: all 8 lessons with Python labs · every worked example and solution · 5 extra problems per lesson · your progress tracked · answers to your questions · every future update.

$20 once · lifetime access
Continue to checkout →

Already a member? Log in to the course