next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > matrices > random and generic matrices

random and generic matrices

random matrices

To construct a random m by n matrix with entries in a ring R use the function random by typing random(R^m,R^n).
i1 : R = GF(3^2,Variable => a);
i2 : random(R^3,R^4)

o2 = | a  1   -a-1 a-1  |
     | -a a+1 -a-1 a-1  |
     | 0  a   -a   -a-1 |

             3       4
o2 : Matrix R  <--- R
Over a polynomial ring, this will select elements in the base ring or field. To obtain a matrix of (say) linear polynomials, use
i3 : T = R[x,y];
i4 : random(T^3,T^{4:-1})

o4 = | -x+(-a-1)y    -ax+y          (a-1)x+(-a-1)y -ax+y          |
     | (a+1)x+(a-1)y -x+y           (-a-1)x+(a-1)y ax+y           |
     | (a-1)x+(a-1)y (a-1)x+(-a+1)y -x+ay          (-a-1)x+(a+1)y |

             3       4
o4 : Matrix T  <--- T

matrices of variables

To build an m by n matrix of variables drawn from the ring R, use genericMatrix. The syntax is genericMatrix(R,x,m,n) where R is the ring, x is the variable where we start and m and n specify the size of the matrix.
i5 : S = R[p..z];
i6 : genericMatrix(S,t,3,2)

o6 = | t w |
     | u x |
     | v y |

             3       2
o6 : Matrix S  <--- S
Note that to use the function genericMatrix the number of variables in the ring R must be at least as large as m*n.

genericSymmetricMatrix

To construct an n by n symmetric matrix whose entries on and above the diagonal are the variables of R use genericSymmetricMatrix. The syntax is genericSymmetricMatrix(R,x,n) where R is the ring, x is the variable you want to start with and n is the size of the matrix.
i7 : genericSymmetricMatrix(S,s,3)

o7 = | s t u |
     | t v w |
     | u w x |

             3       3
o7 : Matrix S  <--- S

genericSkewMatrix

To construct an n by n skew symmetric matrix whose entries above the diagonal are the variables of R use genericSkewMatrix. The syntax is genericSkewMatrix(R,x,n) where R is the ring, x is the variable you want to start with and n is the size of the matrix.
i8 : genericSkewMatrix(S,u,3)

o8 = | 0  u  v |
     | -u 0  w |
     | -v -w 0 |

             3       3
o8 : Matrix S  <--- S