ContentsChapter 1 · Linear algebra5 of 7

1.5

Dot products, angles and projections

In this chapter
  1. 1.1Vectors and linear combinations
  2. 1.2Span, basis and dimension
  3. 1.3Matrices as transformations
  4. 1.4Determinant, inverse and Ax = b
  5. 1.5Dot products, angles and projections
  6. 1.6Eigenvectors and eigenvalues
  7. 1.7Symmetric matrices and the SVD
Before you readTwo patients are vectors of features. How could one number say how similar they are?
Watch: Dot products and duality · 3Blue1Brown · Essence of Linear Algebra, ch. 9

The dot product multiplies matching entries and adds:

u⋅v=uTv=∑iuivi=∥u∥ ∥v∥cos⁡θ.u \cdot v = u^T v = \sum_i u_i v_i = \|u\|\,\|v\|\cos\theta.

Here uiu_i is the ii-th entry of uu and θ\theta is the angle between the vectors. The last form is the geometry: the dot product is positive when the angle is acute, zero when it is a right angle (the vectors are orthogonal), and negative when it is obtuse.

The norm (length) is ∥v∥=v⋅v\|v\| = \sqrt{v \cdot v} and for non-zero vectors the angle comes from cos⁡θ=u⋅v∥u∥∥v∥\cos\theta = \frac{u \cdot v}{\|u\|\|v\|} The zero vector has no direction, so its angle with anything is undefined.

For a non-zero uu the projection of vv onto uu is the point on the line through uu closest to vv

proj⁡uv=u⋅vu⋅u u.\operatorname{proj}_u v = \frac{u \cdot v}{u \cdot u}\, u.

The leftover v−proj⁡uvv - \operatorname{proj}_u v is orthogonal to uu Least squares is this idea in many dimensions: the best fit is the projection of the data onto what the model can reach.

u·v = 7‖u‖ = 4.12‖v‖ = 3.16angle = 57.53°projection = (1.65, 0.41)
Drag u and v. The dot product is positive for an acute angle, zero for a right angle and negative for an obtuse one. The purple arrow is the projection of v onto the line through u.
Recall
Give the geometric formula for u⋅vu \cdot v
Recall
What does u⋅v=0u \cdot v = 0 mean?
Recall
What is the projection of vv onto uu
Exercise
Find the angle between p=(1,0,2)Tp = (1, 0, 2)^T and q=(2,1,1)Tq = (2, 1, 1)^T in degrees to one decimal place.
Exercise
Project v=(2,0,1)Tv = (2, 0, 1)^T onto u=(1,2,2)Tu = (1, 2, 2)^T Give the three entries.