5.4.1 linalg.matrix - Matrices

Elements of matrix spaces are of class Matrix. They can be either sparse or dense, and can be defined over any base ring.

We create the $ 2\times 3$ matrix

$\displaystyle \left(\begin{matrix}1&2&3 4&5&6 \end{matrix}\right)
$

as an element of a matrix space over $ \mathbf{Q}$ :

sage: M = MatrixSpace(RationalField(),2,3)
sage: A = M([1,2,3, 4,5,6])
sage: A
[1 2 3]
[4 5 6]
sage: A.parent()
Full MatrixSpace of 2 by 3 dense matrices over Rational Field

We next change the top-right entry of $ A$ . Note that matrix indexing is 0 -based in SAGE, so the top right entry is $ (0,2)$ , which should be thought of as ``row number 0 , column number 2''.

sage: A[0,2] = 389
sage: A
[  1   2 389]
[  4   5   6]

Also notice how matrices print. All columns have the same width and entries in a given column are right justified. Next we compute the reduced row echelon form of $ A$ .

sage: A.echelon_form()
[      1       0 -1933/3]
[      0       1  1550/3]

The module linalg.matrix defines the following classes:

class Matrix
The Matrix class is the base class for all matrix classes. To create a Matrix, first create a MatrixSpace, then coerce a list of elements into the MatrixSpace. See the documentation of MatrixSpace for more details.

class Matrix_generic_dense
The Matrix_generic_dense class derives from Matrix, and defines functionality for dense matrices over any base ring. Matrices are represented by a list of elements in the base ring, and element access operations are implemented in this class.

class Matrix_generic_sparse
The Matrix_generic_sparse class derives from Matrix, and defines functionality for dense matrices over any base ring. A generic sparse matrix is represented using a dictionary with keys pairs $ (i,j)$ and values in the base ring.

class Matrix_rational_dense
The Matrix_rational_dense class derives from Matrix, and defines functionality for dense matrices over the field $ \mathbf{Q}$ of rational numbers.

class Matrix_rational_sparse
The Matrix_rational_sparse class derives from Matrix, and defines functionality for sparse matrices over the field $ \mathbf{Q}$ of rational numbers.

The module linalg.matrix defines the following methods:

berlekamp( v)

Find minimal polynomial of a linear recurrence sequence.



Subsections
See About this document... for information on suggesting changes.