Tutorials › Linear Algebra › Existence Of Least-Squares Solutions

Least Squares and QR Factorization · Tutorial 683 of 1000

Existence Of Least-Squares Solutions

Learn why projecting the right-hand side onto the column space guarantees a least-squares solution, and how to verify that solution in exact examples.

Intermediate 12 min read

What You'll Learn

  • Define a least-squares solution using the residual norm
  • Identify the column space as the set of vectors a matrix can produce
  • Prove that projecting the right-hand side onto the column space yields a minimum
  • Find a least-squares solution by expressing the projection as a column combination
  • Check least-squares solutions when the system is inconsistent or has dependent columns
  • Distinguish existence of a least-squares solution from uniqueness

When an Exact Solution Does Not Exist

A system \(\mathbf{A}\mathbf{x}=\mathbf{b}\) may have no exact solution: there may be no choice of \(\mathbf{x}\) that makes the product \(\mathbf{A}\mathbf{x}\) equal to \(\mathbf{b}\). Least squares replaces exact equality with a minimization question. Among all vectors the matrix can produce, which one is closest to \(\mathbf{b}\)? If that closest vector can be written as \(\mathbf{A}\widehat{\mathbf{x}}\), then \(\widehat{\mathbf{x}}\) is a least-squares solution.

Throughout, \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and \(\mathbf{b}\in\mathbb{R}^m\). The column space of \(\mathbf{A}\), written \(\operatorname{Col}\mathbf{A}\), is the set of all linear combinations of its columns. Thus \(\operatorname{Col}\mathbf{A}=\{\mathbf{A}\mathbf{x}:\mathbf{x}\in\mathbb{R}^n\}\). The residual at \(\mathbf{x}\) is \(\mathbf{b}-\mathbf{A}\mathbf{x}\); its norm measures the error in the fit.

Definition: A vector \(\widehat{\mathbf{x}}\in\mathbb{R}^n\) is a least-squares solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\) if \(\|\mathbf{b}-\mathbf{A}\widehat{\mathbf{x}}\|\leq\|\mathbf{b}-\mathbf{A}\mathbf{x}\|\) for every \(\mathbf{x}\in\mathbb{R}^n\). Equivalently, it minimizes the residual norm over all possible choices of \(\mathbf{x}\).

The vectors \(\mathbf{A}\mathbf{x}\) range over \(\operatorname{Col}\mathbf{A}\), not over all of \(\mathbb{R}^m\) in general. Therefore, the least-squares question is exactly the question of finding a closest vector in \(\operatorname{Col}\mathbf{A}\) to \(\mathbf{b}\). That subspace is finite-dimensional, so the orthogonal projection of \(\mathbf{b}\) onto it exists. The key point for existence is that this projected vector is itself a matrix output: it belongs to \(\operatorname{Col}\mathbf{A}\), so at least one vector of coefficients produces it.

The Projection Argument

Recall that vectors \(\mathbf{u}\) and \(\mathbf{v}\) in \(\mathbb{R}^m\) are orthogonal when \(\mathbf{u}\cdot\mathbf{v}=0\). The orthogonal projection of \(\mathbf{b}\) onto a subspace \(S\) is the vector \(\mathbf{p}\in S\) for which \(\mathbf{b}-\mathbf{p}\) is orthogonal to every vector in \(S\). For a finite-dimensional subspace, such a vector can be constructed using an orthonormal basis: if \(\mathbf{q}_1,\dots,\mathbf{q}_r\) is an orthonormal basis of \(S\), then \(\mathbf{p}=\sum_{i=1}^r(\mathbf{b}\cdot\mathbf{q}_i)\mathbf{q}_i\). If \(S=\{\mathbf{0}\}\), the basis is empty and the sum is \(\mathbf{0}\).

Theorem (Existence of least-squares solutions): For every \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and every \(\mathbf{b}\in\mathbb{R}^m\), there is at least one least-squares solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\). More precisely, if \(\mathbf{p}\) is the orthogonal projection of \(\mathbf{b}\) onto \(\operatorname{Col}\mathbf{A}\), then any \(\widehat{\mathbf{x}}\) satisfying \(\mathbf{A}\widehat{\mathbf{x}}=\mathbf{p}\) is a least-squares solution.

Proof. Set \(S=\operatorname{Col}\mathbf{A}\). This is a finite-dimensional subspace of \(\mathbb{R}^m\). If \(S=\{\mathbf{0}\}\), let \(\mathbf{p}=\mathbf{0}\). Otherwise, choose a basis \(\mathbf{v}_1,\dots,\mathbf{v}_r\) of \(S\). Applying the Gram-Schmidt construction to this basis gives an orthonormal basis \(\mathbf{q}_1,\dots,\mathbf{q}_r\): at step \(k\), subtract from \(\mathbf{v}_k\) its components along the already constructed \(\mathbf{q}_i\), then normalize the result. The result before normalization is nonzero, since if it were zero then \(\mathbf{v}_k\) would be a linear combination of the preceding basis vectors, contradicting independence.

