# Revision history [back]

You should work with polynomials, not symbolic expressions.

Here is an example, let us assume that your matrix is defined over the field QQ:

sage: A = random_matrix(QQ,3)
sage: A
[   2    0   -2]
[   2    2    0]
[-1/2    0    0]


Then you can define the polynomial ring with one variable over the rationals, and define your polynomial:

sage: R.<x> = PolynomialRing(QQ)
sage: R
Univariate Polynomial Ring in x over Rational Field
sage: f = 2*x^2 + x + 3
sage: f.parent()
Univariate Polynomial Ring in x over Rational Field


And apply it to your matrix:

sage: f(A)
[  15    0  -10]
[  18   13   -8]
[-5/2    0    5]