Gauss-Jordan reduction: rref gaussjord

### 5.56.3 Gauss-Jordan reduction: rref gaussjord

The reduced row echelon form of a matrix is the row echelon form (see previous section) with 0s 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 5.34.17).

- rref takes one mandatory and one optional argument:
  - A, a matrix.
  - Optionally, n, a positive integer.
- rref(A ⟨ n⟩) 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.

#### Examples.

- Solve the system:

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

  Input:
  rref([[3,1,-2],[3,2,2]])
  Output:

  ⎡ ⎢ ⎣ |
  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

  Input:
  rref([[3,1,-2,1],[3,2,2,2]])
  Output:

  ⎡ ⎢ ⎣ |
  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.
- Input:
  rref([[3,1,-2,1],[3,2,2,2]],1)
  Output:

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

  and Gauss-Jordan reduction has been performed only on the first column.