Contents · Linear Algebra
Part 0 · Orientation
Part 1 · Vectors & Spaces
Part 2 · Matrices as Maps
Part 3 · Solving Systems
Part 4 · Orthogonality
- Orthogonality and Least Squares
Part 5 · Eigenvalues
Part 6 · Singular Value Decomposition
Part 7 · Spectral & Positive Definite
Part 8 · Numerical Linear Algebra
Part 4 · Orthogonality
Orthogonality and Least Squares
Most linear systems that come from real data have no exact solution: there are more equations than unknowns, and the measurements disagree. Orthogonality turns that failure into a well-posed question. Instead of solving exactly, we project onto what can actually reach and accept the leftover as error.
Orthogonality
Two vectors are orthogonal when their dot product vanishes,
Geometrically the angle between them is , and the Pythagorean law holds exactly: precisely when . A set of nonzero, mutually orthogonal vectors is automatically independent, which is what makes orthogonal directions such convenient coordinate axes.
Projecting onto a line
Let a line through the origin be spanned by a vector . Any splits uniquely as
The perpendicularity condition becomes , which we solve for the one scalar :
As a matrix, is the projection , which satisfies and (projecting a second time changes nothing).
Worked example. Project onto . Then and , so
Check the right angle: . The residual is perpendicular to the line, as it must be.
- b
- (2.10, 0.50)
- p
- (1.30, 1.30)
- r = b − p
- (0.80, -0.80)
- r · a
- -0.000
Drag the point b. Its projection p is the closest point on the line, and the residual r meets the line at a right angle, so r · a stays ~0.
Projecting onto a subspace
Replace the single direction by the columns of a matrix , taken as a basis for a subspace . Now , and the residual must be orthogonal to every column at once, i.e. :
When has independent columns, is invertible, so
The line formula is just the -column case: makes a scalar.
Least squares and the normal equations
When has no solution, lies outside the column space of . The least-squares choice is the that minimizes the squared error
Setting its gradient to zero reproduces exactly the same normal equations,
This is no coincidence: the minimizer makes the residual orthogonal to the column space, so is the closest point of to . Any other point in adds a component along the subspace, which by Pythagoras only lengthens .
Worked example. Take
The columns are orthogonal, so is diagonal:
Then and . Both columns are orthogonal to the residual: and , which confirms is the projection.
Orthonormal bases: Gram-Schmidt and QR
The algebra collapses when the basis is orthonormal, since then . Gram-Schmidt builds such a basis from any independent set by subtracting off the projection onto the directions already chosen, then normalizing. Collecting the results as the columns of (with ) and the coefficients in an upper-triangular gives the factorization . The normal equations then reduce to , solved by back-substitution with no matrix inverse and far better numerical behavior.1
Footnotes
-
Strang, Introduction to Linear Algebra (5th ed., 2016). ↩