Tutorials › Linear Algebra › Least-Squares Solutions From the SVD

Pseudoinverse and Low-Rank Approximation · Tutorial 812 of 1000

Least-Squares Solutions From the SVD

Use singular-vector coordinates to describe all least-squares minimizers, including the residual that no choice of input can remove.

Advanced 12 min read

What You'll Learn

  • Express the residual norm in left singular-vector coordinates.
  • Derive the coefficient fixed by each nonzero singular value.
  • Identify the freely chosen coordinates associated with zero singular values.
  • Write every least-squares minimizer as a particular solution plus a null-space vector.
  • Compute the minimum residual norm from the left singular vectors.
  • Check least-squares formulas by multiplying the candidate input by the matrix.

Least Squares in Singular-Vector Coordinates

A system \(\mathbf{A}\mathbf{x}=\mathbf{b}\) need not have an exact solution. Least squares replaces exact equality with a minimization problem: choose \(\mathbf{x}\) so that the residual \(\mathbf{A}\mathbf{x}-\mathbf{b}\) has the smallest possible Euclidean norm. A singular value decomposition (SVD) makes the choices in this problem visible. Each positive singular value determines one coordinate of a minimizer, while coordinates corresponding to zero singular values do not affect the output and may be chosen freely.

Work over \(\mathbb{R}\), with \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and \(\mathbf{b}\in\mathbb{R}^m\). The Euclidean norm of a column vector \(\mathbf{w}\) is \(\|\mathbf{w}\|_2=\sqrt{\mathbf{w}^{\top}\mathbf{w}}\). A least-squares solution is any vector \(\mathbf{x}\in\mathbb{R}^n\) that minimizes \(\|\mathbf{A}\mathbf{x}-\mathbf{b}\|_2\) over all \(\mathbf{x}\in\mathbb{R}^n\). A minimizer need not make the residual zero; it does so exactly when the system is consistent.

Definition: A full SVD of \(\mathbf{A}\) is a factorization \(\mathbf{A}=\mathbf{U}\boldsymbol{\Sigma}\mathbf{V}^{\top}\), where \(\mathbf{U}\in\mathbb{R}^{m\times m}\) and \(\mathbf{V}\in\mathbb{R}^{n\times n}\) are orthogonal, and \(\boldsymbol{\Sigma}\in\mathbb{R}^{m\times n}\) is diagonal-shaped with nonnegative singular values on its diagonal. Write the positive singular values as \(\sigma_1,\dots,\sigma_r\), ordered from largest to smallest, and the corresponding columns of \(\mathbf{U}\) and \(\mathbf{V}\) as \(\mathbf{u}_1,\dots,\mathbf{u}_r\) and \(\mathbf{v}_1,\dots,\mathbf{v}_r\). The remaining columns of \(\mathbf{V}\) are right singular vectors for zero singular values.

For a full SVD, \(\mathbf{A}\mathbf{v}_j=\sigma_j\mathbf{u}_j\) when \(\sigma_j>0\), and \(\mathbf{A}\mathbf{v}_j=\mathbf{0}\) for every remaining right singular vector. Thus, if \(\mathbf{x}=\mathbf{V}\mathbf{y}\), then \(y_j=\mathbf{v}_j^{\top}\mathbf{x}\) and \(\mathbf{A}\mathbf{x}=\sum_{j=1}^{r}\sigma_j y_j\mathbf{u}_j\). The SVD therefore separates input coordinates that change \(\mathbf{A}\mathbf{x}\) from coordinates that do not.

Deriving Every Minimizer

Because \(\mathbf{U}\) is orthogonal, it preserves Euclidean norms: \(\|\mathbf{w}\|_2=\|\mathbf{U}^{\top}\mathbf{w}\|_2\). Set \(\beta_j=\mathbf{u}_j^{\top}\mathbf{b}\) for \(1\le j\le m\), and write \(\mathbf{x}=\mathbf{V}\mathbf{y}\). In the \(\mathbf{U}\) coordinates, the residual has coordinate \(\sigma_j y_j-\beta_j\) in each positive-singular-value direction, and coordinate \(-\beta_j\) in each remaining left-singular-vector direction. Consequently, its squared norm is a sum of independent squares.

$$ \|\mathbf{A}\mathbf{x}-\mathbf{b}\|_2^2 =\sum_{j=1}^{r}(\sigma_j y_j-\beta_j)^2 +\sum_{j=r+1}^{m}\beta_j^2. $$

