The topic in class this week is abstract vector spaces. Sage does understand abstract vector spaces (and many other abstract algebraic structures) to some extent, but not in a way that is useful at the level of this class. So, here’s a brief discussion of creating matrices for computational practice.
First, for row reduction practice, it’s nice to be able to create a matrix of a given size and rank, with integer entries which aren’t too huge:
random_matrix(ZZ,4,5,algorithm='echelonizable',rank=3, upper_bound=7)
will create a random 4×5 matrix with rank 3, integer entries (that’s the ZZ), and entries no bigger than 7.
Second, for inverting matrices, it’s nice if A has integer entries and the inverse of A does, too. Since det(AB)=det(A)det(B), if the determinant of A is not +/-1 then the entries of A^{-1} will not be integers. The converse is also true, remarkably: if |det(A)|=1 then the entries of A^{-1} will be integers. (This is one of the very few useful applications of Cramer’s rule.) So, we need a way of creating matrices with determinant 1 (or -1). Such matrices are called “unimodular”:
random_matrix(ZZ,5,algorithm='unimodular',upper_bound=9)
will create a 5×5 matrix with integer entries, determinant 1, and entries no bigger than 9 (or maybe 8) in absolute value.
Have fun…