Ask Your Question

get the coefficients of polynomial of several variables?

asked 2018-03-13 21:12:52 -0500

DanialBagh gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-13 21:51:34 -0500

kcrisman gravatar image

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.

edit flag offensive delete link 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?

DanialBagh gravatar imageDanialBagh ( 2018-03-13 23:24:37 -0500 )edit

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.

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-03-13 21:12:52 -0500

Seen: 9 times

Last updated: Mar 13