Gaussian elimination

From Wikipedia, the free encyclopedia

In mathematics, Gaussian elimination (not to be confused with Gauss–Jordan elimination), named after Carl Friedrich Gauss, is an algorithm in linear algebra for determining the solutions of a system of linear equations, for determining the rank of a matrix, and for calculating the inverse of an invertible square matrix. Formally, the Gaussian elimination algorithm takes an arbitrary system of linear equations as input and returns its solution vector, if it exists and is unique. Equivalently, the algorithm takes an arbitrary matrix and reduces it to reduced row echelon form (also known as row canonical form). Elementary operations are used throughout the algorithm.

Contents

[edit] History

The method is named after the mathematician Carl Friedrich Gauss, but the earliest presentation of it can be found in the important Chinese mathematical text Jiuzhang suanshu or The Nine Chapters on the Mathematical Art, dated approximately 150 B.C.E.

[edit] Algorithm overview

The process of Gaussian elimination has two parts. The first part (Forward Elimination) reduces a given system to either triangular or echelon form, or results in a degenerate equation with no solution, indicating the system has no solution. This is accomplished through the use of elementary operations. The second step (Backward Elimination) uses back-substitution to find the solution of the system above.

Stated equivalently for matrices, the first part reduces a matrix to row echelon form using elementary operations while the second reduces it to reduced row echelon form, or row canonical form.

Another point of view, which turns out to be very useful to analyze the algorithm, is that Gaussian elimination computes a matrix decomposition. The three elementary operations used in the Gaussian elimination (multiplying rows, switching rows, and adding multiples of rows to other rows) amount to multiplying the original matrix with invertible matrices from the left. The first part of the algorithm computes an LU decomposition, while the second part writes the original matrix as the product of a uniquely determined invertible matrix and a uniquely determined reduced row-echelon matrix.

[edit] Example

Suppose the goal is to find and describe the solution(s), if any, of the following system of linear equations:

2x + y - z = 8 \quad (L_1)
-3x - y + 2z = -11 \quad (L_2)
-2x + y + 2z = -3 \quad (L_3)

The algorithm is as follows: eliminate x from all equations below L1, and then eliminate y from all equations below L2. This will put the system into triangular form. Then, using back-substitution, each unknown can be solved for.

In our example, we eliminate x from L2 by adding \begin{matrix}\frac{3}{2}\end{matrix} L_1 to L2, and then we eliminate x from L3 by adding L1 to L3. Formally:

L_2 + \frac{3}{2}L_1 \rightarrow L_2
L_3 + L_1 \rightarrow L_3

The result is:

2x + y - z = 8 \,
\frac{1}{2}y + \frac{1}{2}z = 1 \,
2y + z = 5 \,

Now we eliminate y from L3 by adding − 4L2 to L3:

L_3 + -4L_2 \rightarrow L_3

The result is:

2x + y - z = 8 \,
\frac{1}{2}y + \frac{1}{2}z = 1 \,
-z = 1 \,

This result is a system of linear equations in triangular form, and so the first part of the algorithm is complete.

The second part, back-substitution, consists of solving for the unknowns in reverse order. Thus, we can easily see that

z = -1 \quad (L_3)

Then, z can be substituted into L2, which can then be solved easily to obtain

y = 3 \quad (L_2)

Next, z and y can be substituted into L1, which can be solved to obtain

x = 2 \quad (L_1)

Thus, the system is solved.

This algorithm works for any system of linear equations. It is possible that the system cannot be reduced to triangular form, yet still have at least one valid solution: for example, if y had not occurred in L2 and L3 after our first step above, the algorithm would have been unable to reduce the system to triangular form. However, it would still have reduced the system to echelon form. In this case, the system does not have a unique solution, as it contains at least one free variable. The solution set can then be expressed parametrically (that is, in terms of the free variables, so that if values for the free variables are chosen, a solution will be generated).

In practice, one does not usually deal with the actual systems in terms of equations but instead makes use of the augmented matrix (which is also suitable for computer manipulations). This, then, is the Gaussian Elimination algorithm applied to the augmented matrix of the system above, beginning with:

\begin{bmatrix} 2 & 1 & -1 & 8 \\ -3 & -1 & 2 & -11 \\ -2 & 1 & 2 & -3 \end{bmatrix}

which, at the end of the first part of the algorithm looks like this:

\begin{bmatrix} 2 & 1 & -1 & 8 \\ 0 & \frac{1}{2} & \frac{1}{2} & 1 \\ 0 & 0 & -1 & 1 \end{bmatrix}

That is, it is in row echelon form.

At the end of the algorithm, we are left with

\begin{bmatrix} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 3 \\ 0 & 0 & 1 & -1 \end{bmatrix}

That is, it is in reduced row echelon form, or row canonical form.

[edit] Other applications

[edit] Finding the inverse of a matrix

