Gauss Elimination Method
Multiple Sets of Equations
As mentioned before, it is frequently necessary to solve the equations Ax = b for several constant vectors. Let there be m such constant vectors, denoted by
b 1 , b 2 ,..., b m and let the corresponding solution vectors be x 1 , x 2 ,..., x m . We denote multiple sets of equations by AX = B, where
X= x 1 x 2 ···x m
B= b 1 b 2 ···b m
are n × m matrices whose columns consist of solution vectors and constant vectors, respectively.
An economical way to handle such equations during the elimination phase is to include all m constant vectors in the augmented coefficient matrix, so that they are transformed simultaneously with the coefficient matrix. The solutions are then obtained by back substitution in the usual manner, one vector at a time. It would quite easy to make the corresponding changes in gauss . However, the LU decomposition method, described in the next article, is more versatile in handling multiple constant vectors.
EXAMPLE 2.3 Use Gauss elimination to solve the equations AX = B, where
A= ⎥
B= ⎣ 36 −18 ⎦
Solution The augmented coefficient matrix is
The elimination phase consists of the following two passes: row 2 ← row 2 + (2/3) × row 1
row 3 ← row 3 − (1/6) × row 1 ⎡
35 0 In the solution phase, we first compute x 1 by back substitution:
X 31 = 5/2 = 14
X 80/3 + (10/3)X 31 21 80/3 + (10/3)14 =
X −14 + 4X 21 −X 31 11 −14 + 4(22) − 14 =
6 = 10 Thus the first solution vector is
x 1 = X 11 X 21 X 31 = 10 22 14 The second solution vector is computed next, also using back substitution:
X 32 =0
X −10/3 + (10/3)X 32 22 −10/3 + 0 = = = −1
X 22 + 4X 22 −X 32 12 22 + 4(−1) − 0 =
6 =3 Therefore,
x 2 = X 12 X 22 X 32 = 3 −1 0
EXAMPLE 2.4 An n × n Vandermode matrix A is defined by
i = 1, 2, . . . , n, j = 1, 2, . . . , n where v is a vector. In MATLAB a Vandermode matrix can be generated by the com-
A ij =v n− j i ,
mand vander(v) . Use the function gauss to compute the solution of Ax = b, where
A is the 6 × 6 Vandermode matrix generated from the vector
Also evaluate the accuracy of the solution (Vandermode matrices tend to be ill- conditioned).
Solution We used the program shown below. After constructing A and b, the output format was changed to long so that the solution would be printed to 14 decimal places. Here are the results:
% Example 2.4 (Gauss elimination) A = vander(1:0.2:2); b = [0 1 0 1 0 1]’; format long [x,det] = gauss(A,b) x=
1.0e+004 * 0.04166666666701 -0.31250000000246 0.92500000000697 -1.35000000000972 0.97093333334002 -0.27510000000181
det = -1.132462079991823e-006
As the determinant is quite small relative to the elements of A (you may want to print A to verify this), we expect detectable roundoff error. Inspection of x leads us to suspect that the exact solution is
x= 1250/3 −3125 9250 −13500 29128/3 −2751 in which case the numerical solution would be accurate to 9 decimal places.
Another way to gauge the accuracy of the solution is to compute Ax and compare the result to b:
>> A*x ans =
-0.00000000000091 0.99999999999909 -0.00000000000819 0.99999999998272 -0.00000000005366 0.99999999994998
The result seems to confirm our previous conclusion.