Gauss-Jordan reduction

### 15.7.3 Gauss-Jordan reduction

The reduced row echelon form of a matrix is the row echelon form (see previous section) with zeros above the leading 1s in each row. Gauss-Jordan reduction will turn any matrix into reduced row echelon form, and the reduced row echelon form of a matrix is unique. If the matrix is the augmented matrix of a system, then the reduced row echelon form of the matrix is the simplest form to solve the system. The rref command finds the reduced row echelon form of a matrix (see also Section 11.8.17).

- rref takes one mandatory and one optional argument:
  - A, a matrix.
  - Optionally, n, a positive integer, or keep_pivot, the symbol.
- rref(A ⟨,n,keep_pivot⟩) returns the reduced row echelon form of the matrix. With a second argument of n, Gauss-Jordan reduction will be performed on (at most) the first n columns. With the keep_pivot option, pivots are not normalized to 1s after reduction.

#### Examples

Solve the system:

| ⎧ ⎨ ⎩ |
3x+y | = | −2,
3x +2y | = | 2.

rref([[3,1,-2],[3,2,2]])

⎡ ⎢ ⎣ |
1 | 0 | −2
0 | 1 | 4
| ⎤ ⎥ ⎦

Hence x=−2 and y=4 is the solution of this system.

rref can also solve several linear systems of equations having the same matrix of coefficients by augmenting the matrix of coefficients by vectors representing the right hand side of the equations for each equation. For example, solve the systems:

| ⎧ ⎨ ⎩ |
3x+y | = | −2,
3x +2y | = | 2

and

| ⎧ ⎨ ⎩ |
3x+y | = | 1,
3x +2y | = | 2.

rref([[3,1,-2,1],[3,2,2,2]])

⎡ ⎢ ⎣ |
1 | 0 | −2 | 0
0 | 1 | 4 | 1
| ⎤ ⎥ ⎦

Which means that x=−2 and y=4 is the solution of the first system and x=0 and y=1 is the solution of the second system.

To perform Gauss-Jordan reduction only on the first column, input:

rref([[3,1,-2,1],[3,2,2,2]],1)

⎡ ⎢ ⎢ ⎢ ⎢ ⎣ |
1 |
1
3
− |
2
3
1
3
0 | 3 | 12 | 3
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎦