# Revision history [back]

### Extract coefficients of polynomials

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:

  http://ask.sagemath.org/question/10195/extracting-coefficients-of-multivariate-polynomials/


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.

 2 No.2 Revision kcrisman 11867 ●36 ●121 ●237

### Extract coefficients of polynomials

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:here:

  http://ask.sagemath.org/question/10195/extracting-coefficients-of-multivariate-polynomials/


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.