Suppose you wanted to fit a quadratic curve to the census data set.
format longg
load census
plot(cdate, pop, 'o-')
Let's build the coefficient matrix.
A = [cdate.^2, cdate.^1, cdate.^0]
The elements of A vary in magnitude from 1 to nearly 4 million.
[minValue, maxValue] = bounds(A, 'all')
cond(A)
By the rule of thumb cited on that Wikipedia page, "As a rule of thumb, if the condition number is , then you may lose up to k digits of accuracy on top of what would be lost to the numerical method due to loss of precision from arithmetic methods."
What if we centered and scaled the date data and used the centered and scaled data in the construction of A?
normalizedCdate = normalize(cdate, 'zscore');
Normalizing using 'zscore' (the default) results in normalized data with mean 0 and standard deviation 1.
mean(normalizedCdate) % close enough to 0
std(normalizedCdate)
If we build the coefficient matrix with this data:
A2 = normalizedCdate.^[2 1 0]
the range of elements is much smaller:
[minValue, maxValue] = bounds(A2, 'all')
This matrix is much better conditioned.
cond(A2)
log10(cond(A2))
Instead of losing 9 digits of accuracy we're losing less than half a digit.
coefficients1 = A\pop
coefficients2 = A2\pop
Note that we could be required to multiply a number near 4 million by a small number (0.0065...) if we want to use coefficients1 to evaluate the fit. If we want to use coefficients2 we're multiplying a number between say -2 and 2.5 by 25.1833....