Some problems magnify every tiny error, and no algorithm can save them. Some algorithms ruin perfectly good problems. Telling the two apart is the most important diagnostic skill in numerical computing.
Md Mahbub E Noor · Assistant Professor CSE-3107 Numerical Methods · B.Sc. 3rd Year 1st Semester Department of CSE, University of Barishal
Today's goals
Define conditioning (a property of the problem) and stability (a property of the algorithm)
Compute the condition number of a function and of a matrix
Predict how many digits are lost: about log10κ
Recognise unstable algorithms and replace them with stable ones
Explain forward and backward error
Last time
Errors propagate through arithmetic; cancellation can destroy relative accuracy.
Today
Two questions behind every inaccurate answer: Is the problem sensitive?Is my method careless?
Solving two equations = finding where two lines cross.Change one line a tiny bit (a small data error).Lines at a wide angle: the answer hardly changes.Nearly parallel lines: the same tiny change moves the answer a long way.
In plain words
Some problems are touchy: a tiny change in the data changes the answer a lot
That is a property of the problem, not of the program
A good method (stable) adds no extra trouble of its own
New words today
well-conditioned
small data change → small answer change
ill-conditioned
small data change → large answer change
condition number κ
how much errors are magnified
stable algorithm
one that keeps its own rounding errors small
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
3 / 17
Problem vs algorithm
Conditioning (the problem)
How much does the exact answer change when the input changes a little?
Measured by the condition numberκ
Well-conditioned: κ small (≈ 1–100)
Ill-conditioned: κ huge; data errors are amplified
No algorithm can fix it; only better data, more precision or a reformulated problem
≠
Stability (the algorithm)
Does the algorithm keep its own rounding errors small?
Stable: the answer is as good as the conditioning allows
Unstable: errors grow inside the algorithm (e.g. by n! or by 108)
Fixable: choose a different algorithm for the same problem
κ≈4×104: expect to lose about 4–5 significant digits, whatever method we use.
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
7 / 17
Condition number of a matrix
Definitionκ(A)=∥A∥∥A−1∥≥1
What it guarantees∥x∥∥Δx∥≤κ(A)∥b∥∥Δb∥
∥A∥∞ = largest absolute row sum (easy by hand)
κ=1: perfect (e.g. identity, rotations)
Rule of thumb: digits lost ≈ log10κ(A)
Singular matrix: κ=∞. A small determinant alone does not mean ill-conditioned: 10−10I has κ=1
Full treatment of norms: Lecture 11
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
8 / 17
The famous Hilbert matrix
Hij=i+j−11; we solve Hx=b where the true x is all ones
The algorithm (Gaussian elimination with pivoting, Lecture 12) is stable
Yet the error grows from 10−14 to 10−3 as n goes 3 → 12
Because κ(H12)≈1016: all 16 digits are lost
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
9 / 17
An unstable algorithm for a well-conditioned problem
In=∫01xnex−1dx; integration by parts gives In=1−nIn−1
Start from I0=1−e−1 (rounded) and go forward: the error is multiplied by n each step
By n=20 it is multiplied by 20!≈2.4×1018: I20=−30.19, impossible
Run the same formula backwards from a rough guess: errors are divided by n: stable
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
10 / 17
Unstable algorithms and their stable replacements
Gaussian elimination without pivoting
A tiny pivot like 0.001 creates huge multipliers (Lecture 12). Fix: partial pivoting.
(1−cosx)/x2 for small x
Cancellation inside the algorithm. Fix:2sin2(x/2)/x2.
One-pass variance x2−xˉ2
Cancellation for large means. Fix: subtract the mean first (two passes).
Forward recurrence In=1−nIn−1
Error × n per step. Fix: run it backwards.
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
11 / 17
Forward error and backward error
Forward error: how wrong is the answer?∣x~−x∣
Backward error: for which nearby problem is the answer exact?min{∣Δ∣:x~ solves the problem with data d+Δ}
Linkforward error≲κ×backward error
Example: root of x2−2=0 computed as x~=1.4142
Forward error: ∣1.4142−2∣=1.36×10−5
Backward: 1.41422=1.99996164, so x~ is the exact root of x2−1.99996164=0: data changed by 3.8×10−5
A backward stable algorithm always gives the exact answer to a slightly perturbed problem
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
12 / 17
Diagnosing an inaccurate answer
well-conditioned + stable
Accurate ✓
x, Gaussian elimination with pivoting on a good matrix, 2sin2(x/2).
well-conditioned + unstable
Inaccurate, but fixable
Change the algorithm: pivot, rewrite, reverse the recurrence.
ill-conditioned + stable
Inaccurate, algorithm is innocent
Change the problem: better data, more precision, rescale, regularise. Hilbert matrix, nearly parallel lines.
ill-conditioned + unstable
Hopeless
Fix the algorithm first, then deal with the conditioning.
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
13 / 17
Practice
Practice problem
Problem 2"Distinguish between an ill-conditioned problem and an unstable algorithm. A well-conditioned problem can still yield an inaccurate computed result. Using one example each, illustrate (i) a well-conditioned problem ruined by an unstable algorithm, and (ii) an ill-conditioned problem for which no algorithm, however stable, can guarantee an accurate result."
How to write a complete answer
Definitions: conditioning = sensitivity of the exact solution to input changes (κ); stability = whether the algorithm keeps its own rounding errors from growing
(i) In=1−nIn−1 forward: well-conditioned integral, error × n! ⇒ I20=−30; or GE without pivoting on 0.001x+y=1,x+y=2
(ii) x+y=2, x+1.0001y=2.0001: changing 2.0001 → 2.0002 moves (1,1) to (0,2); κ≈4×104, true for any algorithm
Features in metres and in millimetres make the normal-equations matrix ill-conditioned. Standardising features (mean 0, std 1) reduces κ and speeds up training.
🛡️
Ridge regularisation
Solving (XTX+λI)w=XTy instead of XTXw=XTy caps the condition number: a cure for ill-conditioning (Lecture 23).
⛰️
Ill-conditioned loss surfaces
When the Hessian's eigenvalues differ a lot (ratio = κ), gradient descent zig-zags: exactly the situation studied in Lecture 25.
🔢
Adam's epsilon
Optimisers divide by v+ϵ with ϵ=10−8 so that a tiny denominator cannot amplify noise: a stability safeguard.
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
15 / 17
Checkpoint
Checkpoint · think, then discuss with your neighbourA linear system has κ(A)=1010 and is solved in double precision with a stable algorithm. About how many correct significant digits can we expect?
A16
B10
C6
D0
C. Double gives about 16 digits; log10κ=10 digits are lost: about 16−10=6 remain.
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
16 / 17
Summary
Key points
Conditioning belongs to the problem; stability to the algorithm
κf=∣xf′(x)/f(x)∣; κ(A)=∥A∥∥A−1∥; digits lost ≈ log10κ
Ill-conditioned: change the data or the problem. Unstable: change the algorithm
Forward error ≲ κ × backward error; a backward-stable algorithm solves a nearby problem exactly
Homework
Find κf(x) for f(x)=x10 and for f(x)=lnx. Where is each ill-conditioned?
For A=(1224.001) compute κ∞(A). How many digits would you lose?
Run the recurrence widget to n=25. At which n does the forward value first leave [0,1]?
Write a model answer to Problem 2 in your own words (half a page).
Next lecture
Root finding and the bisection method. The safest way to solve f(x)=0: trap the root in an interval and halve it, with a guaranteed error bound.
Md Mahbub E Noor
Lecture 5: Conditioning and Stability
University of Barishal
17 / 17
Keys →Space next step · ← back A reveal the whole slide number + Enter jump to slide S slide list · F full screen · N notes [] previous / next lecture · L lab In a code box: Ctrl+Enter runs the code