Tutorials › Linear Algebra › Residuals and Forward Error

LU Factorization and Numerical Considerations · Tutorial 919 of 1000

Residuals and Forward Error

Learn how to calculate a residual and a forward error, and why they measure different things in a linear system.

Intermediate 9 min read

What You'll Learn

  • Define the residual and forward error for an approximate solution.
  • Track the dimensions of vectors in rectangular systems.
  • Verify the identity connecting residuals and solution errors.
  • Compute residuals and forward errors in small linear systems.
  • Use an invertible system to recover the forward error from the residual.
  • Avoid confusing the residual with the error or reversing its sign.

Two Different Ways to Measure an Approximate Solution

When a computed vector is offered as a solution to \(\mathbf{A}\mathbf{x}=\mathbf{b}\), two questions arise. How closely does it satisfy the equations? And how far is it from the exact solution? These questions lead to two different quantities: the residual and the forward error. Keeping them distinct is important both when checking a calculation and when interpreting its accuracy.

Vectors are columns. For a matrix \(\mathbf{A}\in\mathbb{R}^{m\times n}\), the unknown and approximate solution \(\mathbf{x},\hat{\mathbf{x}}\), and the forward error \(\mathbf{e}\), belong to \(\mathbb{R}^n\); the right-hand side \(\mathbf{b}\) and residual \(\mathbf{r}\) belong to \(\mathbb{R}^m\). Unless stated otherwise, the scalar field is \(\mathbb{R}\). Suppose \(\mathbf{x}\) is an exact solution of the system, so that \(\mathbf{A}\mathbf{x}=\mathbf{b}\), and \(\hat{\mathbf{x}}\) is a candidate approximation.

Definition: The residual of \(\hat{\mathbf{x}}\) for the system \(\mathbf{A}\mathbf{x}=\mathbf{b}\) is \(\mathbf{r}=\mathbf{b}-\mathbf{A}\hat{\mathbf{x}}\). Given an exact solution \(\mathbf{x}\), the forward error is \(\mathbf{e}=\mathbf{x}-\hat{\mathbf{x}}\). The residual measures how much the candidate fails to satisfy the equations; the forward error measures the difference between the candidate and the exact solution.

The subtraction order in these definitions matters. The residual is right-hand side minus computed matrix-vector product, while the forward error here is exact solution minus approximate solution. Other conventions sometimes reverse the error’s sign; throughout this tutorial, \(\mathbf{e}=\mathbf{x}-\hat{\mathbf{x}}\).

The Identity Connecting Residual and Error

Theorem (Residual-error identity): If \(\mathbf{A}\mathbf{x}=\mathbf{b}\) and \(\mathbf{e}=\mathbf{x}-\hat{\mathbf{x}}\), then \(\mathbf{r}=\mathbf{A}\mathbf{e}\), where \(\mathbf{r}=\mathbf{b}-\mathbf{A}\hat{\mathbf{x}}\). This holds for any \(m\times n\) matrix \(\mathbf{A}\), provided \(\mathbf{x}\) is an exact solution.

Proof. By the definition of an exact solution, \(\mathbf{b}=\mathbf{A}\mathbf{x}\). Substitute this into the definition of the residual, then use distributivity of matrix multiplication over subtraction:

$$ \mathbf{r} =\mathbf{b}-\mathbf{A}\hat{\mathbf{x}} =\mathbf{A}\mathbf{x}-\mathbf{A}\hat{\mathbf{x}} =\mathbf{A}(\mathbf{x}-\hat{\mathbf{x}}) =\mathbf{A}\mathbf{e}. $$

The equality is dimensionally consistent: \(\mathbf{e}\in\mathbb{R}^n\), so \(\mathbf{A}\mathbf{e}\in\mathbb{R}^m\), the same space as \(\mathbf{r}\). \(\square\)

This identity explains the difference between the two quantities. The error is an unknown-space vector, while the matrix transforms it into the residual, an equation-space vector. In a square invertible system, the identity also gives \(\mathbf{e}=\mathbf{A}^{-1}\mathbf{r}\). In a rectangular system, or in a square system without an inverse, that recovery step is not automatically available.

Worked Example: Residual and Error in a Square System

Consider \(\mathbf{A}\mathbf{x}=\mathbf{b}\), where

$$ \mathbf{A}=\begin{bmatrix}2&1\\1&1\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}5\\3\end{bmatrix}, \qquad \hat{\mathbf{x}}=\begin{bmatrix}\frac{19}{10}\\[2pt]\frac{11}{10}\end{bmatrix}. $$

