Ask Your Question

coefficient function in sage

asked 2016-06-15 21:00:50 -0500

this post is marked as community wiki

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 flag offensive close merge delete


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

tmonteil gravatar imagetmonteil ( 2016-06-16 04:25:33 -0500 )edit

What does f.coefficients() give you?

calc314 gravatar imagecalc314 ( 2016-06-16 08:20:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-06-20 03:31:17 -0500

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)
edit flag offensive delete link more

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


Asked: 2016-06-15 21:00:50 -0500

Seen: 264 times

Last updated: Jun 20 '16