next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
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 0    a+1 |
     | -1 a  -a-1 -a  |
     | -a 1  -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 = | a+1x-ay  a-1xa+1y -1xay  a+1y     |
     | 1x-1y    0        ay     a-1x1y   |
     | a-1xa-1y -a-1x1y  -1x-ay -1x-a-1y |

             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 = | 1t 1w |
     | 1u 1x |
     | 1v 1y |

             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 = | 1s 1t 1u |
     | 1t 1v 1w |
     | 1u 1w 1x |

             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 : genericSymmetricMatrix(S,u,3)

o8 = | 1u 1v 1w |
     | 1v 1x 1y |
     | 1w 1y 1z |

             3       3
o8 : Matrix S  <--- S