First find the exact solution. The equations are \(2x_1+x_2=5\) and \(x_1+x_2=3\). Subtracting the second equation from the first gives \(x_1=2\), and then \(2+x_2=3\) gives \(x_2=1\). Thus \(\mathbf{x}=\begin{bmatrix}2\\1\end{bmatrix}\); substitution gives \(\mathbf{A}\mathbf{x}=\begin{bmatrix}4+1\\2+1\end{bmatrix}=\begin{bmatrix}5\\3\end{bmatrix}=\mathbf{b}\).

Compute the residual by first multiplying \(\mathbf{A}\hat{\mathbf{x}}\):

$$ \mathbf{A}\hat{\mathbf{x}} = \begin{bmatrix} 2\left(\frac{19}{10}\right)+\frac{11}{10}\\[2pt] \frac{19}{10}+\frac{11}{10} \end{bmatrix} = \begin{bmatrix}\frac{49}{10}\\3\end{bmatrix}, \qquad \mathbf{r} = \begin{bmatrix}5\\3\end{bmatrix} - \begin{bmatrix}\frac{49}{10}\\3\end{bmatrix} = \begin{bmatrix}\frac{1}{10}\\0\end{bmatrix}. $$

The forward error is a separate subtraction:

$$ \mathbf{e} = \mathbf{x}-\hat{\mathbf{x}} = \begin{bmatrix}2\\1\end{bmatrix} - \begin{bmatrix}\frac{19}{10}\\[2pt]\frac{11}{10}\end{bmatrix} = \begin{bmatrix}\frac{1}{10}\\[2pt]-\frac{1}{10}\end{bmatrix}. $$

Check: multiplying the error by \(\mathbf{A}\) gives \(\mathbf{A}\mathbf{e}=\begin{bmatrix}\frac{2}{10}-\frac{1}{10}\\[2pt]\frac{1}{10}-\frac{1}{10}\end{bmatrix}=\begin{bmatrix}\frac{1}{10}\\0\end{bmatrix}=\mathbf{r}\), as required.

What a Zero Residual Does and Does Not Tell You

Proposition: For any \(\mathbf{A}\in\mathbb{R}^{m\times n}\) and \(\mathbf{b}\in\mathbb{R}^m\), a candidate \(\hat{\mathbf{x}}\in\mathbb{R}^n\) has zero residual if and only if it is an exact solution of \(\mathbf{A}\mathbf{x}=\mathbf{b}\). If \(\mathbf{A}\) is square and invertible, the residual determines the forward error uniquely through \(\mathbf{e}=\mathbf{A}^{-1}\mathbf{r}\).

Proof. The residual is zero exactly when \(\mathbf{b}-\mathbf{A}\hat{\mathbf{x}}=\mathbf{0}\). Rearranging gives \(\mathbf{A}\hat{\mathbf{x}}=\mathbf{b}\), which is precisely the definition of \(\hat{\mathbf{x}}\) being an exact solution. The rearrangement is reversible, proving both directions. Now suppose \(\mathbf{A}\) is square and invertible and \(\mathbf{x}\) is the exact solution. By the residual-error identity, \(\mathbf{r}=\mathbf{A}\mathbf{e}\). Multiplying on the left by \(\mathbf{A}^{-1}\) gives \(\mathbf{A}^{-1}\mathbf{r}=\mathbf{A}^{-1}\mathbf{A}\mathbf{e}=\mathbf{I}\mathbf{e}=\mathbf{e}\). The inverse also makes this error the unique vector satisfying the identity. \(\square\)

The zero-residual statement applies even when the system is rectangular: it says that the candidate satisfies the equations, not that it is the only solution. The invertible-square-matrix condition in the second part is what ensures a unique solution and allows the residual to be converted directly into the forward error.

Worked Example: A Rectangular System and Its Dimensions

Let \(\mathbf{A}\in\mathbb{R}^{3\times2}\) and consider

$$ \mathbf{A}=\begin{bmatrix}1&1\\2&-1\\1&0\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}3\\0\\1\end{bmatrix}, \qquad \hat{\mathbf{x}}=\begin{bmatrix}1\\[2pt]\frac{3}{2}\end{bmatrix}. $$

The exact solution \(\mathbf{x}=\begin{bmatrix}1\\2\end{bmatrix}\) satisfies the system because \(\mathbf{A}\mathbf{x}=\begin{bmatrix}1+2\\2-2\\1\end{bmatrix}=\begin{bmatrix}3\\0\\1\end{bmatrix}=\mathbf{b}\). The approximate vector and exact vector are both in \(\mathbb{R}^2\). Their forward error is

