On Sun, 2008-02-10 at 11:57 +0100, Ondrej Certik wrote:
> > > An example for coeff:
> > > f := (a+1)*x + (a+2)*x^2 + a;
> > > -> f := (a+1)x + (a+2)x^2 + a
> > > coeff(f,x,2);
> > > -> a+2
> > > coeff(f,x,0)
> > > -> a
> 
> .coeff() was just pushed into our main hg repo, so update your sympy and do:
> 
> In [1]: a = Symbol("a")
> 
> In [2]: f = (a+1)*x + (a+2)*x**2 + a
> 
> In [3]: f = Polynomial(f)
> 
> In [4]: f.coeff(x, 2)
> Out[4]: 2 + a
> 
> In [5]: f.coeff(x, 0)
> Out[5]: a
> 
> 
> As always, documentation can be found using for example:
> 
> In [6]: f.coeff?
> Type:         instancemethod
> Base Class:   <type 'instancemethod'>
> String Form:
> <bound method Polynomial.coeff of Polynomial(           2            2
> a + x + 2*x  + a*x + a*x , ((1, 1, 2), (1, 1, 1), (2, 0, 2), (1, 1,
> 0), (1, 0, 1)), [a, x], 'grevlex')>
> Namespace:    Interactive
> File:         /home/ondra/sympy/sympy/polynomials/base.py
> Definition:   f.coeff(self, x, n)
> Docstring:
>     Returns the coefficient at x**n
> 
>     Example:
>     >>> a, x = symbols("ax")
>     >>> f = (a+1)*x + (a+2)*x**2 + a
>     >>> Polynomial(f).coeff(x, 2)
>     2 + a
>     >>> Polynomial(f).coeff(a, 1)
>     1 + x + x**2
> 
> 
> The messy output of repr(f) is due to:
> 
> http://code.google.com/p/sympy/issues/detail?id=659
> 
> Ondrej
> 
> Thank you for your quick responses.

I do feel embarrassed that I asked about collect but it was already
there! Sorry for the unnecessary noise. 

I will update sympy now to get .coeff and thank you so much for all your
help!

Zoho

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to