7.1.2.4 Matrix_domain Objects

class Matrix_domain
Matrix_domain( parent)

Instances of class Matrix_domain have the following methods (in addition to inherited methods and special methods):

characteristic_polynomial,$  $ charpoly,$  $ det,$  $ determinant,$  $ is_invertible,$  $ matrix_over_field

Further documentation:

characteristic_polynomial( )

Return the characteristic polynomial of self, as a polynomial over the fraction field of the base ring.

First a matrix over $ \mathbf{Z}$ :

sage: A = MatrixSpace(IntegerRing(),2)( [[1,2], [3,4]] )
sage: f = A.characteristic_polynomial()
sage: f
x^2 - 5*x - 2
sage: f.parent()
Univariate Polynomial Ring in x over Rational Field

We compute the characteristic polynomial of a matrix over the polynomial ring $ \mathbf{Z}[a]$ :

sage: R = PolynomialRing(IntegerRing(),'a'); a = R.gen()
sage: M = MatrixSpace(R,2)([[a,1], [a,a+1]])
sage: M
[    a     1]
[    a a + 1]
sage: f = M.characteristic_polynomial()
sage: f
x^2 + (-2*a - 1)*x + a^2
sage: f.parent()
Univariate Polynomial Ring in x over Fraction field of Univariate
Polynomial Ring in a over Integer Ring
sage: M.trace()
2*a + 1
sage: M.determinant()
a^2

We compute the characteristic polynomial of a matrix over the multi-variate polynomial ring $ \mathbf{Z}[x,y]$ :

sage: R = MPolynomialRing(IntegerRing(),2); x,y = R.gens()
sage: A = MatrixSpace(R,2)([x,y,x**2,y**2])
sage: f = A.charpoly()
sage: f
x^2 + (-1*x_1^2 - x_0)*x + x_0*x_1^2 - x_0^2*x_1

It's a little difficult to distinguish the variables. To fix this, we rename the indeterminate $ Z$ :

sage: f.parent().assign_names("Z")
sage: f
Z^2 + (-1*x_1^2 - x_0)*Z + x_0*x_1^2 - x_0^2*x_1

charpoly( )

Return the characteristic polynomial of self, as a polynomial over the fraction field of the base ring.

First a matrix over $ \mathbf{Z}$ :

sage: A = MatrixSpace(IntegerRing(),2)( [[1,2], [3,4]] )
sage: f = A.characteristic_polynomial()
sage: f
x^2 - 5*x - 2
sage: f.parent()
Univariate Polynomial Ring in x over Rational Field

We compute the characteristic polynomial of a matrix over the polynomial ring $ \mathbf{Z}[a]$ :

sage: R = PolynomialRing(IntegerRing(),'a'); a = R.gen()
sage: M = MatrixSpace(R,2)([[a,1], [a,a+1]])
sage: M
[    a     1]
[    a a + 1]
sage: f = M.characteristic_polynomial()
sage: f
x^2 + (-2*a - 1)*x + a^2
sage: f.parent()
Univariate Polynomial Ring in x over Fraction field of Univariate
Polynomial Ring in a over Integer Ring
sage: M.trace()
2*a + 1
sage: M.determinant()
a^2

We compute the characteristic polynomial of a matrix over the multi-variate polynomial ring $ \mathbf{Z}[x,y]$ :

sage: R = MPolynomialRing(IntegerRing(),2); x,y = R.gens()
sage: A = MatrixSpace(R,2)([x,y,x**2,y**2])
sage: f = A.charpoly()
sage: f
x^2 + (-1*x_1^2 - x_0)*x + x_0*x_1^2 - x_0^2*x_1

It's a little difficult to distinguish the variables. To fix this, we rename the indeterminate $ Z$ :

sage: f.parent().assign_names("Z")
sage: f
Z^2 + (-1*x_1^2 - x_0)*Z + x_0*x_1^2 - x_0^2*x_1

det( )

Return the determinant of this matrix, which must be square.

We create a matrix over $ \mathbf{Z}[x,y]$ and compute its determinant.

sage: R = MPolynomialRing(IntegerRing(),2); x,y = R.gens()
sage: A = MatrixSpace(R,2)([x,y,x**2,y**2])
sage: A.determinant()
x_0*x_1^2 - x_0^2*x_1

determinant( )

Return the determinant of this matrix, which must be square.

We create a matrix over $ \mathbf{Z}[x,y]$ and compute its determinant.

sage: R = MPolynomialRing(IntegerRing(),2); x,y = R.gens()
sage: A = MatrixSpace(R,2)([x,y,x**2,y**2])
sage: A.determinant()
x_0*x_1^2 - x_0^2*x_1

is_invertible( )

Return True if this matrix is invertible.

The following matrix is invertible over $ \mathbf{Q}$ but not over $ \mathbf{Z}$ .

sage: A = MatrixSpace(IntegerRing(), 2)(range(4))
sage: A.is_invertible()
False
sage: A.matrix_over_field().is_invertible()
True

The inverse function is a constructor for matrices over the fraction field, so it can work even if A is not invertible.

sage: ~A   # inverse of A
[-3/2  1/2]
[   1    0]

The next matrix is invertible over $ \mathbf{Z}$ .

sage: A = MatrixSpace(IntegerRing(),2)([1,10,0,-1])
sage: A.is_invertible()
True
sage: ~A                # compute the inverse
[ 1 10]
[ 0 -1]

The following nontrivial matrix is invertible over $ \mathbf{Z}[x]$ .

sage: R = PolynomialRing(IntegerRing())
sage: x = R.gen()
sage: A = MatrixSpace(R,2)([1,x,0,-1])
sage: A.is_invertible()
True
sage: ~A
[ 1  x]
[ 0 -1]

matrix_over_field( )

Return this matrix, but with entries viewed as elements of the fraction field of the base ring.

sage: A = MatrixSpace(IntegerRing(),2)([1,2,3,4])
sage: B = A.matrix_over_field()
sage: B
[1 2]
[3 4]
sage: B.parent()
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

Instances of class Matrix_domain also have the following special methods:

__invert__

Further documentation:

__invert__( )

Return this inverse of this matrix, as a matrix over the fraction field.

Raises a ZeroDivisionError if the matrix has zero determinant, and raises an ArithmeticError, if the inverse doesn't exist because the matrix is nonsquare.

sage: A = MatrixSpace(IntegerRing(), 2)([1,1,3,5])
sage: ~A
[ 5/2 -1/2]
[-3/2  1/2]

Even if the inverse lies in the base field, the result is still a matrix over the fraction field.

sage: I = MatrixSpace(IntegerRing(),2)( 1 )  # identity matrix
sage: ~I
[1 0]
[0 1]
sage: (~I).parent()
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

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