$$ \mathbf{e} = \begin{bmatrix}1\\2\end{bmatrix} - \begin{bmatrix}1\\[2pt]\frac{3}{2}\end{bmatrix} = \begin{bmatrix}0\\[2pt]\frac{1}{2}\end{bmatrix} \in\mathbb{R}^2. $$

Now compute the product and residual. Both are in \(\mathbb{R}^3\):

$$ \mathbf{A}\hat{\mathbf{x}} = \begin{bmatrix}1+\frac{3}{2}\\[2pt]2-\frac{3}{2}\\[2pt]1\end{bmatrix} = \begin{bmatrix}\frac{5}{2}\\[2pt]\frac{1}{2}\\1\end{bmatrix}, \qquad \mathbf{r} = \begin{bmatrix}3\\0\\1\end{bmatrix} - \begin{bmatrix}\frac{5}{2}\\[2pt]\frac{1}{2}\\1\end{bmatrix} = \begin{bmatrix}\frac{1}{2}\\[2pt]-\frac{1}{2}\\0\end{bmatrix}. $$

Check: \(\mathbf{A}\mathbf{e}=\begin{bmatrix}0+\frac{1}{2}\\[2pt]0-\frac{1}{2}\\[2pt]0\end{bmatrix}=\begin{bmatrix}\frac{1}{2}\\[2pt]-\frac{1}{2}\\0\end{bmatrix}=\mathbf{r}\). The residual has three entries because there are three equations; the forward error has two because there are two unknowns.

Using a Residual to Recover an Error

When the system matrix is square and invertible, one can find the forward error from a known residual by solving \(\mathbf{A}\mathbf{e}=\mathbf{r}\). This does not require computing every entry of \(\mathbf{A}^{-1}\): the same elimination and back-substitution methods used for linear systems apply. The next example shows the relationship by solving for the error directly.

Worked Example: Recovering the Error by Back Substitution

Consider the system with

$$ \mathbf{A}=\begin{bmatrix}1&2\\0&1\end{bmatrix}, \qquad \mathbf{b}=\begin{bmatrix}5\\2\end{bmatrix}, \qquad \hat{\mathbf{x}}=\begin{bmatrix}\frac{6}{5}\\[2pt]\frac{9}{5}\end{bmatrix}. $$

The exact solution is \(\mathbf{x}=\begin{bmatrix}1\\2\end{bmatrix}\), since \(\mathbf{A}\mathbf{x}=\begin{bmatrix}1+4\\2\end{bmatrix}=\mathbf{b}\). For the approximate solution,

$$ \mathbf{A}\hat{\mathbf{x}} = \begin{bmatrix}\frac{6}{5}+2\left(\frac{9}{5}\right)\\[2pt]\frac{9}{5}\end{bmatrix} = \begin{bmatrix}\frac{24}{5}\\[2pt]\frac{9}{5}\end{bmatrix}, \qquad \mathbf{r} = \begin{bmatrix}5\\2\end{bmatrix} - \begin{bmatrix}\frac{24}{5}\\[2pt]\frac{9}{5}\end{bmatrix} = \begin{bmatrix}\frac{1}{5}\\[2pt]\frac{1}{5}\end{bmatrix}. $$

To recover the error, solve \(\mathbf{A}\mathbf{e}=\mathbf{r}\). Writing \(\mathbf{e}=\begin{bmatrix}e_1\\e_2\end{bmatrix}\) gives \(e_1+2e_2=\frac{1}{5}\) and \(e_2=\frac{1}{5}\). Substituting the second equation into the first yields \(e_1+\frac{2}{5}=\frac{1}{5}\), so \(e_1=-\frac{1}{5}\). Thus \(\mathbf{e}=\begin{bmatrix}-\frac{1}{5}\\[2pt]\frac{1}{5}\end{bmatrix}\).

Check: direct subtraction gives \(\mathbf{x}-\hat{\mathbf{x}}=\begin{bmatrix}1-\frac{6}{5}\\[2pt]2-\frac{9}{5}\end{bmatrix}=\begin{bmatrix}-\frac{1}{5}\\[2pt]\frac{1}{5}\end{bmatrix}\). Also, \(\mathbf{A}\mathbf{e}=\begin{bmatrix}-\frac{1}{5}+\frac{2}{5}\\[2pt]\frac{1}{5}\end{bmatrix}=\begin{bmatrix}\frac{1}{5}\\[2pt]\frac{1}{5}\end{bmatrix}=\mathbf{r}\).

Residual Size and Error Size