For \(S\ne\{\mathbf{0}\}\), define \(\mathbf{p}=\sum_{i=1}^r(\mathbf{b}\cdot\mathbf{q}_i)\mathbf{q}_i\); for \(S=\{\mathbf{0}\}\), use \(\mathbf{p}=\mathbf{0}\). In either case \(\mathbf{p}\in S\). In the nonzero case, for each \(j\), orthonormality gives \(\mathbf{q}_j\cdot(\mathbf{b}-\mathbf{p})=\mathbf{q}_j\cdot\mathbf{b}-\sum_{i=1}^r(\mathbf{b}\cdot\mathbf{q}_i)(\mathbf{q}_j\cdot\mathbf{q}_i)=\mathbf{b}\cdot\mathbf{q}_j-\mathbf{b}\cdot\mathbf{q}_j=0\). Since the \(\mathbf{q}_j\) span \(S\), this means \(\mathbf{b}-\mathbf{p}\) is orthogonal to every vector in \(S\). In the zero-subspace case, \(\mathbf{b}-\mathbf{p}=\mathbf{b}\) is orthogonal to the only vector in \(S\), namely \(\mathbf{0}\).

For any \(\mathbf{x}\in\mathbb{R}^n\), we have \(\mathbf{A}\mathbf{x}\in S\), and therefore \(\mathbf{p}-\mathbf{A}\mathbf{x}\in S\). The two terms in \(\mathbf{b}-\mathbf{A}\mathbf{x}=(\mathbf{b}-\mathbf{p})+(\mathbf{p}-\mathbf{A}\mathbf{x})\) are orthogonal. Expanding the dot product of this sum with itself gives \(\|\mathbf{b}-\mathbf{A}\mathbf{x}\|^2=\|\mathbf{b}-\mathbf{p}\|^2+\|\mathbf{p}-\mathbf{A}\mathbf{x}\|^2\geq\|\mathbf{b}-\mathbf{p}\|^2\). Because \(\mathbf{p}\in S=\operatorname{Col}\mathbf{A}\), the definition of column space gives at least one \(\widehat{\mathbf{x}}\in\mathbb{R}^n\) with \(\mathbf{A}\widehat{\mathbf{x}}=\mathbf{p}\). For this choice the second squared norm is zero, so it attains the minimum residual norm. \(\square\)

The proof separates two jobs. Projection identifies the closest attainable output \(\mathbf{p}\); membership in the column space guarantees that some coefficient vector produces that output. It does not claim that this coefficient vector is unique. The minimum value is determined by the projection, while more than one coefficient vector can sometimes produce the same projected vector.

Worked Projection Examples

Worked Example: Projection onto a Coordinate Plane

Find a least-squares solution for \(\mathbf{A}=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}2\\-1\\3\end{bmatrix}\).

The columns of \(\mathbf{A}\) are \(\mathbf{e}_1=(1,0,0)^{\top}\) and \(\mathbf{e}_2=(0,1,0)^{\top}\), so \(\operatorname{Col}\mathbf{A}\) is the \(xy\)-coordinate plane. The vector in that plane obtained by deleting the third coordinate of \(\mathbf{b}\) is \(\mathbf{p}=(2,-1,0)^{\top}\). Its residual is

$$ \mathbf{b}-\mathbf{p} = \begin{bmatrix}2\\-1\\3\end{bmatrix} - \begin{bmatrix}2\\-1\\0\end{bmatrix} = \begin{bmatrix}0\\0\\3\end{bmatrix}. $$

This residual is orthogonal to both columns, since its dot products with \(\mathbf{e}_1\) and \(\mathbf{e}_2\) are both \(0\). Also \(\mathbf{p}=\mathbf{A}\widehat{\mathbf{x}}\) for \(\widehat{\mathbf{x}}=(2,-1)^{\top}\). The theorem therefore guarantees that this is a least-squares solution.

Check: Multiplication gives \(\mathbf{A}\widehat{\mathbf{x}}=(2,-1,0)^{\top}\), so the residual is \((0,0,3)^{\top}\) and has norm \(3\). For any \(\mathbf{x}=(x_1,x_2)^{\top}\), the squared residual norm is \((2-x_1)^2+(-1-x_2)^2+9\geq9\). Equality holds at \(x_1=2,\ x_2=-1\), confirming the minimum.

Worked Example: Projection onto a Plane with a Nonorthogonal Column Basis

Find a least-squares solution for \(\mathbf{A}=\begin{bmatrix}1&0\\0&1\\1&1\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}1\\2\\0\end{bmatrix}\).

Write the columns as \(\mathbf{a}_1=(1,0,1)^{\top}\) and \(\mathbf{a}_2=(0,1,1)^{\top}\). A vector orthogonal to both is \(\mathbf{n}=(-1,-1,1)^{\top}\): the dot products are \(\mathbf{a}_1\cdot\mathbf{n}=-1+1=0\) and \(\mathbf{a}_2\cdot\mathbf{n}=-1+1=0\). Since \(\mathbf{b}\cdot\mathbf{n}=-3\) and \(\mathbf{n}\cdot\mathbf{n}=3\), subtracting the component of \(\mathbf{b}\) along \(\mathbf{n}\) gives

