Projection and Best Approximation
The projection of onto is
the shadow casts on the line through . What is left over, , is perpendicular to , and its length is the distance from to the line.
The coefficient is chosen to make the leftover perpendicular: forces . For and : , the shadow is , and the leftover has dot product with . Replacing by any nonzero multiple gives the same shadow: appears twice on top and twice below, so the scale cancels.
When has no solution, solve instead: is the projection of onto the column space — the best possible fit. Every regression line in statistics is this computation.
Why the normal equations: the vectors fill the column space of , and the closest of them to is the one whose error is perpendicular to that whole space — the projection idea again, one dimension up. Perpendicular to every column means , which rearranges to . If has independent columns, is invertible and the best fit is unique.
Fitting a constant to data minimizes ; the derivative vanishes at the mean, . Least squares generalizes the average — and orthogonality is why it works.
In matrix form this is and : one column, all ones. The normal equation reads , so again. The errors , that is , add to zero — the error vector is perpendicular to the column . The total squared error is , and no other constant does better.
Gauss invented least squares to find a lost asteroid (Ceres, 1801) — and today every regression, every GPS position fix (overdetermined satellite equations), and every curve fit in every lab runs the normal equations from this topic. Orthogonality is also why JPEG and MP3 work: signals are projected onto orthogonal cosine bases and the small components discarded.
Find the distance from the point to the line through the origin along .
Show the answerHide the answer
Project first. The coefficient is , so the shadow is . The leftover is ; check it is perpendicular to the line: ✓. The distance is its length: . Cross-check with the point-to-line formula for : ✓.
Orthogonal Bases and Gram–Schmidt
If are mutually orthogonal and nonzero, the projection of onto their span is the sum of the one-dimensional projections:
Gram–Schmidt manufactures such a basis: keep , then from each next vector subtract its projections onto the 's already built.
Orthogonality makes the pieces independent. To check that is perpendicular to , dot it with : every term with , , vanishes, and the term was built to cancel . So each coefficient can be found alone, with one dot product, instead of solving a system. Gram–Schmidt works for the same reason: subtracting the projections leaves exactly the part of the new vector perpendicular to everything before it, and the span never changes along the way.
Make , orthogonal. Keep . The projection of onto has coefficient .
Subtract it: . Check: ✓. Clearing the fraction, points the same way and is easier to use. To make the basis orthonormal, divide by the lengths and : and . Both still span the same plane as , because is a combination of and .
Write in the orthogonal basis . The three pairwise dot products are , so each coefficient is one dot product divided by one squared length.
Coefficients: , then , then . So . Check: ✓. For a basis that is not orthogonal this would be a system; here it is three independent one-line computations.
Project onto the plane spanned by and , which are orthogonal (). The coefficients are and .
So . The error is . Check it is perpendicular to the plane: ✓ and ✓. The distance from to the plane is .
The sum-of-projections formula needs orthogonality. The plane spanned by and is the -plane, so the projection of is . Adding the two separate projections instead gives — wrong, because the two directions overlap and the shared part is counted twice. Run Gram–Schmidt first (it turns into ), or solve the normal equations.
Apply Gram–Schmidt to , , and give an orthonormal basis for their span.
Show the answerHide the answer
Keep . The projection coefficient of is , so . Check: ✓. Normalize: and , so the orthonormal basis is , . The second vector is the "spread" of around its average — the same subtraction statistics calls centering.
Least Squares in Practice
To fit to points , , the normal equations with become
The residuals then satisfy and .
The two equations are the two orthogonality conditions: the residual vector is perpendicular to the column of -values and to the column of ones. The second one, divided by , says the line passes through the centroid of the data. Those two residual sums are also the fastest check on the arithmetic — if either is not zero, something went wrong.
Fit to . The sums: , , , , . So the normal equations are and .
Solve by Cramer's rule: the determinant is , so and . The line is . Residuals : . Checks: they sum to ✓, and ✓. The centroid is on the line: ✓.
The system , , has no solution (the first two force , and then ). Find the least-squares solution. , , so and .
Solve , : the determinant is , so and . The residual is . Check against both columns: ✓ and ✓. The smallest possible squared error is .
Faced with three equations in two unknowns, it is tempting to solve the first two exactly and ignore the third: . That fits two equations perfectly and misses the third by , a squared error of . The least-squares answer misses all three a little, with total squared error . Least squares spreads the error; dropping data concentrates it.
Find the least-squares line through , and check the residuals.
Show the answerHide the answer
Sums: , , , , . Normal equations: and . Subtracting, , so ; then , so . The line is . Residuals: , , . They sum to ✓, and ✓.
Proofs & Why It Matters
Seek the multiple of making the remainder orthogonal to : gives in one step.
This is also the closest point on the line: for any other multiple , Pythagoras gives .
The best minimizes , i.e. makes the closest point to in the column space. Closest means the error is orthogonal to every column of (else sliding along that column would shrink it — the projection argument again).
Orthogonality to all columns at once is , i.e. . Fitting a constant to data makes this one equation whose solution is the mean.
Going Deeper: Explanations & Worked Problems
The projection formula does more than find shadows — it splits any into two orthogonal pieces relative to a direction : the part along, , and the part across, , which is orthogonal to by construction. Pythagoras then bookkeeps the lengths: . The "across" length is the distance from the point to the line — that is where the point-to-line distance formula comes from. Iterating the split against several directions in turn is Gram–Schmidt: peel off the component along each previously built direction, keep what remains, normalize — manufacturing an orthogonal basis from any basis, one subtraction at a time.
Why that particular multiple: write the along part as and demand that the remainder be perpendicular to . Then , which has exactly one solution, — the formula is forced, not chosen. For and : , the along part is , the across part is , and the Pythagorean bookkeeping checks: .
Take and direction .
Step 1 — the coefficient: .
Step 2 — the along part: .
Step 3 — the across part: ; check orthogonality: ✓.
Step 4 — distance from to the line : the across length, — matching the point-to-line formula ✓.
Step 5 — Pythagoras audit: ✓. Five steps, three self-checks — the decomposition verifies itself.
Fit a line to the points , which do not lie on one line.
Step 1 — the (unsolvable) system: , , , i.e. , .
Step 2 — normal equations : compute and .
Step 3 — solve: and ; subtracting, , , then .
Step 4 — the fitted line predicts ; residuals sum to — as they must, since orthogonality of the error to the all-ones column is literally one of the normal equations.