sage: A = MatrixSpace(IntegerRing(),2)( [[1,2], [3,4]] ) sage: f = A.charpoly() sage: f x^2 - 5*x - 2 sage: f.parent() Univariate Polynomial Ring in x over Integer Ring
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.charpoly() sage: f x^2 + (-2*a - 1)*x + a^2 sage: f.parent() Univariate Polynomial Ring in x over 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.<u,v> = PolynomialRing(ZZ,2) sage: A = MatrixSpace(R,2)([u,v,u^2,v^2]) sage: f = A.charpoly(); f x^2 + (-v^2 - u)*x - u^2*v + u*v^2
It's a little difficult to distinguish the variables. To fix this, we might want to rename the indeterminate "Z", which we can easily do as follows:
sage: f = A.charpoly('Z'); f Z^2 + (-v^2 - u)*Z - u^2*v + u*v^2
See About this document... for information on suggesting changes.