Ask Your Question
2

Extract coefficients of polynomials

asked 2016-04-14 05:59:50 +0100

sophia gravatar image

updated 2016-04-14 14:54:30 +0100

kcrisman gravatar image

I have the following code:

var('a')
_.<k> = PolynomialRing(ZZ)
f = k^3+2*k^2+1
g = k^3 + a*k^2 + 1
f.coefficients()
g.coefficients()

the coefficients of f that i get are perfect:

[1, 2, 1]

the coefficients of g should be [1,a,1], but instead i get:

 [[k^3 + 1, 0], [k^2, 1]]

I've tried the solution suggested here:

but it doesn't always produce the coefficients in a logical order.

As always, any help figuring out how to get the correct coefficients of g would be greatly appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-04-14 08:41:55 +0100

nbruin gravatar image

One solution is to force g into the univariate polynomial ring with respect to which you want to take coefficients:

sage: ZZ['a']['k'](g).coefficients()
[1, a, 1]

By mixing var('a') and _.<k> you're creating an element that has a rather complicated representation. You're better off either sticking entirely with var('a,k') or with defining the appropriate polynomial ring explicitly.

edit flag offensive delete link more

Comments

that works, thank you!

sophia gravatar imagesophia ( 2016-04-14 17:15:34 +0100 )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: 2016-04-14 05:59:50 +0100

Seen: 2,048 times

Last updated: Apr 14 '16