So far, linear algebra has been about combining vectors: spans, bases and linear maps. None of that needed length or angle. But many real questions do: how far is a data point from a model, which vector in a subspace is closest to a given one, when do two directions meet at a right angle? This unit adds geometry to Rn, and it all starts with one simple product.
The inner product
Definition
Inner product (dot product)
For vectors u and v in Rn, the inner product is the number
u⋅v=uTv=u1v1+u2v2+⋯+unvn.
Multiply matching entries and add. The result is a scalar, not a vector. Writing it as uTv (a 1×n matrix times an n×1 matrix) is handy, because it lets you use matrix algebra on inner products.
The inner product has four properties you will use constantly. For all u,v,w in Rn and every scalar c:
u⋅v=v⋅u
(u+v)⋅w=u⋅w+v⋅w
(cu)⋅v=c(u⋅v)
u⋅u≥0, and u⋅u=0 only when u=0
Property 4 holds because u⋅u=u12+⋯+un2 is a sum of squares.
Length and distance
In R2, the Pythagorean theorem says the vector (a,b) has length a2+b2. That is exactly v⋅v, and the same formula works in any dimension.
Length and distance
The length (or norm) of v is ∥v∥=v⋅v=v12+⋯+vn2.
The distance between u and v is dist(u,v)=∥u−v∥.
Scaling a vector scales its length: ∥cv∥=∣c∣∥v∥. A vector of length 1 is a unit vector. Dividing a nonzero vector by its length, u=∥v∥v, gives the unit vector in the same direction. This is called normalizingv.
Worked example: Inner product, length and a unit vector
Let u=(1,−2,3) and v=(2,−1,2,4). Find u⋅u, ∥u∥, and the unit vector in the direction of v.
u⋅u=1+4+9=14, so ∥u∥=14.
For v (a vector in R4): ∥v∥=4+1+4+16=25=5. So the unit vector is
51v=(52,−51,52,54).
Check: 254+1+4+16=1.
Worked example: Distance between two points
Find the distance between u=(7,1) and v=(3,2).
u−v=(4,−1), so dist(u,v)=16+1=17.
Orthogonal vectors
When are u and v perpendicular? Geometrically, exactly when the distance from u to v equals the distance from u to −v. Expand both squared distances:
∥u−v∥2=∥u∥2+∥v∥2−2u⋅v,∥u+v∥2=∥u∥2+∥v∥2+2u⋅v.
These are equal exactly when u⋅v=0. That motivates the definition.
Orthogonality
Vectors u and v are orthogonal if u⋅v=0.
Pythagorean theorem:u and v are orthogonal if and only if ∥u+v∥2=∥u∥2+∥v∥2.
The zero vector is orthogonal to every vector, since 0⋅v=0.
u · v = 2(−1) + 1(2) = 0, so u and v meet at a right angle.Open in grapher →
Angles
More generally, the law of cosines in the plane spanned by u and v gives
u⋅v=∥u∥∥v∥cosθ,
where θ is the angle between the vectors. So cosθ=∥u∥∥v∥u⋅v. A positive inner product means an acute angle, a negative one means an obtuse angle, and zero means a right angle. In statistics, this cosine (for centered data) is the correlation coefficient.
Orthogonal complements
Definition
Orthogonal complement
If W is a subspace of Rn, its orthogonal complementW⊥ ("W perp") is the set of all vectors orthogonal to every vector in W.
Three facts make W⊥ easy to work with:
A vector is in W⊥ if and only if it is orthogonal to every vector in a spanning set of W. (By linearity, orthogonal to the spanning vectors means orthogonal to all their combinations.)
W⊥ is a subspace of Rn, and dimW+dimW⊥=n.
For any m×n matrix A: (RowA)⊥=NulA and (ColA)⊥=NulAT.
The last fact is just matrix multiplication read row by row: Ax=0 says each row of A has inner product 0 with x. So to find W⊥, put a spanning set of W into the rows of a matrix and find its null space.
Worked example: Finding an orthogonal complement
Let W=Span{(1,2,−1),(0,1,1)} in R3. Find a basis for W⊥.
Solve Ax=0 with A=[1021−11]. Row 2 gives x2=−x3. Row 1 gives x1=−2x2+x3=2x3+x3=3x3. With x3 free,
x=x33−11,so {(3,−1,1)} is a basis for W⊥.
Check: (1,2,−1)⋅(3,−1,1)=3−2−1=0 and (0,1,1)⋅(3,−1,1)=−1+1=0. Geometrically, W is a plane through the origin and W⊥ is its normal line. Note dimW+dimW⊥=2+1=3.
Common mistake
To be in W⊥, a vector must be orthogonal to every vector in the spanning set, not just one of them. Put all the spanning vectors into the rows of one matrix, so the null space handles every condition at once. And put them in the rows, not the columns: NulA is orthogonal to the rows of A.
Tip
Always check a claimed orthogonal vector by taking inner products. It takes seconds and catches most arithmetic slips.
Practice
Practice 1
Compute u⋅v for u=(3,−1,2) and v=(1,4,−2).
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 2
Find ∥v∥ for v=(1,−2,2,4).
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 3
Find the distance between u=(2,5,−1) and v=(−1,1,11).
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 4
Find the unit vector in the direction of v=(6,−2,3). Enter it as a triple.
Enter a point like (2, -3)
Practice 5
Find the value of k that makes (2,k,−3) and (4,1,k) orthogonal.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 6
Find the angle, in degrees, between u=(1,1,0) and v=(1,0,1).
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 7
Suppose ∥u∥=3, ∥v∥=4 and u⋅v=2. Find ∥u+v∥2.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 8
Let W=Span{(1,0,2),(0,1,−1)}. The complement W⊥ is a line. Find the vector in W⊥ whose third entry is 1.