A133 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 κ(x)=|xf′(x)f(x)| of four simple functions: how many times a relative change in x is magnified in f(x).
  • x halves relative errors everywhere. ex magnifies them by x, so it's sensitive only for large arguments.
  • ln⁡x and x−1 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 ∑(−20)k/k! in double gives e−20 as 6.1×10−9; the truth is 2.06×10−9. Whose fault is it?

Name it

Conditioning: a property of the problem

The relative condition number of evaluating f at x is

κ=|relative change in frelative change in x|≈|xf′(x)f(x)|

For a linear system Ax=b it's κ(A)=‖A‖‖A−1‖ (A7). Roughly, an answer loses log10⁡κ decimal digits to the unavoidable rounding of its inputs, whatever the algorithm.

Problemκ
x½
ex|x|
ln⁡x1/|ln⁡x|
x−a|x/(x−a)|
roots of a polynomialcan be enormous: Wilkinson's (x−1)(x−2)⋯(x−20), expanded, loses its roots near 16 and 17 to complex values when one coefficient changes by 2−23

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

relative error≲κ×(backward error)≈κu

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 r=12), 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 109 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
  1. The one-pass formula. It needs x2¯≈1018, where doubles are 128 apart, and subtracts x¯2 from it.
  2. What double gives. Summed left to right in double, the result is −128: a negative variance. (Python 3.12's built-in sum rounds more carefully and gets 0, which is still wrong.)
  3. The two-pass formula. Subtract the mean first, which leaves the deviations (−6,−3,3,6): σ2=36+9+9+364=22.5 exactly.
  4. 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 κ(A)≈1011. How many digits can you trust in its node voltages?

Show the solution
  1. Digits left. Double carries about 16 digits, and a condition number of 1011 can cost 11 of them: 16−11=5
  2. The solver can't help. A backward-stable solver (LU with pivoting) can't do better.
  3. 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

x2−2x+1−ε=0 has a double root at 1 when ε = 0. How far do the roots move when ε = 10−10?

Show the solution
  1. The perturbed roots. x=1±ε=1±10−5
  2. Compare the sizes. A change of 10−10 in a coefficient moved the roots by 10−5, a hundred thousand times more.
  3. 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 10−16, which moves a double root by about 10−16=10−8
  4. 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 1±10−5, a hundred thousand times more than the coefficient changed.

Check

What's the condition number of computing ln⁡x at x = 1.1?

Check

What's the condition number of computing ex at x = 20?

Check

A linear system has κ(A)=1010. About how many correct decimal digits can a backward-stable solver give in double?

Check

What's the condition number of computing x−a when x is 1.1 times a?

Check

How large is the largest term of the series for e−20, xxx!?

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 tan⁡x near its pole at π/2.

(a)

What is its relative condition number at x = 1.55?

(b)

About how many digits does that cost?

Check

Find relative condition numbers κ=|xf′(x)f(x)|.

Step 1

For f=ln⁡(1+x)?

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°.

Explain why

What's the difference between an ill-conditioned problem and an unstable 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.