$$ \mathbf{p} =\mathbf{b}-\frac{\mathbf{b}\cdot\mathbf{n}}{\mathbf{n}\cdot\mathbf{n}}\mathbf{n} =\begin{bmatrix}1\\2\\0\end{bmatrix}-\frac{-3}{3}\begin{bmatrix}-1\\-1\\1\end{bmatrix} =\begin{bmatrix}0\\1\\1\end{bmatrix}. $$

This projected vector is \(\mathbf{a}_2\), so \(\mathbf{p}=\mathbf{A}(0,1)^{\top}\). The residual is \(\mathbf{b}-\mathbf{p}=(1,1,-1)^{\top}=-\mathbf{n}\), which is orthogonal to both columns and hence to every vector in their span.

Check: \(\mathbf{A}(0,1)^{\top}=(0,1,1)^{\top}\), as required. The squared residual norm is \(1^2+1^2+(-1)^2=3\). For any other output \(\mathbf{A}\mathbf{x}\), the difference \(\mathbf{p}-\mathbf{A}\mathbf{x}\) lies in the column space and is orthogonal to the residual. The squared residual norm for that output is therefore \(3+\|\mathbf{p}-\mathbf{A}\mathbf{x}\|^2\), which cannot be less than \(3\).

Worked Example: Existence with Dependent Columns

Let \(\mathbf{A}=\begin{bmatrix}1&2\\0&0\\1&2\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}2\\1\\0\end{bmatrix}\). Find a least-squares solution.

The columns are \(\mathbf{u}=(1,0,1)^{\top}\) and \(2\mathbf{u}\), so the column space is the line of multiples \(t\mathbf{u}\). The projection of \(\mathbf{b}\) onto this line has the form \(c\mathbf{u}\). The coefficient is \((\mathbf{b}\cdot\mathbf{u})/(\mathbf{u}\cdot\mathbf{u})=2/2=1\), giving \(\mathbf{p}=\mathbf{u}\). This vector is \(\mathbf{A}(1,0)^{\top}\), so \(\widehat{\mathbf{x}}=(1,0)^{\top}\) produces the projection.

Check: \(\mathbf{A}\widehat{\mathbf{x}}=(1,0,1)^{\top}\), and the residual is \(\mathbf{b}-\mathbf{A}\widehat{\mathbf{x}}=(1,1,-1)^{\top}\). Its dot product with \(\mathbf{u}\) is \(1+0-1=0\), so it is orthogonal to the column space. More explicitly, any output has the form \(t\mathbf{u}\). Its squared residual norm is \((2-t)^2+1^2+(0-t)^2=2t^2-4t+5=2(t-1)^2+3\), which is minimized when \(t=1\). The chosen coefficients give \(t=1\) and attain the minimum.

Common Mistake: Demanding an Exact Fit

In the last example, a mistaken approach is to conclude that no least-squares solution exists because the equation \(\mathbf{A}\mathbf{x}=\mathbf{b}\) has no exact solution. Indeed, every output \(\mathbf{A}\mathbf{x}=(t,0,t)^{\top}\) has second coordinate \(0\), whereas \(\mathbf{b}\) has second coordinate \(1\). Thus no output equals \(\mathbf{b}\). But this only rules out an exact solution; it does not rule out minimizing the residual. The calculation above shows that \(t=1\) gives the minimum squared residual \(3\), attained by \(\widehat{\mathbf{x}}=(1,0)^{\top}\).

A useful check is to keep the two questions separate. An exact solution requires \(\mathbf{b}\in\operatorname{Col}\mathbf{A}\). A least-squares solution requires a coefficient vector whose output is closest to \(\mathbf{b}\) among all vectors in \(\operatorname{Col}\mathbf{A}\). If \(\mathbf{b}\) already lies in the column space, its projection is \(\mathbf{b}\) itself and the minimum residual is zero. If it does not, the projection still exists, and its residual need not be zero.

Existence does not imply uniqueness. The projection onto the column space is a single vector, but different coefficient vectors can map to that same vector when the columns are dependent. The theorem guarantees at least one coefficient vector in all cases; determining when it is unique is a separate question.

Check Your Understanding

Use the projection and column-space ideas to answer these questions.

  1. For \(\mathbf{A}=\begin{bmatrix}1&0\\0&1\\0&0\end{bmatrix}\) and \(\mathbf{b}=(3,2,-4)^{\top}\), find the projection and a least-squares solution.
  2. Explain why the projected vector in the existence proof must equal \(\mathbf{A}\widehat{\mathbf{x}}\) for at least one \(\widehat{\mathbf{x}}\).
  3. For the matrix in the dependent-column example, verify that the residual at \(\widehat{\mathbf{x}}=(1,0)^{\top}\) is orthogonal to each column.
  4. If \(\mathbf{b}\in\operatorname{Col}\mathbf{A}\), what is the minimum residual norm? Explain why.
  5. In the dependent-column example, why does the absence of an exact solution not prevent a least-squares solution from existing?

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon