2
$\begingroup$

What are some computations/ calculations in Sagemath which are done better/ more elegantly because of the existence of matrix spaces? Most of the times it seems to me that constructing matrices with matrix() would suffice.

$\endgroup$

1 Answer 1

3
$\begingroup$

The main reason for the existence of matrix spaces is to be the parent of matrices. This is especially useful for enabling conversion and coercion. In particular, they are used when you call change_ring() on a matrix.

So they perform important tasks mainly in the background, as good parents do.


They can sometimes be useful on the foreground, as seen in some examples in the documentation on Matrix Spaces.

  • Random elements:

    sage: Mat(QQ,2,5).random_element(density=0.5)
    [  2   0   0   0   1]
    [  0   0   0 1/2   0]
    
  • Basis of the space of matrices:

    sage: list(Mat(QQ,2).basis())
    [
    [1 0]  [0 1]  [0 0]  [0 0]
    [0 0], [0 0], [1 0], [0 1]
    ]
    
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .