Accuracy, Condition Numbers and Pivoting: The Effect of Rounding
Accuracy, Condition Numbers and Pivoting: The Effect of Rounding
1
998
3
2995
and
x2 = 3.
This seems fine until you realize that backsolving the unrounded system gives
x1 = 1 and
x2 = 3.001.
Row Pivoting
A way to fix the problem is to use pivoting, which means to switch rows of the matrix. Since switching rows
of the augmented matrix just corresponds to switching the order of the equations, no harm is done:
1
2 5
.
.001 1 3
Exact elimination would produce
1
2
0 .998
39
5
2.995
40
5
3
x2 = 3,
4
1 2
3
0 1
6
7 .
0 2 10 10
Pivoting the 2nd and 3rd rows would produce
1 2
0 2
0 1
4
3
10 10 .
6
7
Condition number
In some systems, problems occur even without rounding. Consider the following augmented matrices:
1
1/2 3/2
1
1/2 3/2
and
.
1/2 1/3
1
1/2 1/3 5/6
Here we have the same A, but two different input vectors:
b1 = (3/2, 1)
and
b2 = (3/2, 5/6)
which are pretty close to one another. You would expect then that the solutions x1 and x2 would also be
close. Notice that this matrix does not need pivoting. Eliminating exactly we get
1 1/2 3/2
3/2
1 1/2
and
.
0 1/12 1/4
0 1/12 1/12
Now solving we find
x1 = (0, 3)
and
x2 = (1, 1)
which are not close at all despite the fact that we did the calculations exactly. This poses a new problem:
some matrices are very sensitive to small changes in input data. The extent of this sensitivity is measured
by the condition number. The definition of condition number is: consider all small changes A and b in
A and b and the resulting change, x, in the solution x. Then
Relative error of output
|x|/|x|
.
cond(A) max |A| |b| = max
Relative error of inputs
+
|A|
|b|
41
Put another way, changes in the input data get multiplied by the condition number to produce changes in
the outputs. Thus a high condition number is bad. It implies that small errors in the input can cause large
errors in the output.
In Matlab enter
> H = hilb(2)
which should result in the matrix above. Matlab produces the condition number of a matrix with the
command
> cond(H)
Thus for this matrix small errors in the input can get magnified by 19 in the output. Next try the matrix
> A = [ 1.2969 0.8648 ; .2161 .1441]
> cond(A)
For this matrix small errors in the input can get magnified by 2.5 108 in the output! (We will see this
happen in the exercise.) This is obviously not very good for engineering where all measurements, constants
and inputs are approximate.
Is there a solution to the problem of bad condition numbers? Usually, bad condition numbers in engineering contexts result from poor design. So, the engineering solution to bad conditioning is redesign.
Finally, find the determinant of the matrix A above:
> det(A)
which will be small. If det(A) = 0 then the matrix is singular, which is bad because it implies there
will not be a unique solution. The case here, det(A) 0, is also bad, because it means the matrix is
almost singular. Although det(A) 0 generally indicates that the condition number will be large, they
are actually independent things. To see this, find the determinant and condition number of the matrix
[1e-10,0;0,1e-10] and the matrix [1e+10,0;0,1e-10].
Exercises
11.1 Let
A=
1.2969
.2161
.8648
.1441
1 2
2 4
symbolically as above. Create a numerical version via Cn = double(Cs) and define the two vectors d1 = [4; 8] and d2 = [1; 1]. Solve the systems Cs*x = d1, Cn*x = d1, Cs*x = d2, and
Cn*x = d2. Explain the results. Does the symbolic or non-symbolic way give more information?
42
11.3 Recall the matrix A that you saved using A_equil_truss in exercise 9.1. (Enter > load A_equil_truss
or click on the file A_equil_truss.mat in the folder where you saved it; this should reproduce the
matrix A.)
Find the condition number for this matrix. Is it good or bad? Now change any of the entries in A
and recalculate the condition number and compare. What does this say about the equilateral truss?