Skip to content

Conditioning

Watch the crossing of two nearly parallel lines fly away at the smallest nudge, measure that danger with the condition number, and tell a hard problem from a bad method.

Helps to know first
This topic

First, the picture

Two lines cross at one point. Watch what a tiny nudge does to that point as the lines become almost parallel.

Nearly parallel lines

x + y = 2 and x + (1 + ε)y = 2 + ε cross at (1, 1). Jiggle the second right-hand side by 0.01.

Two lines, x + y = 2 and x + 2y = 3, crossing at (1, 1). The right-hand side of the second will jiggle by 0.01.

condition number
6.9
largest shift of the crossing
0.014
0.01
0.00 / 10.80 s
Describe this picture

One panel with two lines, x+y=2x+y=2 and x+(1+ε)y=2+εx+(1+\varepsilon)y=2+\varepsilon, which cross at (1,1)(1,1). Over 8 s the right-hand side of the second line is jiggled back and forth by 0.01, while ε\varepsilon shrinks from 1 to 0.01 and the lines close towards each other. The crossing point wobbles with the jiggle: by 0.014 at ε=1\varepsilon=1, 0.141 at 0.1, and 1.41 at 0.01. Readouts give the condition number, about 4/ε4/\varepsilon, and the shift of the crossing. A shaded segment marks the range the crossing wobbles over, and a ring marks (1,1)(1,1); at the end the jiggle settles and the crossing rests at (1,1)(1,1). One control: a slider sets ε\varepsilon on a log scale from 1 to 0.001, where the crossing moves by 14.1.

Two lines that almost agree

When two lines cross at a wide angle, moving one a little moves the crossing a little. When they are almost parallel, the same small move slides the crossing a long way along them. In the picture the nudge is always 0.01, but the crossing moves 100 times further at ε=0.01\varepsilon=0.01 than at ε=1\varepsilon=1.

Nothing is wrong with the arithmetic. The answer itself is sensitive: the data hardly decide where nearly parallel lines meet. A problem like that is ill-conditioned.

The condition number

The singular value decomposition turns the unit circle into an ellipse with semi-axes σ1\sigma_1 and σmin\sigma_\text{min}. The condition number is their ratio:

κ(A)=σ1σmin.\kappa(\mathbf{A})=\frac{\sigma_1}{\sigma_\text{min}}.

A round ellipse has κ=1\kappa=1; a long thin one has a large κ\kappa. Solving Ax=b\mathbf{A}\mathbf{x}=\mathbf{b} means running the ellipse backwards, and the short axis is where a small change in b\mathbf{b} becomes a big change in x\mathbf{x}. In numbers, a relative change in b\mathbf{b} can grow by up to κ\kappa in x\mathbf{x}:

∥Δx∥∥x∥≤κ(A) ∥Δb∥∥b∥.\frac{\lVert\Delta\mathbf{x}\rVert}{\lVert\mathbf{x}\rVert}\le\kappa(\mathbf{A})\,\frac{\lVert\Delta\mathbf{b}\rVert}{\lVert\mathbf{b}\rVert}.

For the lines in the picture, κ\kappa is 6.854 at ε=1\varepsilon=1, 42.08 at 0.1 and 402.0 at 0.01: about 4/ε4/\varepsilon once ε\varepsilon is small.

Watch out

A small determinant does not mean a badly conditioned matrix. Multiply [3045]\begin{bmatrix}3&0\\4&5\end{bmatrix} by 10−610^{-6}: its determinant drops from 15 to 1.5×10−111.5\times10^{-11}, but its ellipse only shrinks, keeping its shape, and κ\kappa stays 3. The condition number measures the shape of the ellipse, not its size.

Digits lost

A computer keeps about 16 significant digits. Solving a system with condition number κ\kappa can lose about log⁡10κ\log_{10}\kappa of them, through rounding errors that the problem itself amplifies.

Digits left

How many of a computer’s 16 digits survive a solve, by condition number.

A computer keeps about 16 digits. Solving with a matrix of condition number κ can lose about log₁₀ κ of them.

0.00 / 4.00 s
Describe this picture

Four bars, each the 16 digits a computer keeps, split into digits left (coloured, below) and digits lost (grey, on top), with the digits left written above. κ=3\kappa=3 loses about half a digit. κ=4×104\kappa=4\times10^4 loses 4.6. The 5×55\times5 Hilbert matrix, with κ\kappa about 4.8×1054.8\times10^5, loses 5.7. κ=1016\kappa=10^{16} loses them all. There is no control.

So a condition number of 10810^8 leaves about 8 trustworthy digits, and one of 101610^{16} leaves none: the answer is noise.

Hard problems and unstable methods

Two different things can go wrong, and they need different fixes.

A hard problem has a large κ\kappa. No method can do better than the problem allows; the remedy is to change the problem, for example by measuring something that separates the nearly parallel lines.

A bad method loses accuracy on a problem that is fine. Take

[10−20111]x=[12],\begin{bmatrix}10^{-20}&1\\1&1\end{bmatrix}\mathbf{x}=\begin{bmatrix}1\\2\end{bmatrix},

