Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}$

instead of

$\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?

Thanks in advance for any help you can give me.

share|improve this question
    
Have you tried the methods provided to the function? –  Spawn1701D Apr 24 '13 at 15:24
1  
If you're asking about the Methods option for RowReduce, they all give the default output. –  Ketil Tveiten Apr 24 '13 at 15:30

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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. –  Ketil Tveiten Apr 24 '13 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. –  whuber Apr 24 '13 at 16:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.