making random matrices

The random command can be used in various ways to make random matrices. We could assemble random polynomials into a doubly nested list and use matrix to enter them into a matrix.

i1 : R = ZZ/101[x,y,z];
i2 : matrix table(3,3,(i,j)->random(2,R))

o2 = {0} | 42x2-50xy+9y2+39xz-15yz-22z2   50x2+45xy-39y2-29xz+30yz+19z2  -38x2+2xy-36y2-4xz-16yz-6z2  |
     {0} | -32x2+31xy-38y2-32xz+31yz+24z2 -42x2-50xy+15y2-41xz+17yz-28z2 37x2-22xy+45y2-19xz-8yz-31z2 |
     {0} | -9x2+32xy+4y2-4xz-2yz+24z2     x2-45xy-15y2+15xz-10yz-2z2     21xy+7y2-42xz+13yz           |

             3       3
o2 : Matrix R  <--- R
i3 : matrix table(3,3,(i,j)->random(i-j,R))

o3 = {0} | -49                           0          0  |
     {0} | -41x+35y-15z                  8          0  |
     {0} | 20x2-13xy-44y2+16xz-46yz+50z2 -33x+33y+z 31 |

             3       3
o3 : Matrix R  <--- R

As usual, the degrees of the basis elements of the source and target of the map are determined from the polynomials' degrees. Alternatively, one could generate a free module with the appropriate degrees and use random to insert random matrix entries of the appropriate degree so as to make the matrix homogeneous.

i4 : random(R^3,R^{1,0,-1,-2})

o4 = {0} | 0 -1  20x-2y+46z 15x2+21y2+5xz+43yz+15z2       |
     {0} | 0 12  38x+4y+34z 32x2-50xy-48y2-15xz+33yz-38z2 |
     {0} | 0 -15 -40x-2z    -13x2-29xy-6y2+50xz-28yz+37z2 |

             3       4
o4 : Matrix R  <--- R
i5 : random(R^{1,0,-1},R^{1,0,-1})

o5 = {-1} | -33 -19x+7y+35z -18x2+22xy+21y2-36xz+27yz-28z2 |
     {0}  | 0   -8          8x-19y+40z                     |
     {1}  | 0   0           4                              |

             3       3
o5 : Matrix R  <--- R


topindexpreviousupnext