parent) |
characteristic_polynomial,
charpoly,
det,
determinant,
is_invertible,
matrix_over_field
Further documentation:
) |
Return the characteristic polynomial of self, as a polynomial over the fraction field of the base ring.
First a matrix over
:
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
:
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
:
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
:
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
) |
Return the characteristic polynomial of self, as a polynomial over the fraction field of the base ring.
First a matrix over
:
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
:
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
:
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
:
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
) |
Return the determinant of this matrix, which must be square.
We create a matrix over
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
) |
Return the determinant of this matrix, which must be square.
We create a matrix over
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
) |
Return True if this matrix is invertible.
The following matrix is invertible over
but not over
.
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
.
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
.
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]
) |
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:
) |
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.