Which point of a plane lies closest to a vector that sticks out of it? Which line comes closest to three measurements that do not fall on one line? How far can a solved coordinate be trusted when a sensor reads it at a millionth of the strength of the other one? All three are linear algebra problems, yet each asks something different. This workshop practices choosing between an exact solve, a projection and a least-squares fit, carrying out that choice, and then checking what the result shows, including whether the coefficients are unique and whether the data determine them reliably.
Key terms
Error criterion
Definition The error criterion of a problem is the quantity its answer must make zero or as small as possible, and it is fixed before any calculation. Three questions are common. An exact solve asks for with , and a solution exists exactly when lies in . A projection asks for the point of a given subspace of that minimizes the Euclidean distance . A least-squares fit first chooses a model, given by a design matrix whose columns span the possible predictions, and then minimizes the sum of squared residuals over coefficient vectors . At a minimizer the fitted vector is the projection of onto . A weighted criterion with positive weights minimizes
which is ordinary least squares after row of and the entry are multiplied by .
In plain words Decide what “best” means before computing anything. Different criteria ask different questions and can give different answers, and weights must come from a stated choice or a measurement model. Linear algebra solves the criterion you pick, but it cannot pick it for you.
Example Tuples such as stand for column vectors on this page, except for data points written . Fit a constant to two readings and , so the data are and the model column is . Unweighted least squares projects onto the line through and gives the mean . Now give the readings weights and . Scaling each equation by the square root of its weight gives the column and the data . The scaled residual must be perpendicular to , so
and . The two answers differ because the criteria differ, not because either calculation is wrong.
Projection onto a plane through its normal
Definition Let be a nonzero vector in , and let be the plane through the origin with normal . For in , the part of along is the residual, and the projection onto is what remains,
The point lies in , the residual is perpendicular to , and for every in
so is the unique closest point of to , at distance . The same formulas hold for a hyperplane in . A plane with misses the origin and is not a subspace, and for it is replaced by .
In plain words The normal points straight out of the plane. Remove the part of that points along the normal, and what is left lies in the plane and is as close to as possible. One projection onto a line replaces a projection onto a plane.
Example Project onto the plane . Its equation reads with . Since and ,
The coordinates of add to , so is in the plane, and is a multiple of , so it is perpendicular to the plane. The squared distance is .
Line fit to observations
Definition Given data points , a least-squares line is one that minimizes the sum of squared vertical residuals
where , , and the design matrix is the matrix whose row is . The minimizers are exactly the solutions of the normal equations
When at least two of the inputs differ, the columns of are independent, is invertible, and the line is unique.
In plain words Each data point gives one equation . With more points than unknowns the equations usually conflict, and the fit makes the vector of misses as short as possible.
Example Fit a line to the points , and . Here
The columns and are orthogonal, with squared lengths and , and their dot products with are and , so
The normal equations and give the line . Its predictions are , the residuals are , and the sum of squared residuals is .
Proportional design columns
Definition Suppose one column of a design matrix is a multiple of another, for some scalar . Then does not have full column rank, is singular, and the normal equations have infinitely many solutions. The fitted vector is still unique, because it is the projection of onto , but the coefficients are not. Two least-squares coefficient vectors differ by a vector of , such as when has these two columns only. In general the coefficients are unique exactly when has full column rank.
In plain words Two names for one direction do not give two degrees of freedom. The model still finds the best prediction, but it cannot say how to split it between the two coefficients.
Example Replace the line model by the columns and , with coefficients and , and keep . Every prediction has all three entries equal to , so the model can only fit a constant. The projection of onto the line through is the mean in every entry, so the fitted vector is , and every pair with is a least-squares solution, for example and . The normal equations
have a second row twice the first. The residual has squared length . The model lost the slope direction, and its constant predictions are also lines, so its error cannot be smaller than the of the line. It is larger here because the best line has slope , not .
Sensitivity to a changed measurement
Definition Let be an invertible matrix, viewed as a measurement map, with data and solution of . A change in the measurements changes the solution by , so
and when the relative change in is at most the condition number times the relative change in . The ratio reaches its largest value when is a nonzero multiple of , where is a unit input direction that stretches least. If the data are uncertain by about along the direction of , the solution is uncertain by about one unit along , however many digits are printed.
In plain words Change one reading by a realistic amount, solve again and compare. A large move in the answer means the data constrain that part of the solution only weakly.
Example Let be diagonal with entries and , and let , so . Change the second measurement to . The new solution is . The measurements moved by and the solution by , a factor of . In relative terms the data changed by about and the solution by , an amplification of about , below . Both solutions are exact, so the change comes from the data and not from the solver. The weakly measured direction is with , so if the second reading is uncertain by about , the second coordinate of the solution is not reliably known.
Checking the model and residual
Definition A projection or a fit is checked in the original problem. The answer must lie in the model space, so a projection must lie in and a fitted vector must have the form . The residual must be orthogonal to the model space in observation space, which for a fit means , one dot product for each design column. Membership and orthogonality are needed together. For the plane with normal , every point of passes the first test, and every point on the normal line through passes the second, but only passes both. The units must agree, with residuals in the units of the observations and each coefficient in the units that make its term match them. Finally, the rank of decides whether the coefficients are unique, and the sensitivity of the problem decides whether the data constrain them reliably.
In plain words Put the answer back into the question that was asked. A residual that is small but not perpendicular, or perpendicular in the wrong space, points to a mistake.
Example For the line above, the residual satisfies
so . This perpendicularity holds in the three-dimensional observation space, while in the scatter plot the residuals are vertical segments that need not meet the line at right angles. If is in seconds and in meters, then is in meters, in meters per second, each residual in meters and the sum of squared residuals is square meters. The two columns are nonzero and orthogonal, hence independent, so the coefficients are unique.
Check yourself
- Find the point of the plane closest to , and the distance between them.
Show the answer
This is a projection onto a plane through the origin with normal . With , we get and , so the residual is and the closest point is
Check that , so is in the plane, and that is a multiple of the normal. The distance is .
- Three readings are all taken at the same time , with values , and . Someone fits by least squares. Are and determined? Find the fitted values and every least-squares pair .
Show the answer
The design columns are and , which are proportional, so has rank and the coefficients are not unique. Every prediction equals , so the model fits a constant, and the best constant is the mean . The fitted vector is , and the least-squares pairs are exactly those with , for example and . Any two of them differ by a multiple of , a vector of . The residual has squared length . Readings at a single input cannot determine a slope, which is why the line model needs at least two distinct inputs.
- Fit to the points , , and , and check the residual. Then raise the last reading from to . How do the coefficients change?
Show the answer
The design matrix has rows for , and . The normal equations are
The determinant is , and solving gives and . The predictions are and the residual is . Its entries add to , and the input-weighted sum is , so . The sum of squared residuals is .
With the last reading , the right-hand side becomes and the solution is , . The change of in one reading moved the intercept by and the slope by . The coefficients depend linearly on the data, so the same change also comes from solving the normal equations with right-hand side , which gives .