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.


Reply via email to