# Use Mathematica to calculate matrix range?

Mathematica has RowReduce[], how can I use this to calculate a basis for the range of any matrix?

Given

A={{1,1,1,1,2},{1,2,4,0,5},{2,1,-1,4,0},{-1,1,5,-1,2}};

RowReduce[A]=={{1,0,-2,0,1},{0,1,3,0,2},{0,0,0,1,-1},{0,0,0,0,0}}


The leading 1's in the reduced row echelon form select the first, second, and fourth column vectors of A as a basis for the range of A. How do I program mathematica to make that selection after calculating RowReduce[A]?

Firstly, there is no such thing as the basis. Secondly, the range of a transformation is generated by the columns, so RowReduce[Transpose[M]] ought to do it.

• This is not what I had in mind at all. Commented Apr 14, 2017 at 16:22
• @PhillipDukes Do you always speak in riddles? Commented Apr 14, 2017 at 17:12
• "This is not what I had in mind at all." - then @Phillip, can you come up with a formulation that won't confuse answerers? Commented Apr 14, 2017 at 18:31
• @J.M. thank you, I hope my example is clear enough. Commented Apr 14, 2017 at 20:32

Long form:

A = (* your matrix *)
reduced = RowReduce[A];
positions = DeleteMissing[FirstPosition[1] /@ reduced];
A[[Catenate[positions]]]


In one line:

basis[A_] :=
A[[Catenate[DeleteMissing[FirstPosition[1] /@ RowReduce[A]]]]]