next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > matrices > extracting information about a matrix

extracting information about a matrix

Consider the ring R and the matrix f.
i1 : R = QQ[x,y,z];
i2 : f = matrix{{2,x,y,x^2},{z,32,2,x}}

o2 = | 2 x  y x2 |
     | z 32 2 x  |

             2       4
o2 : Matrix R  <--- R


From the above output, one sees that Macaulay2 considers f as a linear transformation. Use the target command to obtain the target of the linear transformation f.
i3 : target f

o3 = R

o3 : R-module, free


Likewise, to obtain the source of our linear transformation, use the source command.
i4 : source f

o4 = R

o4 : R-module, free, degrees {3:1, 2}

number of rows or columns

Use numgens to obtain the rank of a free module. Combining it with the commands target or source gives us a way to determine the number of rows or columns of a matrix f.
i5 : numgens target f

o5 = 2
i6 : numgens source f

o6 = 4

extracting an element from a matrix

To extract the (i,j)-th element of a matrix, type f_(i,j).
i7 : f_(1,3)

o7 = x

o7 : R
Note that the first number selects the row, starting at 0 and the second number selects the column, also starting at 0.

entries of a matrix

To obtain the entries of a matrix in the form of a list of lists, use the entries command.
i8 : entries f

o8 = {{2, x, y, x }, {z, 32, 2, x}}

o8 : List
Note that each inner list is a list of elements from a row of f.


The ring command can be used to return the ring of the matrix, that is, the ring containing entries of the matrix.
i9 : ring f

o9 = R

o9 : PolynomialRing
Use the describe command to recover how the ring of f was constructed.
i10 : describe ring f

o10 = QQ[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => {MonomialSize => 32}, DegreeRank => 1]
                                                               {GRevLex => {3:1}  }
                                                               {Position => Up    }