ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 20 Jun 2016 10:31:17 +0200coefficient function in sagehttps://ask.sagemath.org/question/33811/coefficient-function-in-sage/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 ? Thu, 16 Jun 2016 04:00:50 +0200https://ask.sagemath.org/question/33811/coefficient-function-in-sage/Comment by tmonteil for <p>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 ? </p>
https://ask.sagemath.org/question/33811/coefficient-function-in-sage/?comment=33812#post-id-33812Could you please provide an example on how you construct `f`?Thu, 16 Jun 2016 11:25:33 +0200https://ask.sagemath.org/question/33811/coefficient-function-in-sage/?comment=33812#post-id-33812Comment by calc314 for <p>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 ? </p>
https://ask.sagemath.org/question/33811/coefficient-function-in-sage/?comment=33815#post-id-33815What does `f.coefficients()` give you?Thu, 16 Jun 2016 15:20:55 +0200https://ask.sagemath.org/question/33811/coefficient-function-in-sage/?comment=33815#post-id-33815Answer by slelievre for <p>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 ? </p>
https://ask.sagemath.org/question/33811/coefficient-function-in-sage/?answer=33856#post-id-33856First 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)
Mon, 20 Jun 2016 10:31:17 +0200https://ask.sagemath.org/question/33811/coefficient-function-in-sage/?answer=33856#post-id-33856