- Learn
- Mathematics
- University Math
- Linear Algebra 1
- Orthogonality, Projections and Least Squares
Orthogonality, Projections and Least Squares
IntermediateLesson 8 of 9 in Linear Algebra 1 Course
What you will learn
- Use the dot product to compute lengths, distances and angles in , decide when vectors are orthogonal, and describe the orthogonal complement of a subspace, including how the row space, column space and null spaces of a matrix fit together.
- Compute dot products, lengths and distancesCalculate the dot product of two vectors, use it to find lengths, unit vectors and distances, and apply its algebraic rules.
- Test orthogonality and find angles between vectorsDecide whether two vectors are orthogonal, use the Pythagorean theorem for vectors, and compute the angle between nonzero vectors from their dot product.
- Describe orthogonal complements and the fundamental subspacesFind all vectors orthogonal to a subspace, and use the facts that the null space of a matrix is the orthogonal complement of its row space and that the null space of is the orthogonal complement of its column space.
- Compute dot products, lengths and distances
- Recognize orthogonal and orthonormal sets, find coordinates in an orthogonal basis without solving a system, and use matrices with orthonormal columns, which preserve lengths and angles.
- Find coordinates in an orthogonal basisCheck that a set of vectors is orthogonal, explain why nonzero orthogonal vectors are independent, and compute the weights of a vector in an orthogonal basis with dot products.
- Work with orthonormal bases and orthogonal matricesNormalize an orthogonal basis, recognize matrices with orthonormal columns by , and use the facts that such matrices preserve lengths and dot products and that a square one has inverse .
- Find coordinates in an orthogonal basis
- Split a vector into a part in a subspace and a part orthogonal to it, find the closest point of the subspace and the distance to it, and represent projections by matrices.
- Project a vector onto a lineFind the orthogonal projection of a vector onto the line spanned by a nonzero vector, the component orthogonal to that line, and the distance from the vector to the line.
- Project onto a subspace and find the closest pointUse the orthogonal decomposition theorem with an orthogonal basis to project a vector onto a subspace, and use the best approximation theorem to find the closest point and the distance to the subspace.
- Write projections as matricesBuild the matrix that projects onto a subspace from an orthonormal basis or from any basis, and use the properties and .
- Project a vector onto a line
- Turn any basis of a subspace into an orthogonal or orthonormal basis with the Gram–Schmidt process, and record that process as the factorization of a matrix with independent columns.
- Apply the Gram–Schmidt processProduce an orthogonal basis from a given basis step by step, normalize it, and recognize what happens when the given vectors are dependent.
- Factor a matrix as A = QRWrite a matrix with linearly independent columns as , with having orthonormal columns and upper triangular, compute , and explain what the factors are used for.
- Apply the Gram–Schmidt process
- When has no solution, find the vectors that make as close as possible to , using the normal equations, orthogonal columns or a QR factorization, and judge when the answer is unique.
- Solve least-squares problems with the normal equationsExplain what a least-squares solution is, derive and solve the normal equations, compute the least-squares error, and decide whether the solution is unique.
- Use orthogonal columns and QR for least squaresFind least-squares solutions directly when the columns of are orthogonal, solve when , and explain why numerical software prefers QR.
- Solve least-squares problems with the normal equations
- Set up a design matrix for data, find the least-squares line, parabola or multi-variable model, interpret residuals and coefficients, and recognize the limits of a fitted model.
- Fit a least-squares lineWrite a line fit as a least-squares problem , solve its normal equations, and interpret the coefficients and residuals.
- Fit curves and models with several predictorsBuild design matrices for general linear models such as parabolas and models with several input variables, solve them by least squares, and recognize when a fit is unique or misleading.
- Fit a least-squares line
Orthogonality, Projections and Least Squares study guide
1Measure vectors with the dot product
A list of coordinates can describe an arrow in the plane or a point in a space with many dimensions. The dot product gives those lists a geometry: length, distance, angle, and perpendicularity become calculations. Orthogonal complements then connect that geometry to the subspaces you already know, explaining why a homogeneous matrix equation can describe every direction perpendicular to a given space.
1.1 Dot products, lengths, and distances
The dot product combines two vectors with the same number of entries into one number. It is the inner product used in real coordinate spaces. Multiply matching entries, then add all the products.
Turn coordinates into a scalar
For and ,
The transpose turns a column into a row, so this matrix product has size . The dot product is read as a scalar. Keeping just the list of entrywise products would leave the calculation unfinished. Vectors of different sizes have no dot product with each other.
Take and . Their dot product is . The signs belong to the entries being multiplied.
Use the algebraic rules
The dot product is symmetric: . It distributes over addition, and a scalar can be pulled outside:
Also, , with equality exactly when . These rules allow familiar expansions, such as
Find length and direction
The norm, or length, is . Squaring and adding makes every entry contribute nonnegatively; the square root converts squared length back to length. For the example, and .
A unit vector has length 1. Normalize a nonzero vector by dividing every entry by its length. Thus points in the same direction as . The zero vector cannot be normalized, because its length is zero.
Scaling obeys . A negative multiplier reverses direction, but length stays nonnegative: .
Measure separation
The displacement between two vectors is their difference. Therefore . Here , so the distance is . Reversing the subtraction changes the displacement's direction, not its length.
Lengths do not generally add. Here has length , while the separate lengths total about 8.10. The rule that always holds is the triangle inequality: .
Key Takeaways
- The dot product is a scalar: multiply matching entries and add.
- Length is ; distance is .
- Normalize a nonzero vector by dividing by its length.
- Scaling changes length by the absolute value of the scalar.
- The triangle inequality bounds the length of a sum.
1.2 Orthogonality and angles
Two vectors are orthogonal when their dot product is zero. In the plane and in three-dimensional space, this expresses perpendicularity. The same test works in spaces with more coordinates, even when a picture is unavailable.
Check perpendicularity with a dot product
Write when . For and , the calculation is . Both vectors are nonzero. Unlike a product of real numbers, a zero dot product does not force one of its factors to be zero.
The zero vector is orthogonal to every vector. It is also the only vector orthogonal to itself, because forces every entry to vanish. An angle involving the zero vector is undefined, so the angle formula below requires both vectors to be nonzero.
Connect the test to the Pythagorean theorem
Expanding squared length gives
The middle term vanishes exactly when the vectors are orthogonal. Thus
For the example, the squared lengths are 6 and 3. The sum is , whose squared length is 9, as required. Expanding the difference changes the middle term's sign: . The sum and difference have equal lengths precisely when the dot product is zero.
Find an angle
For nonzero vectors, the angle in the range satisfies
The Cauchy–Schwarz inequality, , keeps this quotient between −1 and 1. Use inverse cosine after computing the quotient; choose degree or radian mode to match the answer required.
For and , the dot product is 1 and each length is . Hence and . For and , the quotient is , giving .
Read the sign before calculating
A positive dot product puts the angle in . A negative dot product puts it in . A zero dot product gives exactly for nonzero vectors. Same-direction multiples have angle 0°; opposite-direction multiples have angle 180°.
In the plane, is orthogonal to because . Parallel vectors need a different test: and are parallel but have dot product 10, so they are not orthogonal.
Key Takeaways
- Orthogonality means a zero dot product, including when one vector is zero.
- The Pythagorean identity holds exactly for orthogonal vectors.
- Use for nonzero vectors.
- The sign of the dot product locates the angle relative to 90°.
1.3 Orthogonal complements and matrix spaces
Being perpendicular to one direction gives one linear condition. Being perpendicular to a whole subspace gives a system of conditions. Its solutions form the orthogonal complement, another subspace in the same ambient space.
Find every perpendicular vector
For , the complement contains all vectors orthogonal to every vector in . It is enough to test a spanning set. If for every spanning vector, then
For , write an unknown vector as . Its one condition is . Set and ; then
Thus is a plane with the displayed two-vector basis. Checking one perpendicular vector would establish only that vector's membership, not describe the whole complement.
Account for dimensions
Every subspace satisfies . A line in has a two-dimensional complement. A plane through the origin has a one-dimensional complement. At the extremes, and .
Also, : a vector in both would be perpendicular to itself. Taking the complement twice returns the original space: .
Read matrix equations geometrically
For an matrix , each entry of is a row of dotted with . Therefore
Apply the same statement to the transpose to obtain
Keep those ambient spaces separate when the matrix is rectangular. The left null space is another name for .
For , solving gives . The checks against the two rows are and . Rank 2 plus nullity 1 equals the number of columns, 3.
Distinguish orthogonal subspaces from intersecting planes
Two subspaces are orthogonal when every vector in one is perpendicular to every vector in the other. The coordinate - and -planes are not orthogonal subspaces: both contain , which is not perpendicular to itself. Their perpendicular appearance as surfaces is a different geometric statement.
For least squares, the residual lies in . Its orthogonality to the column space becomes the equation .
Key Takeaways
- Test a spanning set to find every vector in .
- and .
- The row space and null space are orthogonal complements in .
- The column space and left null space are orthogonal complements in .
- Orthogonal subspaces share only the zero vector.
- A least-squares residual lies in .
2Read vectors in orthogonal bases
A basis gives coordinates, but an orthogonal basis makes each coordinate accessible through one dot product. Normalizing the basis removes even the division by squared length. These calculations lead to matrices with orthonormal columns, which keep lengths and angles intact, and to the special square case whose inverse is simply its transpose.
2.1 Coordinates in perpendicular directions
An orthogonal set has zero dot product between every pair of distinct vectors. To verify three vectors, check three pairs; four vectors require six checks. The lengths can differ, and the definition of an orthogonal set even allows the zero vector.
Why nonzero orthogonal vectors are independent
Suppose for an orthogonal set of nonzero vectors. Dot with . Every term from another vector vanishes, leaving . Since the squared length is positive, . This works for every coefficient, proving independence.
Such a set is an orthogonal basis for its span. In particular, three nonzero mutually orthogonal vectors in form a basis of the whole space. Including the zero vector would destroy independence, even though pairwise orthogonality could still hold.
Isolate one coordinate at a time
If belongs to the span of an orthogonal basis, write . Dotting with isolates just its coefficient:
The denominator is the squared length. Dividing by the length alone generally gives the wrong weight. This calculation avoids row reduction because perpendicular directions do not contribute to one another's dot products.
Recover a vector from its weights
Use , , and . Their pairwise products are zero, and their squared lengths are 3, 2, and 6.
For , the numerators are , , and . Therefore , , and . Reconstructing gives
The coordinate vector relative to this ordered basis is . Its entries are weights, not the original entries of . Reordering the basis reorders the weights.
Check the basis before using the shortcut
Independence alone is insufficient for the quotient formula. For the basis and target , the actual weights solve and . Thus they are 1 and 2.
The dot-product quotients would instead give 3 and . Their weighted sum is , which fails to reconstruct the target. The nonzero dot product between the basis vectors allows one direction to affect the other's equation. Use a linear system for such a basis, or first make it orthogonal.
When the target lies outside the span
Each term is a projection onto a perpendicular line. If is outside the basis's span, the same sum belongs to the span but cannot equal . It gives the orthogonal projection of onto that subspace, its closest point there.
Key Takeaways
- Nonzero mutually orthogonal vectors are independent.
- An orthogonal basis gives .
- The denominator is squared length, and the formula requires orthogonality.
- Weights reconstruct the target exactly when the target belongs to the span.
2.2 Orthonormal columns and orthogonal matrices
An orthonormal set is an orthogonal set whose vectors all have length 1. Normalize each vector of an orthogonal basis separately to obtain an orthonormal basis of the same space. Normalizing arbitrary nonorthogonal vectors changes their lengths but does not make them perpendicular.
Coordinates become dot products
The basis becomes
For an orthonormal basis the coordinate formula simplifies to . With , the first weight is . Multiplying it by gives , the same vector contribution as before normalization. Changing the scale of a basis vector changes its weight.
Test all columns at once
Let have columns in . Entry of is the dot product of columns and . Thus
holds exactly when the columns are orthonormal: unit squared lengths on the diagonal, zero cross-products elsewhere.
For , this identity gives
Taking proves . Lengths, dot products, and angles between nonzero vectors are preserved, including when the output space has more dimensions.
The square case has an easy inverse
A square matrix with orthonormal columns is an orthogonal matrix. It satisfies , so its rows are orthonormal too. Its determinant is 1 or −1. Rotations about the origin and reflections across lines through the origin give examples in the plane.
For , each column has squared length and their dot product is . For , multiplication gives . Both squared lengths equal 125.
Keep rectangular matrices separate
For a tall matrix, does not make . With columns and ,
This projects onto the column plane. The tall matrix has no two-sided inverse and is not called an orthogonal matrix.
Even a square matrix with perpendicular columns needs normalization. For , , so . Dividing by makes it orthogonal.
Key Takeaways
- Orthonormal vectors are perpendicular unit vectors.
- Orthonormal coordinates are dot products with the basis vectors.
- tests orthonormal columns.
- Such a matrix preserves lengths, angles, and dot products.
- A square orthogonal matrix has inverse and determinant ±1.
- For a tall matrix, is a projection, not the identity.
3Find the closest vector in a subspace
Projection splits a vector into a part you can represent in a chosen subspace and a perpendicular remainder. That remainder measures the distance to the subspace. Start with one line, add perpendicular basis directions to handle a larger space, and then write the calculation as a matrix that works for every input vector. The closest-point claim follows from the Pythagorean theorem.
3.1 Projection onto a line
To project onto a line through the origin, find the point on the line whose displacement from is perpendicular to it. Let the line be , where . Every possible point has the form .
Derive the coefficient
Set and require the residual to be orthogonal to . Then
The positive denominator gives
The coefficient is a number. The projection is a vector. Multiplying by is part of the answer whenever the question asks for the projection.
Work the two-dimensional example
Take and . First compute and . Thus and .
Subtract to get . Two checks establish the decomposition: and . The projection lies on the line because it is twice its direction vector.
The point is closest to , so the distance is the residual's length: . The length of measures how far along the line the projection lies from the origin; it measures a different distance.
Change the direction vector without changing the line
Replacing with any nonzero multiple leaves the projection unchanged. The numerator gains a factor , the denominator gains , and the final direction vector supplies the second factor .
For in the example, the coefficient is , giving the same . A negative coefficient means the projection lies opposite to the chosen direction vector, not that the distance is negative.
Separate scalar component from vector projection
The signed length along is . Multiplying by the unit direction gives . Using would scale the vector twice unless were already a unit vector.
In , projecting onto gives . The residual is , with length . This projection replaces entries by their mean. More generally, an input on the line projects to itself, while an input perpendicular to the line projects to zero.
Key Takeaways
- Onto a nonzero direction , use .
- The residual is perpendicular to the line.
- The residual length is the distance to the line.
- Changing the nonzero spanning vector leaves the projection unchanged.
- The scalar component and the vector projection have different meanings.
3.2 Projection onto a subspace
A subspace with several perpendicular basis directions lets you project onto each direction separately and add the resulting vectors. The answer is independent of the orthogonal basis used to describe that subspace.
Split the vector uniquely
The orthogonal decomposition theorem says that every has exactly one representation with and . Here and .
For an orthogonal basis of ,
Each term lies in . Dotting the difference from with any basis vector gives zero, which verifies the perpendicular part of the decomposition.
Add two projections
Let , , and . The basis vectors are perpendicular because . Their squared lengths are 2 and 3.
The two weights are and . Therefore
The residual is . Check both directions: and .
The distance to the plane is . Keeping only the first projection gives the point . Its squared distance from is , so that partial projection is not the closest point in the whole plane.
Explain why the point is closest
For any ,
The first term lies in and the second in . The Pythagorean theorem gives
The second square is positive unless . This proves the best approximation theorem: the projection is the unique closest point.
Use the right basis formula
The same plane is spanned by and , but their dot product is 2. Adding the separate line projections in these directions gives , whose residual is not perpendicular to the plane. For a nonorthogonal basis, use Gram–Schmidt or the matrix formula for projection.
Projection is linear: projecting gives the same result as combining their projections with weights . A vector already in stays fixed; a vector in is sent to zero.
Key Takeaways
- Every vector splits uniquely into a part in and a part in .
- With an orthogonal basis, add all the individual line projections.
- The projection is the unique closest point by the Pythagorean theorem.
- Distance is the residual length, and the residual must be perpendicular to every basis direction.
- The sum-of-line-projections formula requires an orthogonal basis.
- Projection fixes vectors in the subspace and removes vectors in its orthogonal complement.
3.3 Matrices that project
Projection is linear, so one matrix can project every input onto the same subspace. Which formula is easiest depends on how the subspace's basis is supplied. The matrix acts on vectors in the original ambient space.
Start with an orthonormal basis
Put an orthonormal basis of into the columns of an matrix . Then lists the dot-product weights. Multiplying those weights by rebuilds the projection:
Keep the product order: is a small identity matrix; is an matrix acting on the input space.
For one nonzero direction , normalization gives
For , . Applying it to gives .
Use any independent basis columns
If the columns of are a basis of , a projection has the form . Its residual must be perpendicular to the columns, so
Independence makes invertible. Solving for the coefficients and multiplying by gives
For , . Multiplying yields
Consequently . This agrees with the orthogonal-basis calculation.
Recognize the matrix properties
An orthogonal projection satisfies : once a vector lies in , projecting again changes nothing. It also satisfies , so it is symmetric. Together these properties characterize orthogonal projection matrices in real coordinate spaces.
Its column space is , and . The complementary matrix projects onto . In the example, . Thus records the orthogonal decomposition.
A projection onto a proper subspace loses information: nonzero vectors in all map to zero. It has no inverse. Only projection onto the entire ambient space is invertible; then .
Preserve the matrix order and conditions
Use directly only when the columns are orthonormal. For a rectangular , no exists, so splitting into inverses of its rectangular factors is invalid. The invertible object in the general formula is the square matrix .
Key Takeaways
- For orthonormal basis columns, .
- For arbitrary independent basis columns, .
- Orthogonal projections satisfy and .
- projects onto the orthogonal complement.
- A projection onto a proper subspace is not invertible.
4Build bases with Gram–Schmidt and QR
A basis can span the right space while pointing in inconvenient directions. Gram–Schmidt removes the overlap with earlier directions, producing a perpendicular basis without changing the space. Normalizing those vectors builds the columns of Q. The coefficients needed to recover the original columns form an upper triangular matrix R, turning the basis construction into the factorization A = QR.
4.1 The Gram–Schmidt process
The Gram–Schmidt process turns an ordered basis into an orthogonal basis of the same subspace. At each stage, subtract the part already represented by earlier output vectors. The remainder supplies one new perpendicular direction.
Remove earlier components
Begin with . Then
For the general step,
The vectors used in the sum are the new orthogonal outputs, not the original inputs. Their mutual orthogonality lets separate projections remove all overlap. At every stage, the first output vectors span the same space as the first inputs.
Work through three vectors
Take , , and . Set . Since and ,
For simpler arithmetic, scale this direction to . Nonzero scaling keeps both orthogonality and the span, but the scaled vector must now be used consistently.
For the third input, , , and . Subtract both components:
Scale this to . The pairwise dot products are , , and . Hence the three directions form an orthogonal basis of the original span.
Normalize after finding the directions
The scaled output lengths are , , and . Dividing gives the orthonormal basis
Changing the input order generally changes the output basis. It does not change the subspace spanned by all the inputs.
Interpret a zero remainder
With independent inputs, each new remainder is nonzero. If an input lies in the earlier span, subtracting its projection leaves zero. For example, replacing the third input by gives a zero third remainder. Discard that output and continue using the nonzero orthogonal vectors; zero cannot be normalized.
Subtracting projections onto both original inputs in the worked example would instead produce . Its dot product with is , exposing the error. Pairwise checks detect a missing component or inconsistent scaling before normalization.
Key Takeaways
- Each step subtracts projection onto the span of earlier orthogonal outputs.
- The span of the processed vectors is preserved.
- Normalize nonzero outputs to obtain an orthonormal basis.
- A zero remainder identifies a dependent direction.
- Input order can change the basis.
- Check pairwise dot products and use any scaling consistently.
4.2 The QR factorization
For a matrix with independent columns, Gram–Schmidt can be recorded as a factorization . The columns of give perpendicular unit directions. The columns of give the coordinates of the original columns in those directions.
Identify the factors and their sizes
If is with independent columns, the reduced QR factorization has of size and of size . The columns of form an orthonormal basis of . The matrix is upper triangular and invertible; choose positive diagonal entries.
Apply Gram–Schmidt to the columns in order and normalize each remainder to form . Then
because . Each entry is a coordinate of column . Gram–Schmidt preserves the first-column spans, so needs only . Entries below the diagonal are zero. The diagonal entry is the length of the corresponding unnormalized remainder.
Factor a four-row matrix
Take . The first column has length 2, giving . To remove its component from the second column, compute and subtract:
Its length is . Equivalently, use the direction of length , so .
Now compute the nonzero entries of :
Thus . Check reconstruction: is the first column, while
Interpret what QR makes easier
For a tall matrix, but is the projection onto , not . To solve a least-squares problem, use the triangular system . For square invertible the same procedure solves the exact system by back-substitution.
Independent columns are necessary for an invertible reduced . A zero Gram–Schmidt remainder identifies failure of that condition. With positive diagonal entries, the reduced factors are unique. Software may instead use paired sign changes in a column of and row of , or return a full square and a taller with zero rows at the bottom. These conventions still multiply to . Numerical QR can be computed with Householder reflections instead of Gram–Schmidt.
Key Takeaways
- Reduced QR has orthonormal basis columns in and an upper triangular .
- Compute , preserving the product order.
- The positive diagonal records lengths of Gram–Schmidt remainders.
- For tall matrices, projects onto the column space.
5Solve systems by least squares
An inconsistent system asks for a vector outside the matrix’s column space, so no coefficient vector can meet every equation. Least squares chooses the closest attainable output instead. The perpendicular residual gives the normal equations and a way to check an answer. Orthogonal columns and QR then turn the same geometric problem into simpler calculations, with independence deciding whether the coefficients are unique.
5.1 The normal equations and the residual
When is inconsistent, lies outside . A least-squares solution minimizes over all coefficient vectors. Minimizing the squared norm gives the same solutions, because square root is increasing on nonnegative numbers.
Project the output vector
Every attainable output is in . Its closest point to is the projection , so the least-squares solutions are exactly the solutions of . Keep the roles separate: for an matrix, coefficients lie in ; fitted outputs and residuals lie in .
The residual is perpendicular to every column. Hence , giving the normal equations
They are consistent for every , even when the original system is not. To solve by hand, form the square matrix and the vector , then row-reduce their system.
Solve an inconsistent example
Let and . The original equations demand , , and , which cannot all hold.
Here and . The normal equations are and . Subtracting gives , then . Thus .
The fitted vector is and the residual is . Dotting this residual with either column gives zero. Its squared length is ; the least-squares error, its length, is . The sum of its entries is not an error measure: signs can cancel without a good fit.
Decide whether the coefficients are unique
Independent columns, invertibility of , and uniqueness of the least-squares solution for every target are equivalent. With independent columns,
Solving the normal equations is usually less work by hand than explicitly finding that inverse.
With dependent columns, the fitted vector is still unique. For with three identical rows and , the normal equations reduce to . Both and produce the same fit . Free variables describe infinitely many least-squares coefficient vectors.
If is already in the column space, the residual is zero and least squares gives the exact solutions. For an inconsistent system, cancelling from the normal equations is invalid: permits a nonzero residual in . It forces only when that null space is trivial.
Key Takeaways
- Least squares projects the target onto the column space.
- The normal equations are and always have a solution.
- The residual satisfies .
- Independent columns give unique coefficients.
- Dependent columns still give one fitted vector.
- Squared error is ; least-squares error is .
5.2 Least squares with orthogonal columns and QR
The normal equations express the right geometric condition, but the basis of the column space affects how much algebra is needed. Orthogonal columns separate the coefficient calculations. QR supplies such directions for any matrix with independent columns.
Use orthogonal columns directly
For nonzero mutually orthogonal columns ,
Each coefficient supplies one line projection, and their weighted sum is the projection onto the column space. Test orthogonality before using this shortcut.
Take columns and with . Their dot product is zero. Squared lengths are 4 and 20, while dot products with are 16 and . Thus . The fit is
Reduce QR to a triangular solve
With and independent columns, the normal equations become . Since is invertible, they reduce to
Compute the dot products in , then solve from the last row upward. That vector contains coordinates of the fitted output in the basis. It is generally not the coefficient vector for the original columns of .
For with rows , use , , and . With the same target, .
The bottom equation gives . The top equation gives . Multiplying by again gives . Equivalently, .
Explain different coefficients for the same fit
The orthogonal columns above span the same space as the two columns of this , because . Changing basis changes the coefficients from to . The fitted outputs agree since . Normal equations with matrix and right side give the same latter coefficients.
Prefer stable calculations on a computer
Normal equations and QR agree in exact arithmetic. In floating-point arithmetic, nearly dependent columns can make forming harmful: its 2-norm condition number is the square of that of . QR avoids forming that product and is commonly used for numerical least squares. Keep exact fractions in small hand calculations and round only the final reported values.
Key Takeaways
- Nonzero orthogonal columns give coefficients by individual dot-product quotients.
- With QR, solve by back-substitution.
- gives coordinates in the new basis; the triangular solve returns original coefficients.
- The same column space gives the same fitted output despite different basis coefficients.
- QR avoids squaring the 2-norm condition number through .
6Fit linear models to data
Data rarely satisfy one exact equation, but their patterns can still be described by a least-squares model. A design matrix translates a chosen line, parabola, or several-predictor equation into columns and coefficients. The fit is a projection of the observations onto those columns. Residuals measure what remains, while the meaning of each coefficient and the range of the data guide how the fitted equation is interpreted.
6.1 Fit a line and read its residuals
For points , a line model predicts . Treat the observed responses as a vector . Each data point contributes one row to the design matrix , and the parameter vector is .
Write the least-squares problem
The residual at point is , a signed vertical difference. The fit minimizes . Its normal equations are , where
The columns are independent as long as at least two input values differ. The line then has unique least-squares coefficients.
Fit measured heights
A seedling's heights at weeks 1, 2, 3, and 4 are 2, 3, 5, and 6 cm. The sums are , , , and . Hence
Multiply the first equation by 2.5 and subtract from the second: . Thus and . The fitted equation is . The slope describes an average increase of 1.4 cm per week over the measured period. The intercept is the prediction at week zero, outside the measured range.
Predicted heights are 1.9, 3.3, 4.7, and 6.1 cm. Subtract them from the observations to get residuals cm. Squaring and adding gives .
Use the intercept and centered inputs
The residual vector is perpendicular to both design columns. The column of ones gives ; the predictor column gives . Here the checks are and .
An intercept also makes the line pass through . Here and . Centering replaces the inputs by , whose sum is zero, so the constant and predictor columns become orthogonal. The equivalent formulas are
The example's numerator is 7 and denominator is 5, recovering the slope 1.4. Its centered inputs are half of .
Interpret the chosen model
Least squares minimizes squared vertical residuals. Swapping response and predictor generally changes the fitted line. Omitting the column of ones forces the line through the origin and removes the usual zero-sum-residual guarantee. At week 6 the fitted line predicts 8.9 cm, but this is extrapolation beyond weeks 1–4, where the growth pattern may change.
Key Takeaways
- A line with an intercept has design rows .
- The fit minimizes squared vertical residuals.
- Solve the normal equations or use centered-input formulas.
- With an intercept, residuals sum to zero and the line passes through the point of means.
- Two distinct input values ensure independent line-design columns.
- Interpret slope units and treat extrapolation cautiously.
6.2 Fit curves and several predictors
A general linear model is linear in its unknown parameters. Its graph can be curved. Choosing columns that describe the input patterns turns a line, parabola, or several-predictor equation into the same least-squares calculation.
Build the design matrix from the model
Write . For , a design row is . For , it is . The parameter order must match the column order. Both models solve .
Fit a parabola
Use data . The design rows are , , , and . The products are
The equations are , , and . Subtract half the first from the second to get . Subtract 1.5 times the first from the third to get . Their difference gives .
Thus , , and . The fitted curve is . Its outputs are , giving residuals and squared error 0.2.
Interpret several predictors
For daily heating energy in kWh, use outdoor temperature in °C and floor area in m². The model describes a plane. The coefficient is the change in predicted energy per 1 °C with floor area held fixed. Its meaning depends on holding the other input constant.
Unique coefficients require independent design columns and at least as many rows as parameters. Including area in both m² and cm² creates dependent columns, because one is 10,000 times the other. The fitted vector remains unique, but coefficients can trade off without changing it.
With a square invertible design matrix, the fit goes through every observation. A parabola can pass through any three points with distinct inputs. Zero training residuals in that situation establish exact interpolation, not reliable prediction on new data.
Distinguish transformations and model size
For positive responses in , take logarithms: . Fit a line to the logged responses, then recover and . The minimized errors are in , so this generally differs from minimizing squared errors in the original responses.
Adding design columns enlarges the available column space. The best squared error on the same data cannot increase, because the old fit remains available by setting new coefficients to zero. A smaller training error by itself does not establish better predictions.
Key Takeaways
- A model can have a curved graph while remaining linear in its parameters.
- Design rows follow the functions and parameter order in the model.
- Unique coefficients require independent design columns.
- With several predictors, interpret each slope while holding the others fixed.
- Fitting log responses changes the error criterion.
- Adding columns cannot increase the best training squared error, but predictive quality needs separate evidence.
Orthogonality, Projections and Least Squares examples
1From coordinates to perpendicular spaces
13 steps
- 1IntroductionGive coordinates a geometry
A vector can have more coordinates than you can draw. The dot product still lets you measure its length, compare directions, and describe perpendicular spaces.
Start with computations on individual vectors. Then turn the requirement of perpendicularity into homogeneous equations, connecting geometry to null spaces.
- 2ExplanationMultiply, then add
For real vectors with matching sizes, multiply corresponding entries and add:
For and , this is . The result is one number, not the list . The same product is when vectors are columns.
- 3ExampleMeasure length and distance
Keep and . Length comes from a self-dot-product: .
For distance, subtract before taking length. The displacement is , so . Taking the difference of the separate lengths would measure a different quantity.
- 4ChallengeKeep the direction, change the length
What unit vector points in the direction of ? What happens to its direction if you multiply that unit vector by −1?
---reveal---
The length is 5, so normalization gives . Multiplying by −1 reverses its direction while keeping length 1. Normalization itself uses the positive length and therefore keeps the original direction.
- 5ExplanationA zero dot product means orthogonality
Two vectors are orthogonal when their dot product is zero. For and , the product is .
Their sum has squared length 9. The separate squared lengths are 6 and 3, so this also illustrates the Pythagorean identity. The zero cross term makes squared lengths add.
- 6ExampleFind an angle from its cosine
For nonzero vectors, use .
The vectors and have dot product 1 and lengths . Their cosine is , giving or . Cauchy–Schwarz guarantees that the quotient lies between −1 and 1, where inverse cosine is defined.
- 7ChallengeRead the sign correctly
For nonzero vectors, a learner says, “A positive dot product always means an acute angle.” What endpoint must be included to make the statement correct?
---reveal---
Include 0°. Positive dot product gives ; a positive multiple of the same direction gives 0°. A zero vector is a separate case: it is orthogonal to every vector, but its angle is undefined.
- 8ExplanationBe perpendicular to a whole space
The orthogonal complement contains vectors perpendicular to every vector in . Test a spanning set, since the dot product distributes across its linear combinations.
For , an unknown vector must satisfy . One equation describes all the perpendicular directions at once.
- 9ExampleSolve for the complement
Solve by taking and . Then
The two directions form a basis of . The original space is a line, and its complement is a plane in . Their dimensions add to 3, and their only common vector is zero.
- 10ChallengeCheck every spanning direction
Let . Does belong to ?
---reveal---
No. Its dot product with the first direction is zero, but its dot product with the second is 2. Membership requires perpendicularity to every spanning direction. Here is the line spanned by , obtained by solving and .
- 11ConnectionRead a null-space equation as dot products
For an matrix, says that x is perpendicular to every row. Thus in .
Applying this to the transpose gives in . This is why a perpendicular fitting residual will satisfy .
- 12ChallengeConnect dimension and orthogonality
A matrix has rank 3. How many dimensions does its left null space have, and why must a vector there be perpendicular to every attainable output?
---reveal---
Its dimension is . A left-null vector is perpendicular to every column, so it is perpendicular to every linear combination of columns. Those combinations are exactly the attainable outputs .
- 13RecapUse the right test
Use a dot product to compare directions, a norm to measure length, and the norm of a difference to measure distance.
For a whole subspace, test its spanning directions. A null-space equation records all those dot-product conditions together. Keep the ambient dimension in view when pairing row or column spaces with their complements.
2Use perpendicular directions as coordinates
11 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionMake each coordinate independent
- 2ExplanationWhy orthogonality gives independence
- 3ExampleRecover the weights
- 4ChallengeCheck the formula’s condition
- 5ExampleNormalize the basis
- 6ExplanationTest columns with a matrix product
- 7ExampleInvert a square orthogonal matrix
- 8ChallengeOrthogonal columns or an orthogonal matrix?
- 9Key InsightA tall matrix has two different products
- 10ChallengeRecover coefficients, then reconstruct
- 11RecapCoordinates and geometry
3Project a vector and verify the closest point
15 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionFind the attainable part
- 2ExplanationRequire a perpendicular remainder
- 3ExampleCalculate the line projection
- 4ExampleCheck the residual and distance
- 5ChallengeRescale the direction
- 6ExplanationAdd perpendicular basis components
- 7ExampleCompute both weights for a plane
- 8ExampleTest the whole residual
- 9Key InsightWhy no different point can be closer
- 10ChallengeTwo checks for a proposed closest point
- 11ExplanationSave the projection in a matrix
- 12ConnectionUse any independent basis
- 13ChallengeProject twice
- 14ChallengeA matrix and a distance
- 15RecapCheck the point and its remainder
4Build perpendicular directions and record QR
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionRemove what earlier vectors already represent
- 2ExplanationSubtract the earlier projections
- 3ExampleFind the first two directions
- 4ExampleRemove two components from the third input
- 5ExampleNormalize the outputs
- 6ChallengeFind an omitted component
- 7Key InsightA zero remainder has a meaning
- 8ExplanationRecord the basis as QR
- 9ExampleBuild Q for a line-design matrix
- 10ExampleCalculate R and reconstruct a column
- 11ChallengeDistinguish the two identities
- 12ChallengeRead dependence from the construction
- 13RecapPreserve spans and track coefficients
5Find and check a least-squares solution
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionFit what cannot be solved exactly
- 2ExplanationDerive the normal equations
- 3ExampleForm the square system
- 4ExampleSolve for the coefficients
- 5ExampleVerify and measure the residual
- 6ChallengeOne fitted vector, several coefficients
- 7Key InsightIndependence controls uniqueness
- 8ExampleSeparate orthogonal-column coefficients
- 9ExampleUse Q to find the new coordinates
- 10ExampleFinish by back-substitution
- 11ChallengeDo not stop at the new coordinates
- 12ChallengeChoose a numerical method
- 13RecapFit, solve, and verify
6Build and interpret least-squares models
15 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionTranslate a model into columns
- 2ExplanationSeparate inputs from responses
- 3ExampleCollect the line-fit sums
- 4ExampleSolve the line coefficients
- 5ExampleRead the signed residuals
- 6ChallengeInterpret a prediction outside the data
- 7ConnectionCenter the predictor
- 8ExplanationA curved graph can be a linear model
- 9ExampleForm the parabola equations
- 10ExampleFinish the curve and check its predictions
- 11ChallengeFind a redundant predictor
- 12ConnectionHold the other predictor fixed
- 13ExplanationTransform the response and track the criterion
- 14ChallengeInterpret a perfect fit
- 15RecapRead the model as well as the answer
Orthogonality, Projections and Least Squares practice questions
Set 1: Projection matrices and model setup10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
Show answerHide answer
Set 2: Lengths, coordinates, and first fits10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Connect geometry, factorizations, and fits10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Diagnose and justify the methods10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 5: Transfer to new spaces and data10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Angle between vectors
B
Back-substitution
Basis coordinate
Best approximation theorem
C
Cauchy–Schwarz inequality
Centering
Column space
Complementary projection matrix
Complementary projections
Condition number
D
Dependent input direction
Design matrix
Distance between vectors
Distance to a subspace
Dot product
E
Extrapolation
F
Fitted vector
Floating-point arithmetic
G
General linear model
Gram–Schmidt process
Gram–Schmidt remainder
I
Idempotence
Intercept
Interpolation
L
Least-squares error
Least-squares solution
Left null space
Linear independence
Log transformation
N
Norm
Normal equations
Normalization
O
Orthogonal basis
Orthogonal complement
Orthogonal decomposition
Orthogonal matrix
Orthogonal projection onto a line
Orthogonal set
Orthogonal subspaces
Orthogonal vectors
Orthogonal-column shortcut
Orthonormal basis
Orthonormal columns
Orthonormal set
P
Parameter vector
Perpendicular component
Positive-diagonal convention
Predictor
Preserved span
Projection matrix
Pythagorean theorem for vectors
Q
QR factorization
R
Reduced QR
Residual vector
Row space
S
Scalar component
Slope
Sum of squared residuals
Symmetric matrix
T
Triangle inequality
U
Unit vector
Upper triangular matrix
- 1Systems of Linear Equations
- 2Linear Transformations
- 3Matrix Algebra
- 4Determinants
- 5Vector Spaces
- 6Dimension and Rank
- 7Eigenvalues and Eigenvectors
- 8Orthogonality, Projections and Least Squares
- 9Symmetric Matrices and Quadratic Forms
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.