First time here? Check out the FAQ!

Ask Your Question
2

How to get Polynomial Coefficients

asked 7 years ago

ortollj gravatar image

Hi

I would like to get the value of coeffs of x^5 + px^3 + qx^2 + rx + s something like [1,0, b - 2/5a^2,...] I do not understand what means the coefficients() outputs in the code below ??

forget()
import math
for v in var( 'a,b,c,d,e' ):    assume( v, 'rational' )
for v in var( 'p,q,r,s' ):    assume( v, 'rational' )
x = PolynomialRing(RationalField(), 'x').gen()
t = PolynomialRing(RationalField(), 't').gen()
Pt= t^5 + a*t^4 + b*t^3 + c*t^2 + d*t + e
vChgt=t==x-a/5
P=Pt.substitute(vChgt)
#Px= x^5          + p*x^3 + q*x^2 + r*x + s
show(P.factor())
show(P.factor().coefficients(sparse=False))
show(P.factor().list())
P.factor()
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
6

answered 7 years ago

dan_fulea gravatar image

The following works:

sage: P.coefficients(x, sparse=0)
[4/3125*a^5 - 1/125*a^3*b + 1/25*a^2*c - 1/5*a*d + e,
 -3/125*a^4 + 3/25*a^2*b - 2/5*a*c + d,
 4/25*a^3 - 3/5*a*b + c,
 -2/5*a^2 + b,
 0,
 1]

The variable x has to be specified, if some other variables are present, and we want the coefficients only with respect to x.

Note that the coefficient on the pythonical place zero corresponds to the zero degree (i.e. free) coefficient of P. So the leading coefficient is on the pythonical fifth place. In order to get "the other list" [1,0, b - 2/5a^2,...], just take the reverse list.

sage: C = P.coefficients(x, sparse=0)
sage: C . reverse()
sage: C[0:3]
[1, 0, -2/5*a^2 + b]
Preview: (hide)
link

Comments

Thank you Dan_fulea

ortollj gravatar imageortollj ( 7 years ago )

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: 7 years ago

Seen: 4,268 times

Last updated: Sep 17 '17