Gaussian elimination
Encyclopedia : G : GA : GAU : Gaussian elimination
In mathematics, Gaussian elimination or Gauss–Jordan elimination, named after Carl Friedrich Gauss and Wilhelm Jordan (many regard Gaussian elimination as the front half of the complete Gauss–Jordan elimination), 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. When applied to a matrix, Gaussian elimination produces what is called "reduced row echelon form".
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.Numerical analysis
The computational complexity of Gaussian elimination is O(n3); that is, the number of operations required is (approximately) proportional to n3 if the matrix size is n × n.This algorithm can be used on a computer for systems with thousands of equations and unknowns. It is, however, numerically unstable, at least on pathological examples; that is, floating-point errors committed throughout the computation are accumulated and may produce results that are far from the correct solution. Because of these errors and the high computational cost of Gaussian elimination, large systems are general solved using iterative methods, generally based on finding a fixed point of a contraction mapping (see Banach fixed point theorem); specific methods exist for even larger systems whose coefficients follow a regular pattern (see system of linear equations). Gaussian elimination is, however, a good method for systems of equations over a field where computations are exact, such as finite fields.
Example
Suppose you need to find numbers x, y, and z such that the following three equations are all simultaneously true:- [2x + y - z = 8\,]
- [-3x - y + 2z = -11\,]
- [-2x + y + 2z = -3\,]
- multiply or divide an equation by a non-zero number
- switch two equations
- add or subtract a (not necessarily integer) multiple of one equation to another one
In our example, we eliminate x from the second equation by adding 3/2 times the first equation to the second, and then we eliminate x from the third equation by adding the first equation to the third. The result is:
- [2x + y - z = 8\,]
- [\begin \frac \endy + \begin \frac \endz = 1]
- [2y + z = 5\,]
- [2x - 2z = 6\,],
- [\begin \frac \endy + \begin \frac \endz = 1],
- [-z = 1\,]
- [2x = 4\,]
- [\begin \frac \endy = \begin \frac \end]
- [-z = 1\,]
This algorithm works generally, also for bigger systems. Sometimes it is necessary to switch two equations: for instance if y had not occurred in the second equation after our first step above, we would have switched the second and third equation and then eliminated y from the first equation. It is possible that the algorithm gets "stuck": for instance if y had not occurred in the second and the third equation after our first step above. In this case, the system does not have a unique solution.
Usually, in practice, one does not deal with the actual systems in terms of equations but instead makes use of the augmented matrix (which is also suitable for computer manipulations), so doing this, our original system would then look like
- [\begin2 & 1 & -1 & 8 \\-3 & -1 & 2 & -11 \\-2 & 1 & 2 & -3\end]
- [\begin2 & 0 & 0 & 4 \\0 & 1/2 & 0 & 3/2 \\0 & 0 & -1 & 1\end]
- [\begin1 & 0 & 0 & 2 \\0 & 1 & 0 & 3 \\0 & 0 & 1 & -1\end]
- Multiply or divide a row by a non-zero value.
- Switch two rows.
- Add or subtract a (not necessarily integer) multiple of one row to another row.
Row echelon and reduced row echelon form
Two special arrangements of matrix are called row echelon form and reduced row echelon form. The definitions of these terms depend on the first non-zero term in each row, called the row's leading coefficient. For a matrix to be in row echelon form (REF), the following conditions must be satisfied:
- All nonzero rows are above any rows of all zeroes.
- The leading coefficient of a row is always to the right of the leading coefficient of the row above it.
- All entries below a leading coefficient, if any, are zeroes.
- [\begin0 & 1 & 4 & 0 & -3 \\0 & 0 & 0 & 1 & 0 \\0 & 0 & 0 & 0 & 1 \\0 & 0 & 0 & 0 & 0 \\\end]
- each leading coefficient is 1.
- each leading coefficient is the only non-zero entry in its column.
Gaussian elimination amounts to using the matrix operations to obtain a matrix in RREF. All matrices have a unique equivalent matrix in RREF. When solving a linear system, sometimes there are no solutions and sometimes there are multiple solutions. Whichever is the case, converting the final matrix back into equations reveals the solutions (if any) of the system. For instance, if the above matrix represents a system in four variables, the third row corresponds to the equation 0 = 1, so the matrix represents a system with no solutions.
A system of equations is inconsistent (i.e., it has no solutions) if the RREF of the augmented matrix has a row which has all zeros except for the last element which is non-zero (i.e. 0 0 0 ... 0 | a, where a is non-zero.)
The following matrix in RREF represents a system with infinitely many solutions:
- [\begin1 & 2/3 & 0 & 11 \\0 & 0 & 1 & 7 \\\end]
A system of linear equations will have infinitely many solutions if the matrix in RREF form has more unknown variables than the total number of rows in RREF where each row has at least a non-zero entry.
Other applications
Finding the inverse of a matrix
Suppose A is a square n × n matrix and you need to calculate its inverse. The n × n identity matrix is augmented to the right of A, which produces an n × 2n matrix. Then you perform the Gaussian elimination algorithm on that matrix. When the algorithm finishes, the identity matrix will appear on the left; the inverse of A can then be found to the right of the identity matrix.If the algorithm gets "stuck" as explained above, 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.
The general algorithm to compute ranks and bases
The Gaussian elimination algorithm can be applied to any m × n matrix A. If we get "stuck" in a given column, we move to the next column. In this way, for example, any 6 by 9 matrix can be transformed to a matrix that has a reduced row echelon form like- [\begin1 & * & 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]
The Gaussian elimination can be performed over any field. 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 A with invertible m × m matrices from the left. In general, we can say:
- To every m × n matrix A over the field K there exists a uniquely determined invertible m × m matrix S and a uniquely determined reduced row-echelon matrix T such that A = ST.
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 = 1 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 + 1end_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.
Note that if the field is the real or complex numbers and floating point arithmetic is in use, the comparison max_val ≠ 0 should be replaced by abs(max_val) > epsilon for some small, machine-dependent constant epsilon, since it is rarely correct to compare floating point numbers to zero.
External links
- [Gauss elimination as java applet] at some local site. Only takes natural coefficients.
- [Algorithm for Gauss-Jordan elimination in Matlab]
- [Algorithm for Gauss-Jordan elimination in Python]
- [Algorithm for Gauss-Jordan elimination in C++]
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
