# get the coefficients of polynomial of several variables?

Consider that I have a polynomial with n variables x1,x2,...,xn and want to get the coefficient of that polynomial. For example I can have: x1+2x1x5^2+3x1^2x4-5x2x5^2+1/2x2x3+x6^2x7x8+9x3x9^3

I would like to ask Sage to give coefficient for the polynomial with variables x1..x9 and the result should be something like this: coefficient,(exponent of x1..x9); 1,(1,0,0,0,0,0,0,0,0); 2,(1,0,0,0,2,0,0,0,0); 3,(2,0,0,1,0,0,0,0,0); -5,(0,1,0,0,2,0,0,0,0); 1/2,(0,1,1,0,0,0,0,0,0); 1,(0,0,0,0,0,2,1,1); 9,(0,0,1,0,0,0,0,0,3)

How can I achieve this?

edit retag close merge delete

Sort by ยป oldest newest most voted

Do you mean something like this?

sage: S = PolynomialRing(QQ, ['a','b','c'])
sage: p = S("a+a^2*b+c^3")
sage: p.dict()
{(0, 0, 3): 1, (1, 0, 0): 1, (2, 1, 0): 1}


See the multivariate polynomial generic documentation for a lot more on these objects.

more

Thanks for the answer, but what if I want to treat 'b' as coefficient and just get the coefficients of the polynomial with respect to 'a' and 'c'? Can i do that?

( 2018-03-13 23:24:37 -0500 )edit
1

Probably; you'd have to coerce this into a polynomial ring over QQ[b] but I'm not quite sure how to do that - it may be as easy as defining T = the right ring and then doing it.

( 2018-03-19 12:20:51 -0500 )edit