# Partial row reduction of a matrix

I have an $m\times n$ matrix (presumably of full rank) with $m>n$, and I would like to row reduce it, but leave the last column unreduced; that is, I want to get output on the form

$\pmatrix{ 1 & 0 & 0 & \ast \\ 0 & 1 & 0 & \ast \\ 0 & 0 & 1 & \ast \\ 0 & 0 & 0 & \ast \\ 0 & 0 & 0 & \ast}$

$\pmatrix{ 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 }$

which is what RowReduce gives me.

I can't seem to mangle RowReduce into doing it, and I would really like to avoid manually implementing the algorithm. Is there some nice way to do this?

• Have you tried the methods provided to the function? Apr 24, 2013 at 15:24
• If you're asking about the Methods option for RowReduce, they all give the default output. Apr 24, 2013 at 15:30

Augmenting the matrix with the identity matrix keeps track of the row reduction. Thus, row-reduce just the first three columns of the matrix and use the augmentation to row-reduce the original matrix in the same way:

(a = RandomInteger[{-5, 5}, {5, 4}]) // MatrixForm


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

(b = RowReduce[Join[a[[All, 1 ;; 3]], IdentityMatrix[Length@a], 2]] ) // MatrixForm


$$\left( \begin{array}{cccccccc} 1 & 0 & 0 & 0 & 0 & -\frac{19}{119} & \frac{5}{119} & \frac{1}{7} \\ 0 & 1 & 0 & 0 & 0 & \frac{33}{119} & -\frac{40}{119} & -\frac{1}{7} \\ 0 & 0 & 1 & 0 & 0 & \frac{2}{119} & \frac{12}{119} & \frac{1}{7} \\ 0 & 0 & 0 & 1 & 0 & -\frac{4}{7} & \frac{4}{7} & \frac{8}{7} \\ 0 & 0 & 0 & 0 & 1 & \frac{59}{119} & -\frac{122}{119} & -\frac{2}{7} \end{array} \right)$$

b[[All, 4 ;;]] . a // MatrixForm


$$\left( \begin{array}{cccc} 1 & 0 & 0 & \frac{13}{17} \\ 0 & 1 & 0 & -\frac{36}{17} \\ 0 & 0 & 1 & \frac{4}{17} \\ 0 & 0 & 0 & 2 \\ 0 & 0 & 0 & -\frac{18}{17} \end{array} \right)$$

• Thanks, that works. I guess it won't be too efficient (my matrices are rather huge), but it does at least give me the right output. Apr 24, 2013 at 15:53
• Matrix multiplication tends to be extremely fast. The join will be fast, too. Row-reducing the augmented matrix should (roughly) double the work and obviously doubles the RAM requirements. Apr 24, 2013 at 16:21