Ask Your Question

Revision history [back]

Just evaluate the polynomial on the matrix.

You will need to create the polynomial in an appropriate polynomial ring.

Here is an example.

sage: m = matrix(((0, 1), (1, 1)))
sage: R.<x> = PolynomialRing(QQ, 'x')
sage: p = x^2 - x - 1
sage: p(m)
[0 0]
[0 0]

Just evaluate the polynomial on the matrix.

You will need to create the polynomial in an appropriate polynomial ring.

Here is an example.

sage: m = matrix(((0, 1), (1, 1)))
sage: R.<x> = PolynomialRing(QQ, 'x')
sage: p = x^2 - x - 1
sage: p(m)
[0 0]
[0 0]

Starting with a polynomial symbolic expression, first turn it into an element of a polynomial ring.

Here is an example.

sage: x = SR.var('x')
sage: q = x^2 - x - 1
sage: m = matrix(((0, 1), (1, 1)))
sage: q(m)
... DeprecationWarning: ...
TypeError ... Traceback (most recent call last)
...
TypeError: no canonical coercion from Full MatrixSpace of 2 by 2 dense matrices over Integer Ring to Symbolic Ring
sage: R.<x> = PolynomialRing(QQ, 'x')
sage: p = R(q)
sage: p(m)
[0 0]
[0 0]

You can check where your polynomial belongs as follows.

sage: q.parent()
Symbolic Ring
sage: p.parent()
Univariate Polynomial Ring in x over Rational Field