Linear Algebra Learning Studio · Module 09

Least Squares and SVD

Learn least-squares projection, regression, residual orthogonality, singular value decomposition, conditioning, pseudoinverses, and PCA.

Offline browser lab Interactive mathematics Student practice environment
Module 09 · Approximation and principal axes

Solve inconsistent systems optimally and expose the geometry of any matrix

Real data rarely satisfies every linear equation exactly. Least squares finds the vector Ax̂ closest to b. The singular value decomposition then provides a universal coordinate system for understanding rank, conditioning, compression, pseudoinverses, and principal directions.

Derive normal equationsInterpret residual orthogonalityFit a lineRead singular valuesConnect SVD and PCA
01

Least-squares geometry

Replace an impossible equation with a closest-point problem

When b is not in C(A), no exact solution to Ax=b exists. Least squares chooses x̂ to minimize ‖Ax−b‖². The fitted vector p=Ax̂ is the orthogonal projection of b onto C(A), so the residual r=b−Ax̂ is orthogonal to every column of A.

Aᵀ(b−Ax̂)=0   ⇒   AᵀA x̂=Aᵀb

Normal equations can magnify conditioning problems

Forming AᵀA squares the 2-norm condition number. QR factorization or SVD is usually preferred for serious numerical work.

02

Linear regression as a matrix problem

Fit slope and intercept simultaneously

Design matrix

For points (xᵢ,yᵢ), model y≈b+mx. The design matrix has a column of ones and a column of x-values. Solving least squares chooses b and m so the vertical residual sum of squares is minimized.

A=[[1,x₁],…,[1,xₙ]],   c=[b,m]ᵀ,   Ac≈y
03

Interactive least-squares line fitting

Enter data and verify the orthogonality conditions

Least-squares regression laboratory

Enter one x,y pair per line. Residual segments and the best-fit line are drawn automatically.

Data fitting
Separators may be commas, spaces, or tabs.
Purple points: observations. Blue line: least-squares fit. Gold segments: vertical residuals.
04

Singular value decomposition

Factor any matrix into orthogonal directions and nonnegative stretches

A=UΣVᵀ
Vᵀ

Input rotation/reflection

Right singular vectors define orthonormal input directions.

Σ

Axis scaling

Nonnegative singular values scale mutually perpendicular axes.

U

Output rotation/reflection

Left singular vectors orient the resulting axes in the output space.

The nonzero singular values are square roots of nonzero eigenvalues of AᵀA. Their count is rank(A). The largest and smallest singular values determine maximum and minimum stretch.

05

Interactive singular-value geometry

Map a unit circle into an ellipse and measure conditioning

2×2 singular-value analyzer

The unit circle is transformed into an ellipse whose semiaxis lengths are σ₁ and σ₂.

SVD geometry
Dashed gray: unit circle. Teal: image under A. A collapsed ellipse indicates rank deficiency.
06

Pseudoinverse, compression, and PCA

Use SVD as a universal structural tool

ApplicationSVD role
Moore–Penrose pseudoinverseInvert nonzero singular values to compute minimum-norm least-squares solutions.
Low-rank approximationKeep the largest singular values and corresponding singular vectors; truncated SVD gives the best rank-k approximation in standard norms.
Conditioningκ₂(A)=σmax/σmin for full-rank square A. Large ratios indicate sensitivity.
PCAAfter centering data, right singular vectors identify principal directions and squared singular values relate to explained variance.
Noise filteringSmall singular components may represent weak or noise-dominated directions, though truncation must be justified by context.
07

Review questions

Test least-squares geometry and SVD structure

Knowledge check

What condition characterizes the least-squares residual r=b−Ax̂?

Knowledge check

What are the normal equations?

Knowledge check

Why can QR or SVD be preferable to normal equations?

Knowledge check

The singular values of A are the square roots of eigenvalues of:

Knowledge check

What does a zero singular value indicate?