The second sum does not depend on \(\mathbf{x}\). In the first sum, each term is nonnegative and can be made zero by setting \(y_j=\beta_j/\sigma_j\), since \(\sigma_j>0\). These choices can be made independently for every \(j\le r\). Every coordinate \(y_j\) belonging to a zero singular value is absent from the expression, so none of those coordinates affects the residual.

Theorem (All least-squares solutions from the SVD): Let \(\mathbf{A}\in\mathbb{R}^{m\times n}\) have full SVD with positive singular values \(\sigma_1,\dots,\sigma_r\), and let \(\mathbf{u}_j,\mathbf{v}_j\) be the corresponding left and right singular vectors. For any \(\mathbf{b}\in\mathbb{R}^m\), the set of all least-squares solutions is $$ \mathbf{x} =\sum_{j=1}^{r}\frac{\mathbf{u}_j^{\top}\mathbf{b}}{\sigma_j}\mathbf{v}_j +\sum_{j=r+1}^{n}c_j\mathbf{v}_j, $$ where \(c_{r+1},\dots,c_n\) are arbitrary real numbers. A sum with no terms is understood to be zero.

Proof. Since \(\mathbf{V}\) is orthogonal, every \(\mathbf{x}\in\mathbb{R}^n\) has a unique coordinate vector \(\mathbf{y}=\mathbf{V}^{\top}\mathbf{x}\), and \(\mathbf{x}=\mathbf{V}\mathbf{y}\). The displayed residual identity shows that its squared norm is at least \(\sum_{j=r+1}^{m}\beta_j^2\), because every term in the first sum is nonnegative. Equality holds if and only if each of those terms is zero. For \(j\le r\), this condition is \(\sigma_j y_j-\beta_j=0\), which, because \(\sigma_j>0\), is equivalent to \(y_j=\beta_j/\sigma_j\). No condition is imposed on \(y_j\) for \(j>r\), since these coordinates do not occur in the residual expression. Therefore equality, and hence minimization of the norm, holds exactly for the vectors with \(y_j=(\mathbf{u}_j^{\top}\mathbf{b})/\sigma_j\) for \(j\le r\) and arbitrary remaining coordinates. Substituting these coordinates into \(\mathbf{x}=\mathbf{V}\mathbf{y}\) gives the stated formula and includes every minimizer. \(\square\)

The freely chosen part is exactly a null-space vector: each \(\mathbf{v}_j\) with \(j>r\) satisfies \(\mathbf{A}\mathbf{v}_j=\mathbf{0}\), so any combination of these vectors lies in \(\operatorname{Nul}\mathbf{A}\). Conversely, in the SVD coordinates, \(\mathbf{A}\mathbf{x}=\mathbf{0}\) forces \(y_j=0\) for each \(j\le r\), because \(\sigma_j>0\), while the other coordinates are unrestricted. Thus the formula can also be written as one specified vector plus any \(\mathbf{z}\in\operatorname{Nul}\mathbf{A}\).

Corollary (Minimum residual): With the notation above, the minimum residual norm is $$ \min_{\mathbf{x}\in\mathbb{R}^n}\|\mathbf{A}\mathbf{x}-\mathbf{b}\|_2 =\sqrt{\sum_{j=r+1}^{m}(\mathbf{u}_j^{\top}\mathbf{b})^2}. $$ The system \(\mathbf{A}\mathbf{x}=\mathbf{b}\) is consistent if and only if \(\mathbf{u}_j^{\top}\mathbf{b}=0\) for every \(j>r\).

Proof. For any \(\mathbf{x}\), the squared residual norm is the sum of \(\sum_{j=1}^{r}(\sigma_j y_j-\beta_j)^2\) and \(\sum_{j=r+1}^{m}\beta_j^2\). The first sum can be made zero, and only zero, by the choices \(y_j=\beta_j/\sigma_j\), so the minimum squared norm is \(\sum_{j=r+1}^{m}\beta_j^2\). Taking the nonnegative square root gives the formula. This minimum is zero exactly when every \(\beta_j=0\) for \(j>r\). A zero minimum means that some \(\mathbf{x}\) has \(\|\mathbf{A}\mathbf{x}-\mathbf{b}\|_2=0\), which is equivalent to \(\mathbf{A}\mathbf{x}=\mathbf{b}\). Since \(\beta_j=\mathbf{u}_j^{\top}\mathbf{b}\), this is precisely the stated consistency condition. \(\square\)

Reading the Formula in Examples

Worked Example: A Full-Column-Rank System

