# Matrix echelon/upper diagonal form

Is there a way to find the echelon form of a matrix in Mathematica? I see there is a function to find the reduced echelon form, RowReduce[], but I can't see anything for the echelon or upper triangular form?

Thanks David.

-
add comment

## 2 Answers

Possibly what you want is the "U" part of an LU factorization. I'll illustrate using the same example as in another response. The code is pretty much straight out of the documentation for LUDecomposition.

m = {{1, 2, 3, 1, 0, 0}, {4, 5, 6, 0, 1, 0}, {7, 8, 9, 0, 0, 1}};

{lu, perm, cond} = LUDecomposition[m]

(* Out[227]= {{{1, 2, 3, 1, 0, 0}, {4, -3, -6, -4, 1, 0}, {7, 2, 0,
1, -2, 1}}, {1, 2, 3}, 1} *)

uu = lu*SparseArray[{i_, j_} /; j >= i -> 1, Dimensions[lu]]

(* Out[230]= {{1, 2, 3, 1, 0, 0}, {0, -3, -6, -4, 1, 0},
{0, 0, 0, 1, -2, 1}} *)

-
UpperTriangularize[] would be a more readable way to grab the upper-triangular factor, tho. –  Ｊ. Ｍ. Apr 22 at 23:14
@J. M. I'd have used it too, had I but known about it. –  Daniel Lichtblau Apr 22 at 23:28
add comment

I learned from this thread that you can use HermiteDecomposition. For example:

m = {{1, 2, 3, 1, 0, 0}, {4, 5, 6, 0, 1, 0}, {7, 8, 9, 0, 0, 1}};

{u,r}=HermiteDecomposition[m];
r//MatrixForm

MatrixForm/@{RowReduce[r],RowReduce[m]}


(Please see comments for more details about what r really is, turns out it's not necessarily the upper triangular)

-
Thanks. Will checkout HermiteDecomposition[]. –  David McHarg Apr 22 at 22:56
HermiteDecomposition is really a "reduced" echelon form. It just happens that, because it works over a ring and not a field, it cannot fully reduce above the pivots. That said, it might still be what the poster wants. –  Daniel Lichtblau Apr 22 at 23:00
add comment