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.
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.
$\endgroup$
Commented
Apr 22, 2013 at 23:14
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)