Linear Algebra / Unit 6, Orthogonality / Topic 6.1
Unit 6. Orthogonality
This topic finds the point of a line, or of a subspace, that is closest to a given vector. That point is called the projection of the vector. Projections are the basis of least squares in Topic 6.4, and of the rules for measurement in quantum mechanics.
You need Topics 1.2, 3.3, 4.4, and 5.1 for this topic.
Let a be a vector that is not the zero vector, and let b be any vector. The line through a is the set of all multiples of a. The projection of b onto this line is the multiple p = ca that is closest to b.
The closest point is the one for which the error e = b − p is perpendicular to the line. So a · (b − ca) = 0, which gives the number c.
c = (a · b)/(a · a) p = (a · b)/(a · a) aFor example, take a = (2, 1) and b = (3, 4).
a · b = (2)(3) + (1)(4) = 10the dot product of a and ba · a = (2)(2) + (1)(1) = 5the dot product of a with itselfp = 10/5 21 = 42the projectione = b − p = −12the errorCheck that the error is perpendicular to the line: (2, 1) · (−1, 2) = 0.
The vector b has been split into two perpendicular parts, b = p + e. The part p is along the line, and the part e is perpendicular to it. You have done this in physics when a weight is split into a component along an incline and a component perpendicular to it.
Try it: the projection onto a line
Drag the tip of the blue arrow to choose the line, and drag the red point to choose the vector b. The green arrow is the projection p, and the dashed purple segment is the error e. The error always meets the line at a right angle.
The projection is a linear map, so it has a matrix. Write the formula with the transpose, as in Topic 3.3: the number a · b is aTb, and the product aaT of a column and a row is a square matrix.
p = Pb with P = aaT/aTaFor a = (2, 1),
aaT = 21 21 = 4221a column times a rowP = 1/5 4221divide by aTa = 5P 34 = 1/5 2010 = 42the same projection as beforeThe matrix depends only on the line. Replacing a by 3a gives the same P.
Now let the subspace be the column space of a matrix A whose columns a₁, …, aₙ are independent. The projection p is a combination of the columns, so p = Ax̂ for some vector of coefficients, which is written x̂. The symbol is read “x hat”.
As for a line, the closest point is the one for which the error e = b − Ax̂ is perpendicular to the subspace. It must be perpendicular to each column of A, and these conditions together are AT(b − Ax̂) = 0.
The coefficients of the projection satisfy AT Ax̂ = ATb. These are called the normal equations.
The matrix AT A is square and symmetric. It has an inverse when the columns of A are independent. Solving the normal equations gives the three results.
x̂ = (AT A)⁻¹ATb p = Ax̂ P = A(AT A)⁻¹ATProject b = (3, 1, 4) onto the plane in ℝ³ that is spanned by a₁ = (1, 1, 0) and a₂ = (0, 1, 1).
A = 101101the two vectors as columnsAT A = 2112the dot products of the columns with each otherATb = 45the dot products of the columns with bThe normal equations are 2x + y = 4 and x + 2y = 5, with the solution x̂ = (1, 2).
p = 1 110 + 2 011 = 132the projection Ax̂e = b − p = 2−22the errorCheck that the error is perpendicular to both columns:
(2, −2, 2) · (1, 1, 0) = 2 − 2 + 0 = 0the first column(2, −2, 2) · (0, 1, 1) = 0 − 2 + 2 = 0the second columnThe formula for a line is the special case in which A has one column. Then AT A is the number a · a, and dividing by it replaces the inverse.
For the line in Part 2:
P² = 1/25 2010105P times PP² = 1/5 4221 = Pdivide each entry by 5tr P = 4/5 + 1/5 = 1the dimension of a lineThe set of all vectors that are perpendicular to each vector of a subspace is also a subspace. It is called the orthogonal complement of the subspace. Topic 4.4 gave two examples: the null space of a matrix is the orthogonal complement of its row space, and the left null space is the orthogonal complement of its column space.
Each vector b splits in exactly one way into a part p in the subspace and a part e in the orthogonal complement. The matrix P gives the first part, and the matrix I − P gives the second part, because e = b − Pb. The matrix I − P is the projection matrix of the orthogonal complement.
The two parts are perpendicular, so their lengths satisfy the Pythagorean theorem.
|b|² = |p|² + |e|²For the example of Part 3:
|b|² = 9 + 1 + 16 = 26the vector (3, 1, 4)|p|² + |e|² = (1 + 9 + 4) + (4 + 4 + 4) = 26the projection (1, 3, 2) and the error (2, −2, 2)In quantum mechanics, a measurement projects the state vector onto a subspace of eigenvectors, and the probability of each result is the square of the length of the projection. The equation above then says that the probabilities add to 1. Topic 9.2 develops this.
| Fact | Statement |
|---|---|
| Projection onto a line | p = ((a · b) / (a · a)) a |
| Projection matrix for a line | P = aaT / (aTa) |
| Normal equations | AT Ax̂ = ATb |
| Projection onto the column space of A | p = Ax̂, and P = A(AT A)⁻¹AT |
| Properties | P² = P and PT = P |
| Error | e = b − p is perpendicular to the subspace |
Work each problem on paper first. Then open the answer to check your work.
a · b = 3 + 28 = 31a · a = 9 + 16 = 25p = (31/25)(3, 4) = (3.72, 4.96)the projectione = (1, 7) − (3.72, 4.96) = (−2.72, 2.04)the error3(−2.72) + 4(2.04) = 0the check: the error is perpendicular to a
P = (1/2) 1111.
P(5, 1) = (1/2)(6, 6) = (3, 3)
a · a = 9P = 1/9 122244244aaT divided by a · atr P = (1 + 4 + 4)/9 = 1the dimension of a line
AT A = 1002ATb = (1, 8)x̂ = (1, 4)the solution of the normal equationsp = (1, 0, 0) + 4(0, 1, 1) = (1, 4, 4)the projectione = (0, −2, 2)the error
Check: e is perpendicular to (1, 0, 0) and to (0, 1, 1).
The eigenvalues are 1, 1, and 0.
The trace is 2, and the determinant is 0.
(I − P)² = I − 2P + P²multiply out(I − P)² = I − 2P + Pbecause P² = P(I − P)² = I − P
The instruction np.dot calculates a dot product. The code below calculates the projection of b = (3, 4) onto the line through a = (2, 1), and the error, as in Part 1 of this topic.
Python
The projection is (4, 2), and the error is (−1, 2). The last result is 0, so the error is perpendicular to the line.
Now find the projection in Practice Problem 1: the vector (1, 7) onto the line through (3, 4).
Python
The last result may be a number such as 8.9e-16 and not exactly 0. This is a very small rounding error.
The instruction np.outer multiplies a column by a row. For one vector with itself, it gives the square matrix aaT of Part 2.
Python
The matrix P has the rows 0.8, 0.4 and 0.4, 0.2. The second result is the projection (4, 2). The third result is P again, because projecting twice is the same as projecting once.
In the next box, change the vector so that P is the projection matrix for the line through (1, 2, 2), as in Practice Problem 3. The last line prints the trace.
Python
The code below solves the normal equations for the example of Part 3. The expression A.T is the transpose of A, the @ sign multiplies matrices and vectors, and np.linalg.solve solves a system.
Python
The coefficients are (1, 2), and the projection is (1, 3, 2). The last result is [0. 0.]: the error is perpendicular to both columns of A.
Now project the vector (1, 2, 6) onto the plane of Practice Problem 4, which is spanned by (1, 0, 0) and (0, 1, 1). The two vectors are the columns of A, and a matrix is typed by its rows.
Python
The code below builds P = A(ATA)⁻¹AT for the plane of Part 3. The instruction np.linalg.inv calculates an inverse. The instruction np.allclose compares two matrices and gives True when all of their entries agree, apart from rounding errors.
Python
The trace is 2, the dimension of the plane. The last two results are True: P² = P, and P is symmetric.
The instruction np.linalg.norm calculates the length of a vector, and two stars mean a power. The code below checks the equation of Part 5 for the example.
Python
Both results are 26, or very close to it.
This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.
Choose how your answers are checked
1. Find the projection p of b = (4, 2) onto the line through a = (1, 1).
a · b = 6a · a = 2c = 6/2 = 3divide the two dot productsp = 3a = (3, 3)the projection
2. For the same vectors, b = (4, 2) and a = (1, 1), find the error e = b − p.
e = (4, 2) − (3, 3) = (1, −1)the errore · a = 1 − 1 = 0the error is perpendicular to the line
3. Find the projection matrix P for the line through a = (1, 3). Write the four entries.
P = aaT / (aTa). The product aaT has the rows 1, 3 and 3, 9, and aTa = 10.
4. Which equation is true for each projection matrix P?
The projection of a vector that is already in the subspace is the vector itself. So projecting twice gives the same result as projecting once.
5. The matrix P projects onto a subspace of ℝ⁵ that has the dimension 3. Find the trace of P.
The eigenvalues of P are 1 for the 3 dimensions of the subspace and 0 for the 2 perpendicular dimensions. The trace is the sum of the eigenvalues, which is 3.
Next: Topic 6.2, Orthogonal Bases and the Gram-Schmidt Process