Hi, On 13 February 2013 02:18, Aaron Meurer <asmeu...@gmail.com> wrote: > It's not exactly the best name, but the method you are looking for is > nth(). The arguments are powers of the generators. > > In [21]: Poly(3*x**3+2*x+12, gens=[x]).nth(3) > Out[21]: 3 > > In [22]: Poly(2*3*4*x*y*exp(8) + 23*x, gens=[x,y]).nth(0, 1) > Out[22]: 0 > > In [23]: Poly(2*3*4*x*y*exp(8) + 23*x, gens=[x,y]).nth(1, 0) > Out[23]: 23 >
Apparently this the best Poly can do at the moment. I just submitted https://github.com/sympy/sympy/pull/1777 which fixes this issue. > Aaron Meurer > > On Tue, Feb 12, 2013 at 4:55 PM, someone <someb...@bluewin.ch> wrote: >> Hi *, >> >> >> I have a small question about (multivariate) polynomials. Suppose I have a >> polynomial object P and I only know the complete set of all generators >> (f.e. [x,y,z, ...]) as well as all monomials present (x*y, x**2*y*z**3, etc) >> in this instance. >> >> How can I retrieve the coefficients of a single, specific monomial? >> >> The poly object has a "coeff()" method which behaves very wrong: >> >> In [11]: P = Poly(3*x**3+2*x+12, gens=[x]) >> In [12]: P.coeff(x**3) >> Out[12]: 0 >> >> I would like to get "3" here. The reason for this is that "coeff" >> is a method of Expr (I think): >> >> In [13]: P.as_expr().coeff(x**3) >> Out[13]: 3 >> >> This is not optimal in the sense that I have to convert my Poly >> back to Exprs just for doing very basic polynomial math. And it >> fails badly in the multivariate case: >> >> In [20]: P = Poly(2*3*4*x*y*exp(8) + 23*x, gens=[x,y]) >> >> In [21]: P.as_expr().coeff(y) >> Out[21]: 24*x*exp(8) >> >> In [22]: P.as_expr().coeff(x) >> Out[22]: 24*y*exp(8) + 23 >> >> I really want just "0" in the first and "23" in the second call! >> >> My current "solution" around this is to do it that way and >> afterwards set all variables corresponding to generators to zero. >> >> But I'm sure there is a much better way! Any hints please? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to sympy+unsubscr...@googlegroups.com. >> To post to this group, send email to sympy@googlegroups.com. >> Visit this group at http://groups.google.com/group/sympy?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > Visit this group at http://groups.google.com/group/sympy?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > Mateusz -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.