Unit 7, lesson 36

Conditioning and Sensitivity

How far a small change in the data can move the solution of a linear system, measured with relative error, the induced matrix norm and the condition number, and how conditioning differs from stability.

  • Video 36
  • Conditioning and Sensitivity

The lines x+y=2x + y = 2 and x+1.01y=2.01x + 1.01y = 2.01 cross at (1,1)(1, 1). Raise the second right-hand side to 2.022.02 and the crossing jumps to (0,2)(0, 2), although no number in the data moved by more than one hundredth. Both answers are exact, so the jump comes from the system itself, whose two lines are nearly parallel, and not from rounding. This lesson measures that kind of sensitivity with the induced matrix norm and the condition number, and it keeps it apart from the accuracy of the method used to solve the system.

Key terms

Perturbation of the data

Definition Let AA be an invertible n×nn \times n real matrix, let b\mathbf{b} be a vector in Rn\mathbb{R}^n, and let x\mathbf{x} be the solution of Ax=bA\mathbf{x} = \mathbf{b}. A perturbation of the data replaces b\mathbf{b} by b+δb\mathbf{b} + \delta\mathbf{b} while AA stays fixed. The new solution is x+δx\mathbf{x} + \delta\mathbf{x}, and subtracting the two systems gives

A δx=δb,δx=A−1δb.A\,\delta\mathbf{x} = \delta\mathbf{b}, \qquad \delta\mathbf{x} = A^{-1}\delta\mathbf{b}.

Sizes are measured with a chosen vector norm, on this page the Euclidean length ∥⋅∥\lVert \cdot \rVert. The absolute error, or absolute change, of the solution is ∥δx∥\lVert \delta\mathbf{x} \rVert, and for x≠0\mathbf{x} \ne \mathbf{0} its relative error is ∥δx∥/∥x∥\lVert \delta\mathbf{x} \rVert / \lVert \mathbf{x} \rVert. The data have absolute error ∥δb∥\lVert \delta\mathbf{b} \rVert and, for b≠0\mathbf{b} \ne \mathbf{0}, relative error ∥δb∥/∥b∥\lVert \delta\mathbf{b} \rVert / \lVert \mathbf{b} \rVert. Against a zero baseline a relative error is undefined, and only the absolute error is reported. Changes in the matrix AA itself need a separate analysis.

In plain words A perturbation is a small change in the measured right-hand side. The absolute error says how large the change is, and the relative error compares it with the size of the quantity being changed, which is what a percentage reports. These numbers depend on units, so coordinates measured in different units should be scaled to comparable sizes before their lengths are compared.

Example Tuples such as (2,2.01)(2, 2.01) stand for column vectors on this page. The opening example has

A=[1111.01],b=[22.01],A = \begin{bmatrix} 1 & 1 \\ 1 & 1.01 \end{bmatrix}, \qquad \mathbf{b} = \begin{bmatrix} 2 \\ 2.01 \end{bmatrix},

and x=(1,1)\mathbf{x} = (1, 1). The change δb=(0,0.01)\delta\mathbf{b} = (0, 0.01) moves the solution to (0,2)(0, 2), so δx=(−1,1)\delta\mathbf{x} = (-1, 1), and indeed A δx=(−1+1,−1+1.01)=(0,0.01)A\,\delta\mathbf{x} = (-1 + 1, -1 + 1.01) = (0, 0.01). The absolute errors are ∥δb∥=0.01\lVert \delta\mathbf{b} \rVert = 0.01 and ∥δx∥=2\lVert \delta\mathbf{x} \rVert = \sqrt{2}. Since ∥x∥=2\lVert \mathbf{x} \rVert = \sqrt{2} and ∥b∥=8.0401≈2.8355\lVert \mathbf{b} \rVert = \sqrt{8.0401} \approx 2.8355, the relative errors are

∥δb∥∥b∥≈0.00353,∥δx∥∥x∥=1.\frac{\lVert \delta\mathbf{b} \rVert}{\lVert \mathbf{b} \rVert} \approx 0.00353, \qquad \frac{\lVert \delta\mathbf{x} \rVert}{\lVert \mathbf{x} \rVert} = 1.