with κ=2.618\kappa=2.618, perfectly healthy, and answer very nearly (1,1)(1,1). Eliminate in the written order, as Elimination does for clarity, with no row exchange. The pivot is 10−2010^{-20}, the multiplier 102010^{20}, and the second pivot 1−10201-10^{20}, which a computer rounds to −1020-10^{20}: the 1 is lost. The computed answer comes out (0,1)(0,1). Exchange the two rows first, so the larger number is the pivot, and the answer comes out right. The lessons eliminate in order only for clarity; standard solvers always choose the largest pivot.

Squaring makes it worse. Forming A⊤A\mathbf{A}^\top\mathbf{A}, as the normal equations of Least squares do, squares the condition number: κ(A⊤A)=κ(A)2\kappa(\mathbf{A}^\top\mathbf{A})=\kappa(\mathbf{A})^2. For the matrix of QR factorisation with ε=10−8\varepsilon=10^{-8}, κ(A)=1.41×108\kappa(\mathbf{A})=1.41\times10^8 is manageable, but κ(A⊤A)=2×1016\kappa(\mathbf{A}^\top\mathbf{A})=2\times10^{16} is past what 16 digits can carry. That is the failing run of that page, and why least squares is solved by QR or the SVD.

In signal processing · sensitive poles

Second-order sections, in the signal processing course, splits a high-order filter into small pieces. The reason is conditioning: the poles of a high-order polynomial move wildly when its coefficients are rounded, while each two-pole piece keeps its poles where they belong.

Worked example

1. A nearly singular system. A=[1111.0001]\mathbf{A}=\begin{bmatrix}1&1\\1&1.0001\end{bmatrix} and b=(2, 2.0001)\mathbf{b}=(2,\,2.0001) give x=(1,1)\mathbf{x}=(1,1). Change b\mathbf{b} to (2, 2.0002)(2,\,2.0002). Subtracting the first row from the second gives 0.0001 y=0.00020.0001\,y=0.0002, so y=2y=2, x=0x=0: the answer jumps to (0,2)(0,2). The relative change in b\mathbf{b} is 10−4/2.8285=3.5×10−510^{-4}/2.8285=3.5\times10^{-5}; in x\mathbf{x} it is ∥(−1,1)∥/∥(1,1)∥=1\lVert(-1,1)\rVert/\lVert(1,1)\rVert=1. The change grew about 2.8×1042.8\times10^4 times, within the bound κ≈4.0×104\kappa\approx4.0\times10^4: the singular values are about 2 and 5×10−55\times10^{-5}.

2. Healthy matrices. [2−111]\begin{bmatrix}2&-1\\1&1\end{bmatrix} has σ=(13±1)/2\sigma=(\sqrt{13}\pm1)/2, that is 2.303 and 1.303, so κ=1.768\kappa=1.768. The matrix [3045]\begin{bmatrix}3&0\\4&5\end{bmatrix} has κ=6.708/2.236=3\kappa=6.708/2.236=3.

3. Eigenvalues can be sensitive too. [11ε1]\begin{bmatrix}1&1\\\varepsilon&1\end{bmatrix} has eigenvalues 1±ε1\pm\sqrt\varepsilon, as in Similar matrices and the Jordan form: a change of 10−1610^{-16} moves them by 10−810^{-8}.

Try these before you read the answers.

  • κ\kappa of a matrix with orthonormal columns? 1: it turns without stretching.
  • κ\kappa of diag(1, 0.001)\mathrm{diag}(1,\ 0.001)? 1000.
  • At κ=108\kappa=10^8, how many digits are left of 16? About 8.
  • If κ(A)=104\kappa(\mathbf{A})=10^4, what is κ(A⊤A)\kappa(\mathbf{A}^\top\mathbf{A})? 10810^8.

Where you’ll meet this

Polynomial fits. Fitting a high-degree polynomial gives columns 1,x,x2,…1,x,x^2,\dots that are nearly parallel, and a large condition number. Good fitting software reports it, or quietly works around it.

Adaptive filters. An adaptive filter that learns by small steps converges slowly when its input’s correlation matrix has a large condition number, as Adaptive filters: LMS shows.

Filters in hardware. A filter built as one high-order polynomial can become unstable from rounding alone; built from second-order sections it is far less likely to.

Reference card

QuantityFormulaNotes
Condition numberκ(A)=σ1/σmin\kappa(\mathbf{A})=\sigma_1/\sigma_\text{min}the ellipse’s long axis over its short axis
Sensitivity∥Δx∥/∥x∥≤κ ∥Δb∥/∥b∥\lVert\Delta\mathbf{x}\rVert/\lVert\mathbf{x}\rVert\le\kappa\,\lVert\Delta\mathbf{b}\rVert/\lVert\mathbf{b}\rVertthe worst case
Rangeκ≥1\kappa\ge11 for orthonormal columns times a number
Digits lostabout log⁡10κ\log_{10}\kappaof about 16 in double precision
Normal equationsκ(A⊤A)=κ(A)2\kappa(\mathbf{A}^\top\mathbf{A})=\kappa(\mathbf{A})^2use QR or the SVD instead
Scaleκ(cA)=κ(A)\kappa(c\mathbf{A})=\kappa(\mathbf{A})the determinant is no guide
Method mattersexchange rows to use the largest pivota healthy problem can still be solved badly

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look