2. After the Advance

Matlab rref

MATLAB inbuilt method rref is designed to form Reduced Row Echelon Form applying the ‘Gauss-Jordan elimination method’ and partial pivoting. This is used to remove the dependencies of successive rows of a matrix from each other, performing a set of operation on the rows. This functionality is useful to solve system linear equations easily. The resultant matrix from rref() function consists of zero at non-diagonal positions whereas diagonal positions gets occupied with Ones as shown below:

Matlab rref-1


The rref function in MATLAB can exhibit different behavior by dealing with different parameters of pivoting and each follows different syntax as explained below:

Rm = rref(M)This syntax can be used to create reduced row echelon form for the input matrix ‘M’by adopting the method of Gauss-Jordan elimination through partial pivoting.
Rm= rref(M,tol)This syntax can be used to create reduced row echelon form for the input matrix ‘M’witha pivot tolerance being specified, which is used by the algorithm to determine negligible columns.
[Rm,p] = rref(M)This syntax can be used to create reduced row echelon form for the input matrix ‘M’and results nonzero pivots p as return values.

Examples of Matlab rref

Following are the examples:

Example 1:

The below example is written to create a reduced row echelon form for a nXn matrix.

M = magic(3)
RA = rref(M)


As the input matrix is a full rank matrix, rref results in an identity matrix.

Matlab rref-1.1

Example 2:

The below code snippet is developed to find out the reduced row echelon form and non-zero pivot column for a nXn matrix.

M = magic(4)[RB,p] = rref(M)


Matlab rref-1.2


Input matrix (M)M is denoted for input matrix for which reduced row echelon form is expected in result.Rrefin MATLAB supports both data Types: single and double for input matrix value.Complex Numberare supported in rref() method.
Pivot tolerance (tol)Pivot tolerance (tol) is scalar input parameter for rref() method.The pivot tolerance acts as a threshold value for which, if the element largest with respect to its absolute value, present in a pivot column, is less than the tolerance value, then the respective column gets empty valued.This helps in preventing the arithmetic operations such as division and multiplication with elements from nonzero pivot column that are smaller than the tolerance.Rref in MATLAB supports both data types: single and double with respect topivot tolerance value.The Default pivot tolerance value is decided from the programming as:max(size(A))*eps*norm(A,inf)Value for this parameter is scalar by nature.
Reduced row echelon form of M (R)This parameter represents the resultant value of rref() method which is the Reduced row echelon form of the input matrix M.The output is generated in the form of a matrix.
Nonzero pivot columns (p)Nonzero pivot columns that is generated with the column index of the input matrix M.The value for this parameter results in the form of a vector.The pivot columns p can be used to find out several types of data such as:length(p) can be used to find estimation of the rank of the input matrix M.x(p) can be formed from the pivot variables contained in a linear system which can be presented in the form of: Ax = b.A basis for the range of the input matrix M can be formed by M(:,p).A identity matrix of size r-by-r can created using the notation R(1:r,p), where r is nothing but length(p).

Example 3:

An augmented matrix can be defined as an equivalent representation with respect to a system of linear equations. In the derived set of equation, when an equation is multiplied by a constant and is added to another equation, then the resultant solution consisting set of a new system is the same as the previous o


The below code generates reduced row echelon form for the augmented matrix M(:,4) using rref() method.

M = magic(3)M(:,4) = [2; 5; 3]R = rref(M)



Example 4:

1. Solving system equation: Rref() is usefull in order to solve set of linear equations.


The input matrix M for the system is derived from the coefficients of the variables as:

M = [2  2  10;
6  3  24;
2  4  14;
-3  3 -3];
b = [12 24 20 6]';
M = [M b];
R = rref(M)



The resultant equation is:

Matlab rref-1...

As there is not pivot element for third column, it shows that this system has multiple solutions.

2. Finding Matrix Inverse by reducing an Augmented Matrix

Rref() is used to find reverse of a matrix by following the algorithm as:

The Augmented matrix I: [A I] can be reduced to[I X];

Then X = .


M=[3 9 5;4 6 7;5 8 9]rref([M eye(size(M))])



Hence the answer is:

Matlab rref-1..2

The output can be validated by comparing the result from inv() method :




  1. In the computation of rank and basis vectors of a matrix, using orth, rank, and null is comparatively faster and accurate as compared to that of computing by means of rref non zero pivot column.
  2. In case of an input matrix being badly scaled or having a deficient rank or close to singular, mldivide function is recommended to use.

Additional Point:

  • In the calculation carried out in the operation of rref method, the application of partial pivoting in Gaussian elimination reduces round off errors, but it does not eliminate completely.
  • It can be said that matrix M is in row echelon form when the below conditions are satisfied:
  • All rows with nonzerovalues are above rows with all zeros.
  • For each row, the leading coefficient is exactly to the right of the element in the row, above it.

It qualifies to be reduced row echelon form when it satisfied the additional condition of having each leading coefficient as 1, and must be having only nonzero in the respective column.

Leave a Reply

Your email address will not be published. Required fields are marked *