Find the least-squares solution for \(\mathbf{A}=\begin{bmatrix}0&2\\1&0\\0&0\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}3\\5\\4\end{bmatrix}\), and compute its residual norm.

Take \(\mathbf{u}_1=\begin{bmatrix}1\\0\\0\end{bmatrix}\), \(\mathbf{u}_2=\begin{bmatrix}0\\1\\0\end{bmatrix}\), \(\mathbf{u}_3=\begin{bmatrix}0\\0\\1\end{bmatrix}\), and \(\mathbf{v}_1=\begin{bmatrix}0\\1\end{bmatrix}\), \(\mathbf{v}_2=\begin{bmatrix}1\\0\end{bmatrix}\). Then \(\mathbf{A}\mathbf{v}_1=2\mathbf{u}_1\) and \(\mathbf{A}\mathbf{v}_2=\mathbf{u}_2\), so the positive singular values are \(\sigma_1=2\) and \(\sigma_2=1\). The coefficients are \(\mathbf{u}_1^{\top}\mathbf{b}=3\) and \(\mathbf{u}_2^{\top}\mathbf{b}=5\). The formula gives

$$ \mathbf{x}=\frac{3}{2}\mathbf{v}_1+5\mathbf{v}_2 =\begin{bmatrix}5\\ \frac{3}{2}\end{bmatrix}. $$

Check: \(\mathbf{A}\mathbf{x}=\begin{bmatrix}0&2\\1&0\\0&0\end{bmatrix}\begin{bmatrix}5\\ \frac{3}{2}\end{bmatrix}=\begin{bmatrix}3\\5\\0\end{bmatrix}\). Hence \(\mathbf{A}\mathbf{x}-\mathbf{b}=\begin{bmatrix}0\\0\\-4\end{bmatrix}\), whose norm is \(4\). The minimum-residual formula gives the same result: the only left coordinate beyond the two positive singular values is \(\mathbf{u}_3^{\top}\mathbf{b}=4\). There are no free right coordinates in this example.

Worked Example: A Consistent Rank-Deficient System

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

Choose \(\mathbf{u}_1=\begin{bmatrix}0\\1\end{bmatrix}\), \(\mathbf{u}_2=\begin{bmatrix}1\\0\end{bmatrix}\), \(\mathbf{v}_1=\begin{bmatrix}0\\0\\1\end{bmatrix}\), \(\mathbf{v}_2=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\\0\end{bmatrix}\), and \(\mathbf{v}_3=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\-1\\0\end{bmatrix}\). Direct multiplication gives \(\mathbf{A}\mathbf{v}_1=2\mathbf{u}_1\), \(\mathbf{A}\mathbf{v}_2=\sqrt{2}\mathbf{u}_2\), and \(\mathbf{A}\mathbf{v}_3=\mathbf{0}\). Thus \(\sigma_1=2\), \(\sigma_2=\sqrt{2}\), and \(\mathbf{v}_3\) is a null-space direction. The relevant coefficients are \(\mathbf{u}_1^{\top}\mathbf{b}=4\) and \(\mathbf{u}_2^{\top}\mathbf{b}=3\). Therefore

$$ \begin{aligned} \mathbf{x} &=\frac{4}{2}\mathbf{v}_1+\frac{3}{\sqrt{2}}\mathbf{v}_2+c\mathbf{v}_3\\ &=\begin{bmatrix}\frac{3}{2}\\ \frac{3}{2}\\2\end{bmatrix} +\frac{c}{\sqrt{2}}\begin{bmatrix}1\\-1\\0\end{bmatrix}, \qquad c\in\mathbb{R}. \end{aligned} $$

Check: Multiplying the particular vector gives \(\mathbf{A}\begin{bmatrix}\frac{3}{2}\\ \frac{3}{2}\\2\end{bmatrix}=\begin{bmatrix}3\\4\end{bmatrix}=\mathbf{b}\). The added vector is a multiple of \(\mathbf{v}_3\), and \(\mathbf{A}\mathbf{v}_3=\mathbf{0}\), so every displayed \(\mathbf{x}\) also maps to \(\mathbf{b}\). The residual is zero, which is the smallest possible norm.

Worked Example: An Inconsistent Rank-Deficient System

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

