Macaulay2 » Documentation
Packages » Macaulay2Doc > matrices > extracting information about a matrix
next | previous | forward | backward | up | index | toc

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

target

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 : M = target f

      2
o3 = R

o3 : R-module, free
Free modules are actually graded free modules, with the same sort of grading that the ring comes with. The degrees of the basis vectors of the target are always zero.
i4 : degree M_0

o4 = {0}

o4 : List
i5 : degree M_1

o5 = {0}

o5 : List

source

Likewise, to obtain the source of our linear transformation, use the source command.
i6 : N = source f

      4
o6 = R

o6 : R-module, free, degrees {3:1, 2}
If possible, the degrees of the basis vectors of the source are set so that the map f turns out to a homogeneous map of degree zero. This opportunism is important because certain algorithms will run faster on homogeneous maps.
i7 : degree N_0

o7 = {1}

o7 : List
i8 : degree N_1

o8 = {1}

o8 : List
i9 : degree N_2

o9 = {1}

o9 : List
i10 : degree N_3

o10 = {2}

o10 : List
i11 : isHomogeneous f

o11 = false
A list of the degrees of all the basis vectors can be obtained with degrees.
i12 : degrees N

o12 = {{1}, {1}, {1}, {2}}

o12 : List
It may happen that the matrix can not be made homogeneous. In that case, the degree of a basis vector is currently set to the degree of the largest monomial occurring in the corresponding column of the matrix. In a future version of the program it might be more sensible to set the degrees of the basis vectors all to zero.
i13 : g = matrix {{x,0,y*z},{y^2,x^2,0}}

o13 = | x  0  yz |
      | y2 x2 0  |

              2      3
o13 : Matrix R  <-- R
i14 : isHomogeneous g

o14 = false
i15 : degrees source g

o15 = {{2}, {2}, {2}}

o15 : List

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.
i16 : numgens target f

o16 = 2
i17 : numgens source f

o17 = 4

extracting an element from a matrix

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

o18 = x

o18 : 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.
i19 : entries f

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

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

ring

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

o20 = R

o20 : PolynomialRing
Use the describe command to recover how the ring of f was constructed.
i21 : describe ring f

o21 = QQ[x..z, Degrees => {3:1}, Heft => {1}]