A change of about 0.350.35 percent in the data produced a 100100 percent change in the solution.

Induced matrix norm

Definition Let AA be a real m×nm \times n matrix. Its induced Euclidean norm is the largest length of AuA\mathbf{u} over unit vectors u\mathbf{u} in Rn\mathbb{R}^n,

∥A∥2=max⁡∥u∥=1∥Au∥=max⁡v≠0∥Av∥∥v∥.\begin{aligned} \lVert A \rVert_2 &= \max_{\lVert \mathbf{u} \rVert = 1} \lVert A\mathbf{u} \rVert \\[0.4em] &= \max_{\mathbf{v} \ne \mathbf{0}} \frac{\lVert A\mathbf{v} \rVert}{\lVert \mathbf{v} \rVert}. \end{aligned}

The maximum is always attained. It follows that ∥Av∥≤∥A∥2∥v∥\lVert A\mathbf{v} \rVert \le \lVert A \rVert_2 \lVert \mathbf{v} \rVert for every v\mathbf{v} in Rn\mathbb{R}^n, both sides being 00 when v=0\mathbf{v} = \mathbf{0}, and that ∥A∥2\lVert A \rVert_2 is the smallest number with this property. For a product of compatible matrices, ∥AB∥2≤∥A∥2∥B∥2\lVert AB \rVert_2 \le \lVert A \rVert_2 \lVert B \rVert_2. Other vector norms induce other matrix norms in the same way, and the subscript records which one is meant.

In plain words The induced norm of a matrix is its greatest stretch factor. Feed in every vector of length one, and the length of the longest output is the norm.

Example For a square diagonal matrix the norm is the largest absolute value on the diagonal. Take

D=[1000.01].D = \begin{bmatrix} 1 & 0 \\ 0 & 0.01 \end{bmatrix}.

A unit vector u=(u1,u2)\mathbf{u} = (u_1, u_2) gives ∥Du∥2=u12+0.0001 u22≤u12+u22=1\lVert D\mathbf{u} \rVert^2 = u_1^2 + 0.0001\,u_2^2 \le u_1^2 + u_2^2 = 1, with equality at u=e1\mathbf{u} = \mathbf{e}_1, so ∥D∥2=1\lVert D \rVert_2 = 1. The unit circle goes to an ellipse with semiaxes 11 and 0.010.01. The inverse D−1D^{-1} has diagonal entries 11 and 100100, and the same argument gives ∥D−1∥2=100\lVert D^{-1} \rVert_2 = 100. The direction e2\mathbf{e}_2 that DD shrinks most is the direction that D−1D^{-1} stretches most.

Condition number

Definition For an invertible n×nn \times n real matrix AA, the Euclidean condition number is

κ2(A)=∥A∥2 ∥A−1∥2.\kappa_2(A) = \lVert A \rVert_2 \, \lVert A^{-1} \rVert_2.

The smallest stretch min⁡∥u∥=1∥Au∥\min_{\lVert \mathbf{u} \rVert = 1} \lVert A\mathbf{u} \rVert equals 1/∥A−1∥21 / \lVert A^{-1} \rVert_2, so κ2(A)\kappa_2(A) is the ratio of the largest stretch of AA to its smallest. It satisfies κ2(A)≥1\kappa_2(A) \ge 1, because 1=∥I∥2≤∥A∥2∥A−1∥21 = \lVert I \rVert_2 \le \lVert A \rVert_2 \lVert A^{-1} \rVert_2, and κ2(cA)=κ2(A)\kappa_2(cA) = \kappa_2(A) for every scalar c≠0c \ne 0. For a singular matrix the definition gives no finite number.

The condition number bounds the effect of a perturbation of the data. Suppose AA is fixed, b≠0\mathbf{b} \ne \mathbf{0}, Ax=bA\mathbf{x} = \mathbf{b} and A(x+δx)=b+δbA(\mathbf{x} + \delta\mathbf{x}) = \mathbf{b} + \delta\mathbf{b}. Then

∥δx∥∥x∥≤κ2(A) ∥δb∥∥b∥.\frac{\lVert \delta\mathbf{x} \rVert}{\lVert \mathbf{x} \rVert} \le \kappa_2(A) \, \frac{\lVert \delta\mathbf{b} \rVert}{\lVert \mathbf{b} \rVert}.

