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

inputting a matrix

by its entries

Using the function matrix is the most basic method for inputting a matrix. The entries are typed in by rows as a doubly nested list of ring elements.
i1 : R = ZZ/5[s..z];
i2 : M = matrix {{ x^2+y, z^3}, {y^3-z,3*z-6*x-5*y}}

o2 = | x2+y z3    |
     | y3-z -x-2z |

             2      2
o2 : Matrix R  <-- R
One way to construct a doubly nested list of ring elements is with the table command.
i3 : table(3,3,(i,j) -> R_i^j)

              2           2           2
o3 = {{1, s, s }, {1, t, t }, {1, u, u }}

o3 : List
i4 : p = matrix oo

o4 = | 1 s s2 |
     | 1 t t2 |
     | 1 u u2 |

             3      3
o4 : Matrix R  <-- R
i5 : q = matrix table(3,3,(i,j) -> R_j^i)

o5 = | 1  1  1  |
     | s  t  u  |
     | s2 t2 u2 |

             3      3
o5 : Matrix R  <-- R

by a function

The function map can be used to construct matrices.
i6 : G = map(R^3,3,(i,j)->R_i^j)

o6 = | 1 s s2 |
     | 1 t t2 |
     | 1 u u2 |

             3      3
o6 : Matrix R  <-- R
i7 : f = 3*s^2*v-t*u*v+s*t^2

        2     2
o7 = s*t  - 2s v - t*u*v

o7 : R
i8 : H = map(R^4,R^4,(i,j)->diff(R_j*R_i,f))

o8 = | v  2t 0  s  |
     | 2t 2s -v -u |
     | 0  -v 0  -t |
     | s  -u -t 0  |

             4      4
o8 : Matrix R  <-- R

identity matrix

The function id is used to form the identity matrix as a map from a module to itself.
i9 : id_(R^3)

o9 = | 1 0 0 |
     | 0 1 0 |
     | 0 0 1 |

             3      3
o9 : Matrix R  <-- R
i10 : id_(source M)

o10 = {3} | 1 0 |
      {3} | 0 1 |

              2      2
o10 : Matrix R  <-- R
The first example gives a 3x3 identity matrix with entries in the ring R. The second gives a 2x2 identity matrix whose source and target are the (graded) source of the matrix M.