Notebooks · posts/the-error-follows-the-condition-number
The error of a linear solve follows the condition number
Gaussian elimination with partial pivoting solves Hilbert systems whose exact solution is all ones. From to 12 the condition number grows from 524 to , and the error grows with it, staying between 0.005 and 0.18 times , while the residual stays under . In least squares, fitting a degree-11 polynomial to 40 points, Householder QR is off by (about ), and the normal equations, which square , by 0.18.
Every computed answer here is compared with an exact one. The Hilbert systems
are scaled to have integer entries, so the system stored in the computer is the
exact system and its solution is exactly all ones; the Python reference
confirms it by solving in rational arithmetic with fractions. The exact
condition numbers come from mpmath at 80 digits, and numpy's
linalg.cond agrees with them to through . The
reference, posts/refs/the-error-follows-the-condition-number.py, also repeats
every solve in Python in the same order of operations (output beside it).
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.
Conditioning
The condition number , the ratio of the largest to the smallest singular value, bounds how much a relative change in or can change the solution of : by up to times as much. Rounding a number to double precision changes it, relative to its size, by at most half of (machine epsilon, the gap between 1 and the next double), so no method can promise better than about .
A method is backward stable if its answer is the exact solution of a nearby system, one whose data differ from and by a few relative. Its residual is then a few relative to , and its error is about . Gaussian elimination with partial pivoting (GEPP) behaves this way in practice. So a small residual says the method did its job, and it says nothing about the error when is large.
The Hilbert matrix is the standard ill-conditioned example; grows about 32 times with each row added. Multiplying by makes every entry an integer below , stored exactly, with the same . The right side is a sum of integers, also exact.
The condition number has to be computed too, and it runs into the same limit.
eig_sym finds the smallest eigenvalue to within about times the
largest, so comes out with a relative error below :
at and 4.4% at , where numpy's cond is off by
1.6%. The tests use the exact values.
In least squares the method sets the condition number
A least-squares fit asks for the that minimizes for a tall matrix . Here is the Vandermonde matrix of a polynomial fit, , at points , and the data are , so the coefficients sought are all ones.
The normal equations are the textbook route: a square system, solved here with the same elimination. But , so the error is about . Householder QR multiplies by reflections , each of which zeroes one column below the diagonal, until is upper triangular, . Reflections are orthogonal and change no lengths, so the problem becomes with , and the error is about .
The data are rounded when they are formed, which moves the exact
least-squares answer of the stored problem slightly away from all ones. The
Python reference computes that answer in rational arithmetic: it is at most
from ones (at degree 13), a small part of the errors below.
The singular values for come from one-sided Jacobi (lib/svd).