To prove it, combine ∥δx∥=∥A−1δb∥≤∥A−1∥2∥δb∥\lVert \delta\mathbf{x} \rVert = \lVert A^{-1}\delta\mathbf{b} \rVert \le \lVert A^{-1} \rVert_2 \lVert \delta\mathbf{b} \rVert with ∥b∥=∥Ax∥≤∥A∥2∥x∥\lVert \mathbf{b} \rVert = \lVert A\mathbf{x} \rVert \le \lVert A \rVert_2 \lVert \mathbf{x} \rVert, where x≠0\mathbf{x} \ne \mathbf{0} because b≠0\mathbf{b} \ne \mathbf{0}. When b=0\mathbf{b} = \mathbf{0}, use the absolute bound ∥δx∥≤∥A−1∥2∥δb∥\lVert \delta\mathbf{x} \rVert \le \lVert A^{-1} \rVert_2 \lVert \delta\mathbf{b} \rVert instead. The bound is a worst case. For every AA some choice of b\mathbf{b} and δb\delta\mathbf{b} attains it, but when κ2(A)\kappa_2(A) is large a particular perturbation may be amplified far less.

In plain words The condition number is the largest factor by which a relative error in the data can grow in the solution. It compares the strongest stretch of the matrix with its weakest one.

Example The matrix DD above has κ2(D)=1⋅100=100\kappa_2(D) = 1 \cdot 100 = 100. The matrix AA of the opening example has

A−1=[101−100−100100],A^{-1} = \begin{bmatrix} 101 & -100 \\ -100 & 100 \end{bmatrix},

and a numerical computation gives ∥A∥2≈2.005\lVert A \rVert_2 \approx 2.005 and ∥A−1∥2≈200.5\lVert A^{-1} \rVert_2 \approx 200.5, so κ2(A)≈402\kappa_2(A) \approx 402. The perturbation (0,0.01)(0, 0.01) in the opening example multiplied the relative error by 1/0.003527≈2841 / 0.003527 \approx 284, within the bound. The perturbation δb=(0.01,−0.01)\delta\mathbf{b} = (0.01, -0.01) gives δx=(2.01,−2)\delta\mathbf{x} = (2.01, -2) and a factor of about 402402, essentially the whole bound.

Ill-conditioned system

Definition A square system Ax=bA\mathbf{x} = \mathbf{b} with invertible AA is ill-conditioned when κ2(A)\kappa_2(A) is large, so that for some right-hand sides a small relative change in the data can cause a much larger relative change in the exact solution. It is well-conditioned when κ2(A)\kappa_2(A) is small, so that no relative change in the data can grow by more than a modest factor. There is no fixed cutoff. If the data carry relative errors up to ε\varepsilon, the bound above only limits the relative error of the solution to κ2(A) ε\kappa_2(A)\,\varepsilon, so whether κ2(A)\kappa_2(A) counts as large depends on how accurate the data are. Ill-conditioning is a property of the exact problem in its chosen units and norm, and the size of det⁡A\det A does not decide it.

In plain words An ill-conditioned matrix stretches some directions far more than others, so by comparison it nearly flattens the weakest one. Solving the system undoes the stretching. A data error along the image of that weakest direction is multiplied by a far larger factor than an error along the image of the strongest one, however carefully the arithmetic is done.

Example The determinant measures how volume scales, not how unevenly directions are stretched. In two dimensions the matrix 0.001 I0.001\,I has determinant 10−610^{-6}, but it shrinks every direction equally. Its norm is 0.0010.001, its inverse 1000 I1000\,I has norm 10001000, and its condition number is 11. The diagonal matrix with entries 100100 and 0.010.01 has determinant 11, yet its norm is 100100, its inverse has norm 100100, and its condition number is 10410^4. The first system is perfectly conditioned and the second is ill-conditioned, the reverse of what the determinants suggest.

Conditioning versus stability

