1 | initial version |
One way is:
R.<x,y>=SR[]
a,b,c=var('a b c')
p=a*x^2 + a*y^2 + b*y^2 + c*y^2 + (2*a*y + b*y)*x
p
a*x^2 + (2*a + b)*x*y + (a + b + c)*y^2
p.coefficients()
[a, 2*a + b, a + b + c]
2 | No.2 Revision |
One way is:
R.<x,y>=SR[]
a,b,c=var('a b c')
p=a*x^2 + a*y^2 + b*y^2 + c*y^2 + (2*a*y + b*y)*x
p
a*x^2 + (2*a + b)*x*y + (a + b + c)*y^2
p.coefficients()
[a, 2*a + b, a + b + c]
See also https://ask.sagemath.org/question/10195/extracting-coefficients-of-multivariate-polynomials/