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.
Describe this picture
One panel with two lines, and , which cross at . Over 8 s the right-hand side of the second line is jiggled back and forth by 0.01, while shrinks from 1 to 0.01 and the lines close towards each other. The crossing point wobbles with the jiggle: by 0.014 at , 0.141 at 0.1, and 1.41 at 0.01. Readouts give the condition number, about , and the shift of the crossing. A shaded segment marks the range the crossing wobbles over, and a ring marks ; at the end the jiggle settles and the crossing rests at . One control: a slider sets 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 than at .
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 and . The condition number is their ratio:
A round ellipse has ; a long thin one has a large . Solving means running the ellipse backwards, and the short axis is where a small change in becomes a big change in . In numbers, a relative change in can grow by up to in :
For the lines in the picture, is 6.854 at , 42.08 at 0.1 and 402.0 at 0.01: about once is small.
Watch out
A small determinant does not mean a badly conditioned matrix. Multiply by : its determinant drops from 15 to , but its ellipse only shrinks, keeping its shape, and 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 can lose about 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.
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. loses about half a digit. loses 4.6. The Hilbert matrix, with about , loses 5.7. loses them all. There is no control.
So a condition number of leaves about 8 trustworthy digits, and one of 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 . 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
with , perfectly healthy, and answer very nearly . Eliminate in the written order, as Elimination does for clarity, with no row exchange. The pivot is , the multiplier , and the second pivot , which a computer rounds to : the 1 is lost. The computed answer comes out . 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 , as the normal equations of Least squares do, squares the condition number: . For the matrix of QR factorisation with , is manageable, but 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. and give . Change to . Subtracting the first row from the second gives , so , : the answer jumps to . The relative change in is ; in it is . The change grew about times, within the bound : the singular values are about 2 and .
2. Healthy matrices. has , that is 2.303 and 1.303, so . The matrix has .
3. Eigenvalues can be sensitive too. has eigenvalues , as in Similar matrices and the Jordan form: a change of moves them by .
Try these before you read the answers.
- of a matrix with orthonormal columns? 1: it turns without stretching.
- of ? 1000.
- At , how many digits are left of 16? About 8.
- If , what is ? .
Where you’ll meet this
Polynomial fits. Fitting a high-degree polynomial gives columns 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
| Quantity | Formula | Notes |
|---|---|---|
| Condition number | the ellipse’s long axis over its short axis | |
| Sensitivity | the worst case | |
| Range | 1 for orthonormal columns times a number | |
| Digits lost | about | of about 16 in double precision |
| Normal equations | use QR or the SVD instead | |
| Scale | the determinant is no guide | |
| Method matters | exchange rows to use the largest pivot | a healthy problem can still be solved badly |