Definition Conditioning is a property of a problem. It describes how much the exact answer changes when the exact data change, and the condition number measures it. Stability is a property of an algorithm. A stable algorithm keeps the errors it introduces through rounding under control, and one common standard, backward stability, asks that the computed answer be the exact answer for slightly changed data. A stable algorithm can still return an inaccurate answer to an ill-conditioned problem, because that small change in the data can be amplified, in the worst case by a factor of about the condition number. An unstable algorithm can fail even on a well-conditioned problem.

Three practices improve the computation without changing the problem. Pivoting exchanges rows so that elimination never divides by a needlessly small pivot, and partial pivoting takes the entry of largest absolute value available in the column. Guard digits are extra digits kept in intermediate steps, with rounding only at the end. In least squares with a design matrix XX of full column rank, the normal equations replace XX by X⊤XX^{\top}X, and the ratio of the largest to the smallest stretch of X⊤XX^{\top}X is the square of that ratio for XX, a fact the singular value decomposition explains in general later in the course. A QR method solves Rc=Q⊤yR\mathbf{c} = Q^{\top}\mathbf{y} instead, and ∥Ru∥=∥QRu∥=∥Xu∥\lVert R\mathbf{u} \rVert = \lVert QR\mathbf{u} \rVert = \lVert X\mathbf{u} \rVert for every u\mathbf{u} because QQ has orthonormal columns, so RR keeps the stretches of XX. None of these practices can lower the condition number of the problem itself.

In plain words Conditioning asks whether the question is sensitive. Stability asks whether the method adds avoidable error. A good method cannot rescue a sensitive question, and a poor method can spoil an easy one.

Example Solve 0.0001x+y=10.0001x + y = 1 and x+y=2x + y = 2, rounding every result to three significant digits. The exact solution is x=10000/9999≈1.0001x = 10000/9999 \approx 1.0001 and y=9998/9999≈0.9999y = 9998/9999 \approx 0.9999, and the coefficient matrix has condition number about 2.62.6, so the problem is well-conditioned. Without pivoting, R2→R2−10000R1R_2 \to R_2 - 10000R_1 gives −9999y=−9998-9999y = -9998, which rounds to −10000y=−10000-10000y = -10000. Then y=1y = 1, and the first equation becomes 0.0001x=00.0001x = 0, so x=0x = 0, a wrong answer. With pivoting the rows are exchanged first, and R2→R2−0.0001R1R_2 \to R_2 - 0.0001R_1 gives 0.9999y=0.99980.9999y = 0.9998, which rounds to 1.00y=1.001.00y = 1.00. Then y=1y = 1 and x=2−1=1x = 2 - 1 = 1, correct to three digits.

The normal equations show the opposite effect. For XX with diagonal entries 11 and 0.010.01, which has condition number 100100,

X⊤X=[1000.0001],X^{\top}X = \begin{bmatrix} 1 & 0 \\ 0 & 0.0001 \end{bmatrix},

whose condition number is 10410^4.

Residual versus solution error

Definition Let AA be an invertible n×nn \times n matrix, let x\mathbf{x} be the exact solution of Ax=bA\mathbf{x} = \mathbf{b}, and let x^\hat{\mathbf{x}} be any proposed solution. Its residual r=b−Ax^\mathbf{r} = \mathbf{b} - A\hat{\mathbf{x}} lives in the output space, and its error e=x−x^\mathbf{e} = \mathbf{x} - \hat{\mathbf{x}} lives in the input space. They are related by Ae=rA\mathbf{e} = \mathbf{r}, so

∥e∥≤∥A−1∥2 ∥r∥,\lVert \mathbf{e} \rVert \le \lVert A^{-1} \rVert_2 \, \lVert \mathbf{r} \rVert,

and when b≠0\mathbf{b} \ne \mathbf{0},

∥e∥∥x∥≤κ2(A) ∥r∥∥b∥.\frac{\lVert \mathbf{e} \rVert}{\lVert \mathbf{x} \rVert} \le \kappa_2(A) \, \frac{\lVert \mathbf{r} \rVert}{\lVert \mathbf{b} \rVert}.

A small residual guarantees a small error only when ∥A−1∥2\lVert A^{-1} \rVert_2, or in relative terms κ2(A)\kappa_2(A), is moderate.