To compare sizes, a norm assigns a nonnegative length to a vector. An induced matrix norm is the corresponding maximum amplification factor: for a matrix \(\mathbf{A}\), it is defined by \(\|\mathbf{A}\|=\sup_{\mathbf{v}\ne\mathbf{0}}\|\mathbf{A}\mathbf{v}\|/\|\mathbf{v}\|\), using the chosen vector norms in the domain and codomain. From this definition, \(\|\mathbf{A}\mathbf{v}\|\leq\|\mathbf{A}\|\,\|\mathbf{v}\|\) for every \(\mathbf{v}\); for \(\mathbf{v}=\mathbf{0}\) both sides are zero, and otherwise the inequality follows from the supremum.

For a square invertible system, applying this inequality to \(\mathbf{e}=\mathbf{A}^{-1}\mathbf{r}\) gives the bound below. Its hypotheses matter: the inverse is needed to express the error in terms of the residual, and the matrix norm and vector norm must be compatible as an induced norm.

Residual-based error bound: If \(\mathbf{A}\) is square and invertible and \(\mathbf{A}\mathbf{x}=\mathbf{b}\), then \(\|\mathbf{e}\|\leq\|\mathbf{A}^{-1}\|\,\|\mathbf{r}\|\).

Proof. The residual-error identity gives \(\mathbf{e}=\mathbf{A}^{-1}\mathbf{r}\). The induced-norm inequality applied to \(\mathbf{A}^{-1}\) and \(\mathbf{r}\) gives \(\|\mathbf{e}\|=\|\mathbf{A}^{-1}\mathbf{r}\|\leq\|\mathbf{A}^{-1}\|\,\|\mathbf{r}\|\), as claimed. \(\square\)

The bound involves both the residual and the matrix. Therefore the residual alone is not the forward error, nor does its size alone specify the error’s size. The residual records the equation discrepancy; interpreting it as a solution discrepancy requires accounting for how the matrix acts on vectors.

Common Mistake: Subtracting in the Wrong Order

A frequent error is to compute \(\mathbf{A}\hat{\mathbf{x}}-\mathbf{b}\) and label it the residual under the convention used here. In the first worked example, that reversed subtraction gives \(\begin{bmatrix}\frac{49}{10}\\3\end{bmatrix}-\begin{bmatrix}5\\3\end{bmatrix}=\begin{bmatrix}-\frac{1}{10}\\0\end{bmatrix}\), which is the negative of the defined residual, not the residual itself. The correction is to calculate \(\mathbf{b}-\mathbf{A}\hat{\mathbf{x}}=\begin{bmatrix}\frac{1}{10}\\0\end{bmatrix}\). With \(\mathbf{e}=\mathbf{x}-\hat{\mathbf{x}}\), the check is \(\mathbf{A}\mathbf{e}=\mathbf{r}\); using the reversed residual without also changing the error convention produces a false sign in that identity.

Another dimension check prevents a different kind of mistake. For \(\mathbf{A}\in\mathbb{R}^{m\times n}\), \(\mathbf{A}\hat{\mathbf{x}}\) and \(\mathbf{r}\) have \(m\) entries, whereas \(\hat{\mathbf{x}}\) and \(\mathbf{e}\) have \(n\). The rectangular example makes this distinction visible: its residual has three entries and its forward error has two.

Check Your Understanding

For each question, keep the definitions \(\mathbf{r}=\mathbf{b}-\mathbf{A}\hat{\mathbf{x}}\) and \(\mathbf{e}=\mathbf{x}-\hat{\mathbf{x}}\) in view.

  1. For \(\mathbf{A}=\begin{bmatrix}1&1\\0&2\end{bmatrix}\), \(\mathbf{b}=\begin{bmatrix}3\\4\end{bmatrix}\), and \(\hat{\mathbf{x}}=\begin{bmatrix}1\\[2pt]\frac{3}{2}\end{bmatrix}\), compute the residual. Find the exact solution and forward error, then check \(\mathbf{A}\mathbf{e}=\mathbf{r}\).
  2. If \(\mathbf{A}\in\mathbb{R}^{4\times2}\), what are the dimensions of \(\mathbf{b}\), \(\hat{\mathbf{x}}\), \(\mathbf{r}\), and \(\mathbf{e}\)?
  3. State the residual-error identity and the assumption about \(\mathbf{x}\) needed for it to hold.
  4. Why does a zero residual show that a candidate is an exact solution, even if \(\mathbf{A}\) is rectangular?
  5. In a square invertible system, what equation can be solved to recover the forward error from a known residual?

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