Let \(\mathbf{u}_1=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\\0\end{bmatrix}\), \(\mathbf{u}_2=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\-1\\0\end{bmatrix}\), \(\mathbf{u}_3=\begin{bmatrix}0\\0\\1\end{bmatrix}\), and take \(\mathbf{v}_1=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\1\end{bmatrix}\), \(\mathbf{v}_2=\frac{1}{\sqrt{2}}\begin{bmatrix}1\\-1\end{bmatrix}\). Multiplication gives \(\mathbf{A}\mathbf{v}_1=2\mathbf{u}_1\) and \(\mathbf{A}\mathbf{v}_2=\mathbf{0}\). The only positive singular value is \(2\). Since \(\mathbf{u}_1^{\top}\mathbf{b}=1/\sqrt{2}\), the specified coordinate is \((1/\sqrt{2})/2=1/(2\sqrt{2})\). Hence

$$ \mathbf{x}=\frac{1}{2\sqrt{2}}\mathbf{v}_1+c\mathbf{v}_2 =\begin{bmatrix}\frac14\\ \frac14\end{bmatrix} +\frac{c}{\sqrt{2}}\begin{bmatrix}1\\-1\end{bmatrix}, \qquad c\in\mathbb{R}. $$

Check: For the particular vector, \(\mathbf{A}\begin{bmatrix}\frac14\\ \frac14\end{bmatrix}=\begin{bmatrix}\frac12\\ \frac12\\0\end{bmatrix}\). The added vector is annihilated because its two coordinates sum to zero. Thus every minimizer has residual \(\mathbf{A}\mathbf{x}-\mathbf{b}=\begin{bmatrix}-\frac12\\ \frac12\\-2\end{bmatrix}\), with squared norm \(\frac14+\frac14+4=\frac92\). Equivalently, the unused left coordinates of \(\mathbf{b}\) are \(\mathbf{u}_2^{\top}\mathbf{b}=1/\sqrt{2}\) and \(\mathbf{u}_3^{\top}\mathbf{b}=2\), giving minimum norm \(\sqrt{\frac12+4}=\frac{3}{\sqrt{2}}\).

Common Mistakes and a Reliable Check

Forgetting to divide by the singular value changes the answer. Consider \(\mathbf{A}=\begin{bmatrix}2&0\\0&0\end{bmatrix}\) and \(\mathbf{b}=\begin{bmatrix}4\\3\end{bmatrix}\). Here the positive singular value is \(2\), with left and right singular vector \(\begin{bmatrix}1\\0\end{bmatrix}\); the other right direction is \(\begin{bmatrix}0\\1\end{bmatrix}\). A wrong calculation sets the first coordinate equal to \(\mathbf{u}_1^{\top}\mathbf{b}=4\), giving \(\mathbf{x}=\begin{bmatrix}4\\0\end{bmatrix}\). But \(\mathbf{A}\mathbf{x}=\begin{bmatrix}8\\0\end{bmatrix}\), so the residual is \(\begin{bmatrix}4\\-3\end{bmatrix}\), with norm \(5\). The required coordinate is instead \(4/2=2\), giving every minimizer \(\mathbf{x}=\begin{bmatrix}2\\c\end{bmatrix}\). For these vectors, \(\mathbf{A}\mathbf{x}=\begin{bmatrix}4\\0\end{bmatrix}\), and the residual norm is \(3\), independent of \(c\).

A second error is trying to divide by a zero singular value. The formula divides only for \(j\le r\), where \(\sigma_j>0\). At a zero singular value the corresponding right coordinate is free; it does not have a prescribed value obtained by division. A useful check is to substitute the proposed input into \(\mathbf{A}\mathbf{x}\), then compare its residual norm with the SVD minimum-residual formula. This checks both the determined coordinates and the part of \(\mathbf{b}\) that cannot be matched.

Check Your Understanding

Use singular-vector coordinates in each question, and verify any proposed minimizer by evaluating its residual.

  1. For a full SVD with one positive singular value \(\sigma_1\), what value must the coordinate \(y_1\) have in a least-squares solution?
  2. Why can the coordinates belonging to zero singular values be chosen freely without changing the residual?
  3. Suppose \(m=4\), \(r=2\), and \(\mathbf{u}_3^{\top}\mathbf{b}=1\), \(\mathbf{u}_4^{\top}\mathbf{b}=2\). What is the minimum residual norm?
  4. For the matrix in the inconsistent worked example, compute \(\mathbf{A}\mathbf{x}\) when \(c=1\), and verify that its residual norm is unchanged.
  5. State the condition, in terms of the left singular vectors for zero singular values, that is equivalent to \(\mathbf{A}\mathbf{x}=\mathbf{b}\) having a solution.

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