Skip to content
Feb 24

Linear Algebra: Least Squares Solutions

MT
Mindli Team

AI-Generated Content

Linear Algebra: Least Squares Solutions

In engineering and data science, you will constantly face a fundamental problem: what do you do when a system of equations has no exact solution? Real-world data is messy, measurements have error, and physical models are often approximations. The least squares method provides the powerful, definitive answer. It finds the "best" approximate solution to an inconsistent or overdetermined system (where there are more equations than unknowns) by minimizing the sum of the squares of the residuals. This technique is the engine behind curve fitting, regression analysis, satellite positioning, and countless other optimization tasks.

The Core Problem and the Normal Equations

Consider the system , where is an matrix with . This system is overdetermined and typically has no solution because is not in the column space of , . The least squares approach redefines the goal. Instead of solving , we seek a vector that minimizes the squared error or residual vector .

The quantity to minimize is the squared Euclidean norm: This is equivalent to minimizing the sum of the squares of the residual components: .

The solution is found by projecting onto . The key result is that the error vector must be orthogonal to . This orthogonality condition leads directly to the normal equations: To derive this, we state that the residual is orthogonal to every vector in , meaning it is orthogonal to each column of . Writing this condition as immediately yields the normal equations. Provided the columns of are linearly independent, is invertible, and the unique least squares solution is:

Example: Fit a line to the data points . We have the overdetermined system: In matrix form, with: The normal equations are: Solving gives . The best-fit line is .

Geometric Interpretation and the QR Factorization Approach

Geometrically, the least squares solution is the vector whose image is the orthogonal projection of onto . This projected vector is denoted . The residual is the component of orthogonal to the column space.

While the normal equations are conceptually clear, they can be numerically unstable if is ill-conditioned, as the condition number of is roughly the square of the condition number of . A more robust computational method uses QR factorization.

Here, we factor , where is an matrix with orthonormal columns (a basis for ) and is an invertible upper triangular matrix. Substituting into the normal equations: Since , this simplifies to: And because is invertible, we arrive at the clean system: This system is easy to solve by back substitution. The geometric insight is powerful: computes the coordinates of the projection of onto the orthonormal basis given by 's columns, and maps those coordinates back to the original -coordinates.

Linear Regression and Weighted Least Squares

Linear regression is the most famous application of least squares. In simple linear regression, we fit a line to data points . The design matrix has a column of ones (for the intercept ) and a column of values. The normal equations solve for and . This extends directly to multiple linear regression with many predictor variables.

A crucial extension is weighted least squares (WLS). In standard least squares, we assume all measurements in are equally reliable. What if some data points are known to be more precise than others? WLS incorporates a weight for each observation. If we have a diagonal weight matrix with positive weights , the problem becomes: The solution modifies the normal equations: Heavier weights force the solution to fit certain data points more closely. This is essential in engineering when combining sensor data of varying quality or in econometrics to handle heteroscedasticity.

Applications in Data Fitting and Engineering Systems

The utility of least squares spans from simple curve fitting to complex system control. In data fitting, you can fit not just lines but polynomials, exponentials (by taking logs), or any model linear in its parameters to a dataset. The matrix is constructed from the basis functions evaluated at the data points.

For overdetermined systems in engineering, think of triangulating a device's location from multiple GPS satellites with slightly inconsistent time signals. Each satellite gives an equation relating distances, and the least squares solution provides the most probable location. In electrical engineering, solving for circuit parameters from noisy measurements is a least squares problem. In mechanical and aerospace engineering, calibrating sensors or estimating forces from strain gauge readings relies on these principles.

The method also underpines the Kalman filter, a recursive algorithm for state estimation that uses a form of sequential least squares to optimally combine predictions with new measurements, which is vital for navigation and control systems.

Common Pitfalls

  1. Solving Normal Equations Directly for Ill-Conditioned Problems: As mentioned, forming squares the condition number, which can lead to catastrophic loss of precision for nearly rank-deficient matrices. Correction: Use the QR factorization method or, for rank-deficient cases, a Singular Value Decomposition (SVD) approach, which is the most stable numerical algorithm for least squares.
  1. Misinterpreting the Solution When is Singular: If the columns of are linearly dependent, is not invertible and the normal equations have infinitely many solutions. This means the least squares problem itself has infinitely many minimizers. Correction: Recognize that this indicates your model has redundant parameters. You must either reformulate the model to remove the dependency or use the SVD to select the minimum norm least squares solution, which is often the desired unique output.
  1. Applying Least Squares to a Model that is Nonlinear in its Parameters: You cannot directly fit a model like using the linear least squares framework unless you transform it. Taking logs gives , which is linear in parameters and . Correction: Always check if your model can be transformed into a linear one, or be prepared to use nonlinear least squares algorithms (e.g., Gauss-Newton), which are more complex and iterative.
  1. Ignoring the Assumptions and Diagnostics: Least squares provides the "best" linear unbiased estimator under specific assumptions (errors are uncorrelated, have constant variance, and are normally distributed). Blindly applying it without checking residuals for patterns can lead to poor models. Correction: After fitting, always plot residuals versus fitted values and predictors to check for heteroscedasticity (non-constant variance) or nonlinearity, which may require weighted least squares or a different model form.

Summary

  • The least squares method finds the best approximate solution to an inconsistent system by minimizing the sum of squared residuals .
  • The solution is defined by the normal equations and corresponds geometrically to the orthogonal projection of onto the column space of .
  • For numerical stability, the QR factorization is preferred, reducing the problem to solving the triangular system .
  • Linear regression is a direct application, and weighted least squares generalizes the method to account for measurements of differing precision or reliability.
  • The technique is indispensable for solving overdetermined systems in engineering domains like signal processing, navigation, and data fitting, providing a principled way to extract optimal estimates from noisy, redundant data.

Write better notes with AI

Mindli helps you capture, organize, and master any subject with AI-powered summaries and flashcards.