Ask Your Question
0

get the coefficients of polynomial of several variables?

asked 2018-03-14 03:12:52 +0200

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
1

answered 2018-03-14 03:51:34 +0200

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

Comments

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-14 05:24:37 +0200 )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.

kcrisman gravatar imagekcrisman ( 2018-03-19 18:20:51 +0200 )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

Stats

Asked: 2018-03-14 03:12:52 +0200

Seen: 660 times

Last updated: Mar 14 '18