I am wondering if there is a Mathematica command that will put a matrix in row echelon form. That is, put

$$ \begin{bmatrix} 1 & 2 & 3\\ 2 & 3 & 4\\ -1 & 0 & 2 \end{bmatrix} $$ in row echelon form: $$ \begin{bmatrix} 1 & 2 & 3\\ 0 & 1 & 2\\ 0 & 0 & 1\end{bmatrix} $$ I am aware that I can do a sequence of elementary row operations. I am also aware of the RowReduce command which puts a matrix in reduced row echelon form. I even saw a Method->"OneStepRowReduction" used by the RowReduce command which I thought might be the choice.

Just wondering if there is a command for this that I cannot find.

  • 2
    $\begingroup$ Your second matrix is not in row echelon form. $\endgroup$ – enzotib Mar 22 '15 at 13:21
  • $\begingroup$ What @enzotib quite correctly observes leads me to wonder if perhaps you actually want the "echelon" form over the ring of integers. That would be found with HermiteDecomposition. $\endgroup$ – Daniel Lichtblau Mar 22 '15 at 13:27
  • $\begingroup$ Fixed the row echelon error. Sorry about that. No, I just want the ordinary row echelon form students have to do when first introduced to Gaussian elimination. $\endgroup$ – David Mar 22 '15 at 15:12
  • $\begingroup$ Note that there is nothing unique about a row echelon form, even such a form whose leading entries are all 1. So the question needs to be restated in a more precise manner. E.g., do you want a command that follows a particular algorithm for obtaining a row echelon form? As you noted, it's easy to do a sequence of elementary row operations, and to write little functions to do such operations, then to write a main function that calls those little functions to follow a particular reduction algorithm. But then how do you want to handle roundoff errors? (Or do you want exact rational arithmetic?) $\endgroup$ – murray Mar 22 '15 at 20:24

I think LUDecomposition should be able to do this. Using code from help in Mathematica docs:

a = {{1, 2, 3}, {2, 3, 4}, {-1, 0, 2}};
{lu, p, c} = LUDecomposition[a]
(u = lu SparseArray[{i_, j_} /; j >= i -> 1, {3, 3}]) // MatrixForm

Mathematica graphics

If you want all pivots to be +1, this can now be easily done.

d = Position[Diagonal[u], -1]
(u[[First@#]] = -u[[First@#]]) & /@ d

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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