Skip to content

MATLAB - Reduced Row Echelon Form

The Reduced Row Echelon Form (RREF) is a unique form of a matrix that is central to solving systems of linear equations and understanding matrix properties in linear algebra. It is obtained by applying a sequence of elementary row operations to a matrix. MATLAB’s built-in rref function provides a powerful and numerically stable way to compute it.

A matrix is in Reduced Row Echelon Form if it satisfies all of the following conditions:

  • Leading 1s: The first non-zero entry in each non-zero row, called the pivot, must be 1.
  • Pivot Columns: Each pivot (leading 1) is the only non-zero entry in its column.
  • Staircase Pattern: The pivot in any row is always to the right of the pivot in the row above it.
  • Zero Rows: All rows containing only zeros are at the bottom of the matrix.

Understanding the manual steps of Gaussian-Jordan elimination helps in appreciating what the rref function does. Let’s find the RREF of matrix A:

$$ A = \begin{bmatrix} 1 & 2 & 1 \ 2 & 4 & -3 \ 3 & 6 & 4 \end{bmatrix} $$

Step 1: The first pivot is already 1. Use it to create zeros below it.

$$ R_2 \leftarrow R_2 - 2 \times R_1 \implies \begin{bmatrix} 1 & 2 & 1 \ 0 & 0 & -5 \ 3 & 6 & 4 \end{bmatrix} $$

$$ R_3 \leftarrow R_3 - 3 \times R_1 \implies \begin{bmatrix} 1 & 2 & 1 \ 0 & 0 & -5 \ 0 & 0 & 1 \end{bmatrix} $$

Step 2: Move to the next pivot. The next available pivot is in the third column. Let’s make it 1 (it already is in R3). Swap R2 and R3 to get the staircase form.

$$ R_2 \leftrightarrow R_3 \implies \begin{bmatrix} 1 & 2 & 1 \ 0 & 0 & 1 \ 0 & 0 & -5 \end{bmatrix} $$

Step 3: Use the new pivot in R2 to create zeros above and below it.

$$ R_1 \leftarrow R_1 - 1 \times R_2 \implies \begin{bmatrix} 1 & 2 & 0 \ 0 & 0 & 1 \ 0 & 0 & -5 \end{bmatrix} $$

$$ R_3 \leftarrow R_3 + 5 \times R_2 \implies \begin{bmatrix} 1 & 2 & 0 \ 0 & 0 & 1 \ 0 & 0 & 0 \end{bmatrix} $$

The resulting matrix is now in RREF.

MATLAB automates this entire process with the rref function.

R = rref(A)
[R, p] = rref(A)
R = rref(A, tol)
  • R = rref(A): Returns the RREF of matrix A using Gauss-Jordan elimination with partial pivoting for numerical stability.
  • [R, p] = rref(A): Also returns a vector p containing the indices of the pivot columns.
  • R = rref(A, tol): Uses a specified tolerance tol to determine which elements are negligible and should be treated as zero. This is crucial for working with real-world data that may have floating-point inaccuracies.

Example 1: Solving a System of Linear Equations

Section titled “Example 1: Solving a System of Linear Equations”

Consider the system: 2x + 4y = 10 4x + 9y = 19

% Define the augmented matrix [coefficients | constants]
A = [2 4 10; 4 9 19];
% Compute the Reduced Row Echelon Form
R = rref(A);
% Display the result
disp('The Augmented Matrix:');
disp(A);
disp('The RREF is:');
disp(R);

Output:

The Augmented Matrix:
2 4 10
4 9 19
The RREF is:
1 0 7
0 1 -1

The RREF [1 0 | 7; 0 1 | -1] translates back to the equations:

  • 1x + 0y = 7 => x = 7
  • 0x + 1y = -1 => y = -1

This is a system with a unique solution.

Floating-point numbers can introduce small errors. The tol parameter helps rref distinguish between significant values and numerical noise.

% A matrix that is nearly rank-deficient
A = [1 2 3; 2 4 6.000001; 3 6 9];
% --- Using the default (small) tolerance ---
% The tiny difference is considered significant.
R_low_tol = rref(A);
disp('RREF with default low tolerance:');
disp(R_low_tol);
% --- Using a larger tolerance ---
% The tiny difference is treated as zero.
tol = 1e-5; % Any value smaller than this is treated as 0
R_high_tol = rref(A, tol);
disp('RREF with higher tolerance of 1e-5:');
disp(R_high_tol);

Output:

RREF with default low tolerance:
1 2 0
0 0 1
0 0 0
RREF with higher tolerance of 1e-5:
1 2 3
0 0 0
0 0 0

Besides solving linear systems, RREF is used to:

  • Find the rank of a matrix: The rank is the number of non-zero rows (or pivots) in its RREF.
  • Find the basis for the null space (kernel): By solving the system Ax=0 using the RREF of A.
  • Determine linear independence of a set of vectors.