Suppose A is a n \times n matrix and you need to calculate its inverse. The n \times n identity matrix is augmented to the right of A, forming a n \times 2n matrix (the block matrix B = [A,I]). Through application of elementary row operations and the Gaussian elimination algorithm, the left block of B can be reduced to the identity matrix I, which leaves A − 1 in the right block of B.

If the algorithm is unable to reduce A to triangular form, then A is not invertible.

In practice, inverting a matrix is rarely required. Most of the time, one is really after the solution of a particular system of linear equations.[1]

[edit] The general algorithm to compute ranks and bases

The Gaussian elimination algorithm can be applied to any m \times n matrix A. If we get "stuck" in a given column, we move to the next column. In this way, for example, any 6 \times 9 matrix can be transformed to a matrix that has a reduced row echelon form like

\begin{bmatrix} 1 & * & 0 & 0 & * & * & 0 & * & 0 \\ 0 & 0 & 1 & 0 & * & * & 0 & * & 0 \\ 0 & 0 & 0 & 1 & * & * & 0 & * & 0 \\  0 & 0 & 0 & 0 & 0 & 0 & 1 & * & 0 \\  0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\  0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0  \end{bmatrix}

(the *'s are arbitrary entries). This echelon matrix T contains a wealth of information about A: the rank of A is 5 since there are 5 non-zero rows in T; the vector space spanned by the columns of A has as basis the first, third, fourth, seventh and ninth column of A (the columns of the ones in T), and the *'s tell you how the other columns of A can be written as linear combinations of the basis columns.

[edit] Analysis

Gaussian elimination on an n × n matrix requires approximately 2n3 / 3 operations.

This algorithm can be used on a computer for systems with thousands of equations and unknowns. However, the cost becomes prohibitive for systems with millions of equations. These large systems are generally solved using iterative methods. Specific methods exist for systems whose coefficients follow a regular pattern (see system of linear equations).

The Gaussian elimination can be performed over any field.

Gaussian elimination is numerically stable for diagonally dominant or positive-definite matrices. For general matrices, Gaussian elimination is usually considered to be stable in practice if you use partial pivoting as described below, even though there are examples for which it is unstable.[2]

[edit] Pseudocode

As explained above, Gaussian elimination writes a given m × n matrix A uniquely as a product of an invertible m × m matrix S and a reduced row-echelon matrix T. Here, S is the product of the matrices corresponding to the row operations performed.

The formal algorithm to compute T from A follows. We write A[i,j] for the entry in row i, column j in matrix A. The transformation is performed "in place", meaning that the original matrix A is lost and successively replaced by T.

i=1
j=1
while (i ≤ m and j ≤ n) do
  #Find pivot in column j, starting in row i:
  max_val = A[i, j]
  max_ind = i
  for k=i+1 to m do
    val = A[k, j]
    if abs(val) > abs(max_val) then
      max_val = val
      max_ind = k
    end_if
  end_for
  if max_val ≠ 0 then
    switch rows i and max_ind #but remain the values of i and max_ind
    #Now A[i, j] will contain the same value as max_val
    divide row i by max_val
    #Now A[i, j] will have the value 1
    for u = i to m do
       if u ≠ i then
          subtract A[u, j] * row i from row u
          #Now A[u, j] will be 0, since A[u, j] - A[u, j] * A[i, j] = A[u, j] - 1 * A[u, j] = 0
       end_if
    end_for
    i = i + 1
  end_if
  j = j + 1
end_while

This algorithm differs slightly from the one discussed earlier, because before eliminating a variable, it first exchanges rows to move the entry with the largest absolute value to the "pivot position". Such a pivoting procedure improves the numerical stability of the algorithm; some variants are also in use.

The column presently being transformed is called the pivot column. Proceed from left to right, letting the pivot column be the first column, then the second column, etc. and finally the last column before the vertical line. For each pivot column, do the following two steps before moving on to the next pivot column:

  1. Locate the diagonal element in the pivot column. This element is called the pivot. The row containing the pivot is called the pivot row. Divide every element in the pivot row by the pivot to get a new pivot row with a 1 in the pivot position.
  2. Get a 0 in each position below the pivot position by subtracting a suitable multiple of the pivot row from each of the rows below it.

Upon completion of this procedure the augmented matrix will be in triangular echelon form and may be solved by back-substitution.

[edit] Notes

  1. ^ Atkinson (1989), p. 514
  2. ^ Golub and Van Loan, §3.4.6

[edit] References

  • Atkinson, Kendall A. An Introduction to Numerical Analysis, 2nd edition, John Wiley & Sons, New York, 1989. ISBN 0-471-50023-2.
  • Golub, Gene H., and Van Loan, Charles F. Matrix computations, 3rd edition, John Hopkins, Baltimore, 1996. ISBN 0-8018-5414-8.
  • Lipschutz, Seymour, and Lipson, Mark. Schaum's Outlines: Linear Algebra. Tata McGraw-hill edition.Delhi 2001. pp. 69-80.

[edit] External links