A13 · Lesson 3 · Conditioning and stability
Is the problem sensitive, or is the method careless?
When a computed answer comes out wrong, there are two very different possible culprits. The problem itself may be ill-conditioned: so sensitive that a change in the 16th digit of the input changes the 5th digit of the answer, and no algorithm can do better. Or the problem is fine and the algorithm is unstable: it amplifies rounding errors that a better method wouldn't. The distinction tells you what to fix. An ill-conditioned problem needs better data or a reformulation; an unstable algorithm needs replacing. Most of this course is about choosing stable algorithms and knowing the condition of the problems they solve.
- The curves are the condition numbers of four simple functions: how many times a relative change in x is magnified in f(x).
- halves relative errors everywhere. magnifies them by x, so it's sensitive only for large arguments.
- and blow up near x = 1: there the answer is near zero, so any absolute error in x is a huge relative error in the answer. The readouts give the digits lost at the marked x.
Predict
Summing the Taylor series in double gives as ; the truth is . Whose fault is it?
The algorithm's. Evaluating has condition number , so about 1 digit at risk. But the series adds and subtracts terms as large as to reach ; each carries an error near , larger than the answer. Computing , a series of all-positive terms, gives to full precision.
Name it
Conditioning: a property of the problem
The relative condition number of evaluating f at x is
For a linear system it's (A7). Roughly, an answer loses decimal digits to the unavoidable rounding of its inputs, whatever the algorithm.
| Problem | κ |
|---|---|
| ½ | |
| roots of a polynomial | can be enormous: Wilkinson's , expanded, loses its roots near 16 and 17 to complex values when one coefficient changes by |
Stability: a property of the algorithm
An algorithm is backward stable if its computed answer is the exact answer to a slightly perturbed problem, with the perturbation a few units of roundoff. Then
which is the best any method can promise. An unstable algorithm adds errors of its own: cancellation (lesson 2), growth through repeated steps (A12's explicit scheme past ), or large intermediate values like the alternating series above.
Checking which one you have
Perturb the input by a few ulps and rerun: if the answer moves a lot, the problem is ill-conditioned. Compare with a different, trusted method on the same input: if they disagree while the problem is well-conditioned, an algorithm is unstable.
Worked example
A sensor's readings are plus 4, 7, 13 and 16. Compute their variance as the mean of squares minus the square of the mean, and as the mean squared deviation.
Show the solution
- The one-pass formula. It needs , where doubles are 128 apart, and subtracts from it.
- What double gives. Summed left to right in double, the result is −128: a negative variance. (Python 3.12's built-in
sumrounds more carefully and gets 0, which is still wrong.) - The two-pass formula. Subtract the mean first, which leaves the deviations : exactly.
- Conditioning and stability. The problem is well-conditioned (the deviations are known to full precision); the one-pass algorithm is unstable.
Answer the one-pass formula gives −128 (0 with Python 3.12's sum); the two-pass formula gives the correct variance, 22.5.
Worked example
A circuit's nodal matrix has . How many digits can you trust in its node voltages?
Show the solution
- Digits left. Double carries about 16 digits, and a condition number of can cost 11 of them:
- The solver can't help. A backward-stable solver (LU with pivoting) can't do better.
- Where a large κ comes from. It usually means a nearly floating node or wildly different conductances (a 1 Ω part next to a 100 GΩ one). Rescaling or a better model is the fix.
Answer about 5 digits.
Worked example
has a double root at 1 when ε = 0. How far do the roots move when ε = ?
Show the solution
- The perturbed roots.
- Compare the sizes. A change of in a coefficient moved the roots by , a hundred thousand times more.
- No method avoids it. This is a conditioning problem, so any method, however careful, faces it: rounding the coefficients to doubles already perturbs them by about , which moves a double root by about
- In circuits. Near-double roots, like the poles of a lightly damped resonance, come out with only half the digits.
Answer the roots move to , a hundred thousand times more than the coefficient changed.
Check
What's the condition number of computing at x = 1.1?
Check
What's the condition number of computing at x = 20?
Check
A linear system has . About how many correct decimal digits can a backward-stable solver give in double?
Check
What's the condition number of computing when x is 1.1 times a?
Check
How large is the largest term of the series for , ?
Check
Two well-written solvers give answers that agree in only 4 digits on the same input, and perturbing the input in the 16th digit changes each answer in its 5th. What's the likely cause?
Check
Evaluate near its pole at .
(a)
What is its relative condition number at x = 1.55?
(b)
About how many digits does that cost?
Check
Find relative condition numbers .
Step 1
For ?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
For ?
Explain why
What's the difference between an ill-conditioned problem and an unstable algorithm?
Conditioning belongs to the problem: it says how much the exact answer changes when the input changes slightly, regardless of how the answer is computed. A problem with condition number κ loses about digits to the unavoidable rounding of its input, and no method can recover them. Stability belongs to the algorithm: a stable one gives the exact answer to a problem only slightly different from the one posed, so its error is about κ times the roundoff, as good as possible. An unstable algorithm does worse than that, because it amplifies rounding errors in its own intermediate steps, as summing an alternating series or subtracting nearly equal partial results does. An ill-conditioned problem needs better data or a reformulation; an unstable algorithm needs a better algorithm.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.