# coefficient function in sage

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I want to compute the coefficient of certain polynomial but he coefficient function in sage gives me back for the coefficient of X^0 that is for any polynomial f f.coefficient(x^0) = 0 Can you some suggest how to change this thing in sage library ?

edit retag close merge delete

Could you please provide an example on how you construct f?

( 2016-06-16 04:25:33 -0600 )edit

What does f.coefficients() give you?

( 2016-06-16 08:20:55 -0600 )edit

Sort by ยป oldest newest most voted

First of all, when you want to use polynomials in Sage, it is always wiser to use elements in some polynomial ring rather than elements of Sage's symbolic ring.

Then, if f is such a polynomial, you can ask for the coefficient of x^k simply by asking f[k]. This works for any k, even if k is larger than the degree of f.

Here is an example.

sage: R.<x> = PolynomialRing(QQ)
sage: f = x^2 - 3
sage: f[0], f[1], f[2], f[3], f[20]
(-3, 0, 1, 0, 0)

more