rref

Reduced row echelon form of a matrix, by Gauss-Jordan elimination.

Category: Mathematics > Linear Algebra

Syntax

R = rref(A)

Returns the reduced row echelon form.

[R, p] = rref(A)

Also returns the pivot column indices.

[R, p] = rref(A, tol)

Uses tol to decide when an entry is treated as zero.

Description

Elimination with partial pivoting brings the matrix to a form in which each pivot is 1 and is the only nonzero entry of its column. Applied to an augmented matrix [A b] it solves a linear system and shows whether it has no solution, one, or infinitely many.

Because it relies on a tolerance to detect zeros, rref is a teaching tool rather than a robust numerical method for large or ill-conditioned matrices.

Input arguments

A
Numeric matrix.
tol
Pivot tolerance. The default is eps * max(size(A)) * norm(A, inf).

Output arguments

R
Matrix of the same size as A with leading ones in the pivot columns and zeros elsewhere in those columns.
p
Row vector of the pivot columns; numel(p) is the rank.

Example

Solving a system

Ab = [1 1 3; 1 -1 1];
[R, p] = rref(Ab)
Output
R = 2×3

     1     0     2
     0     1     1
p = 1×2

     1     2

See also

rank lu null mldivide