Categories

# 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:

## Syntax:

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

## 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)``````

## Output:

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

## 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)``

## 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

## Example:

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.

## Example:

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)``````

## Output:

The resultant equation is:

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 = .

## Example:

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

## Output:

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

## Limitations:

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.