In plain words The residual says how nearly the equations are satisfied, and the error says how far the proposal is from the answer. The proposal x^\hat{\mathbf{x}} solves the system exactly for the data b−r\mathbf{b} - \mathbf{r}, so a residual acts like a change in the data, and the conditioning decides how far such a change can move the solution.

Example Take DD with diagonal entries 11 and 0.010.01 and b=(1,0)\mathbf{b} = (1, 0), whose exact solution is x=(1,0)\mathbf{x} = (1, 0). The proposal x^=(1,1)\hat{\mathbf{x}} = (1, 1) gives Dx^=(1,0.01)D\hat{\mathbf{x}} = (1, 0.01), so the residual r=(0,−0.01)\mathbf{r} = (0, -0.01) has length 0.010.01. The error e=(0,−1)\mathbf{e} = (0, -1) has length 11, a hundred times larger. The error points along e2\mathbf{e}_2, which DD shrinks a hundredfold, so it leaves only a short residual.

Check yourself

  1. Find the condition number of the diagonal matrix with entries 44 and 12\tfrac{1}{2}. If the matrix and the right-hand side of a system with this matrix are both multiplied by 10001000, what happens to the solution, the determinant and the condition number?
Show the answer

The largest stretch is 44. The inverse has diagonal entries 14\tfrac{1}{4} and 22, so its norm is 22, and the condition number is 4⋅2=84 \cdot 2 = 8.

Multiplying both sides of every equation by 10001000 gives an equivalent system, so the solution does not change. The determinant grows from 22 to 10002⋅2=2×1061000^2 \cdot 2 = 2 \times 10^6. The norm of the scaled matrix is 40004000 and the norm of its inverse is 0.0020.002, so the condition number is still 88. A change of scale is not a change of sensitivity.

  1. Use the matrix AA and the data b=(2,2.01)\mathbf{b} = (2, 2.01) of the opening example. The candidate x^=(2,0)\hat{\mathbf{x}} = (2, 0) satisfies the first equation exactly and misses the second by only 0.010.01. Is it close to the solution?
Show the answer

No. The residual is

r=b−Ax^=[22.01]−[22]=[00.01],\mathbf{r} = \mathbf{b} - A\hat{\mathbf{x}} = \begin{bmatrix} 2 \\ 2.01 \end{bmatrix} - \begin{bmatrix} 2 \\ 2 \end{bmatrix} = \begin{bmatrix} 0 \\ 0.01 \end{bmatrix},

with length 0.010.01. The exact solution is (1,1)(1, 1), so the error is e=(1,1)−(2,0)=(−1,1)\mathbf{e} = (1, 1) - (2, 0) = (-1, 1), with length 2≈1.41\sqrt{2} \approx 1.41. This agrees with the bound ∥e∥≤∥A−1∥2∥r∥≈200.5⋅0.01≈2.005\lVert \mathbf{e} \rVert \le \lVert A^{-1} \rVert_2 \lVert \mathbf{r} \rVert \approx 200.5 \cdot 0.01 \approx 2.005. For this ill-conditioned matrix a small residual says little about the error.

  1. Let DD have diagonal entries 11 and 0.010.01, and let b=(1,0)\mathbf{b} = (1, 0). Compare the relative change in the solution caused by δb=(0.001,0)\delta\mathbf{b} = (0.001, 0) with the one caused by δb=(0,0.001)\delta\mathbf{b} = (0, 0.001). Which perturbation reaches the bound set by κ2(D)=100\kappa_2(D) = 100?
Show the answer

The solution is x=(1,0)\mathbf{x} = (1, 0), and ∥x∥=∥b∥=1\lVert \mathbf{x} \rVert = \lVert \mathbf{b} \rVert = 1. Both perturbations have relative size 0.0010.001.

The first gives δx=(0.001,0)\delta\mathbf{x} = (0.001, 0), a relative change of 0.0010.001, so it is not amplified at all. The second gives δx=(0,0.1)\delta\mathbf{x} = (0, 0.1), a relative change of 0.10.1, which is 100100 times the relative change in the data. Only the second reaches the bound. The condition number is a worst case, and whether a perturbation comes near it depends on its direction.

How this lesson connects

Where this leads in Linear Algebra II