HOME

PDF (letter size)

RREF.nb Mathematica notebook (current version)

Mathematica function showing Reduced Row Echelon Form (RREF) steps

Nasser M. Abbasi

January 31, 2024   Compiled on January 31, 2024 at 1:52am
1 Introduction and how to use
2 Examples showing how to use displayRREF

1 Introduction and how to use

This describes how to use RREF.nb which contains one Mathematica function called displayRREF which displays on the screen all the steps in the forward Gaussian elimination process and also in the backward phase to produced a reduced row-echelon form when applied on a matrix \(A\). The matrix can be square or rectangular.

To use, download the RREF.nb from the link given at the top. Open the notebook using Mathematica, and evaluate the whole notebook using Evaluation->Evaluate Notebook. Now the function displayRREF is loaded and ready to be used.

Open a new notebook to use the function. Examples of usage are given below.

It has an option to normalize the pivot to 1 or not. Also, it has an option to display each step or just show the final result.

Note that, pivot has to be noramlized to one if we are to obtain an RREF form, since that is the definition of RREF. But this option is there if needed for some other reasons.

There are two functions in the notebook. displayRREF which does reduced RREF, and displayREF which does only the forward Gaussian elimination phase.

Any bugs please let me know.

2 Examples showing how to use displayRREF

2.1 Example 1. RREF on square matrix
2.2 Example 2. RREF on rectangular matrix
2.3 Example 3. RREF on rectangular matrix
2.4 Example 4. RREF on symbolic matrix

More examples are shown in the notebook.

2.1 Example 1. RREF on square matrix

Given the matrix \[ \left ( \begin {array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \\ \end {array} \right ) \] The RREF is \[ \left ( \begin {array}{ccc} 1 & 0 & -1 \\ 0 & 1 & 2 \\ 0 & 0 & 0 \\ \end {array} \right ) \] To see the steps do

mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} 
displaymat = True; normalizePivot = True; 
{result, pivots} = displayRREF[mat, displaymat, normalizePivot]
 

Note that the default is to display the steps and to also normalized the pivot to one. So the above command can be reduced to

mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} 
{result, pivots} = displayRREF[mat]
 

2.2 Example 2. RREF on rectangular matrix

Given the matrix \[ \left ( \begin {array}{cccc} 1 & 2 & 2 & 4 \\ 1 & 3 & 3 & 5 \\ 2 & 6 & 5 & 6 \\ \end {array} \right ) \] The RREF is \[ \left ( \begin {array}{cccc} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & -3 \\ 0 & 0 & 1 & 4 \\ \end {array} \right ) \] To see the steps do

mat = {{1, 2, 2, 4}, {1, 3, 3, 5}, {2, 6, 5, 6}}; 
{result, pivots} = displayRREF[mat]
 

2.3 Example 3. RREF on rectangular matrix

Given the matrix

\[ \left ( \begin {array}{cccc} -7 & -6 & -12 & -33 \\ 5 & 5 & 7 & 24 \\ 1 & 0 & 4 & 5 \\ \end {array} \right ) \]

The RREF is

\[ \left ( \begin {array}{cccc} 1 & 0 & 0 & -3 \\ 0 & 1 & 0 & 5 \\ 0 & 0 & 1 & 2 \\ \end {array} \right ) \]

To see the steps do

mat = {{-7, -6, -12, -33}, {5, 5, 7, 24}, {1, 0, 4, 5}}; 
displaymat = True; normalizePivot = True; 
{result, pivots} = displayRREF[mat, displaymat, normalizePivot]
 

2.4 Example 4. RREF on symbolic matrix

Given \(A\) as \[ \left ( \begin {array}{ccccc} s & \sqrt {s} & 3 & 10 & s^2 \\ 1 & s & 2 s & 10 & 1 \\ 0 & 2 & 3 & 10 & s^9 \\ \frac {1}{s} & 5 & 3 & 8 & s+2 \\ \end {array} \right ) \]

The RREF is

\[ \left ( \begin {array}{ccccc} 1 & 0 & 0 & 0 & \frac {s \left (8 s^{21/2}-15 s^{19/2}-10 s^{5/2}-5 s^{3/2}-47 s^{10}+75 s^9+31 s^3-25 s^2+10 s+33 \sqrt {s}-66\right )}{-7 s^{3/2}+31 s^3-45 s^2+14 s+15 \sqrt {s}-30} \\ 0 & 1 & 0 & 0 & -\frac {s^2 \left (8 s^{10}-15 s^9-7 s^8+15 s^7-10 s^2+2 s+18\right )}{-7 s^{3/2}+31 s^3-45 s^2+14 s+15 \sqrt {s}-30} \\ 0 & 0 & 1 & 0 & \frac {-4 s^{21/2}+5 s^{19/2}+5 s^{5/2}+10 s^{3/2}+4 s^{12}-25 s^{11}+20 s^{10}-5 s^4-12 s^3+17 s^2-20 s-5 \sqrt {s}+10}{-7 s^{3/2}+31 s^3-45 s^2+14 s+15 \sqrt {s}-30} \\ 0 & 0 & 0 & 1 & \frac {-s^{21/2}+3 s^{5/2}+6 s^{3/2}-7 s^{12}+12 s^{10}+s^4-8 s^3+3 s^2-12 s-3 \sqrt {s}+6}{14 s^{3/2}-62 s^3+90 s^2-28 s-30 \sqrt {s}+60} \\ \end {array} \right ) \]

To see the steps do

mat = {{s, Sqrt[s], 3, 10, s^2}, 
       {1, s, 2*s, 10, 1}, 
       {0, 2, 3, 10, s^9}, 
       {1/s, 5, 3, 8, 2 + s}}; 
displaymat = True; normalizePivot = True; 
{result, pivots} = displayRREF[mat, displaymat, normalizePivot]