# way to subs var by matrix in polynomial

HI

What is the best way to substitute to the variables of a polynomial x, y with 2 matrices X, Y

R.<x,y> = QQ[]
p = x^2 + 5*y + 2*x*y + 3*x + y^2
show("p : ",p," \t degre : \t",p.degree(x))
for ex in range(1,p.degree(x)+1) :
coefx=p.coefficient(x^ex)
print(" ex : ",ex," \t coefx : ",coefx)
for ey in range(1,p.degree(x)+1) :
coefy=p.coefficient(y^ey)
print(" ey : ",ey," \t coefy : ",coefy)
#for ey in range(1,p.degree(y)+1) :
#    coefy=p.coefficient(y^ex)
#    for ex in range(0,coefy.degree(y)+1) :
#        coefx=p.coefficient(x^ex)
#        print(" ex : ",ex," \t coefx : ",coefx," \t ey : ",ey," \t coefy : ",coefy)

var('x_00,x_01,x_10,x_11',domain='integer')
var('y_00,y_01,y_10,y_11',domain='integer')
X=matrix(SR,[[x_00,x_01],[x_10,x_11]]); Y=matrix(SR,[[y_00,y_01],[y_10,y_11]])
show(X,Y)
#p.subs([x==X,y==Y])

edit retag close merge delete

Sort by ยป oldest newest most voted

You can use one of the following:

sage: p.subs({x:X,y:Y})

sage: p.subs(x=X,y=Y)


The first passes a dictionary to the subs method, the second sets two arguments.

When you write p.subs([x==X,y==Y]), you try to pass a list of booleans to the subs method.

more

Thank you @tmonteil

( 2021-06-22 09:49:06 +0200 )edit