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

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.
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

by a function

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

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

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

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

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

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

             4       4
o5 : Matrix R  <--- R

identity matrix

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

o6 = | 1 0 0 |
     | 0 1 0 |
     | 0 0 1 |

             3       3
o6 : Matrix R  <--- R
i7 : id_(source M)

o7 = {3} | 1 0 |
     {3} | 0 1 |

             2       2
o7 : 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.