Or using the .coeff() method. We had a bit in our tutorial about this sort of thing. See http://mattpap.github.com/scipy-2011-tutorial/html/mathematics.html#partial-fraction-decomposition.
Aaron Meurer On Sat, Jul 16, 2011 at 9:10 AM, Mateusz Paprocki <[email protected]> wrote: > Hi, > > On 16 July 2011 06:05, Chris Smith <[email protected]> wrote: >> >> >> On Sat, Jul 16, 2011 at 8:58 AM, Matthew Rocklin <[email protected]> >> wrote: >>> >>> How can I separate an expression like >>> a*(x+y) + x >>> into terms involving only x and only y >>> (a+1)*x , a*y >>> This seems like the kind of function SymPy probably has. I'm having >>> trouble finding it. >> >> >>> eq >> a*(x + y) + x >> >>> collect(eq.expand(), x, y) >> a*y + x*(a + 1) > > collect() requires x, y to be passed as [x, y] or (x, y), and otherwise you > set evaluate keyword to y. To get the coefficients, use evaluate=False. This > problem can be also solved with polys: > In [1]: var('a') > Out[1]: a > In [2]: f = a*(x + y) + x > In [3]: factor(f, x, y) > Out[3]: a⋅y + x⋅(a + 1) > In [4]: Poly(f, x, y).nth(1, 0) > Out[4]: a + 1 > In [5]: Poly(f, x, y).nth(0, 1) > Out[5]: a >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To post to this group, send email to [email protected]. >> 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. > > Mateusz > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > 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. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected]. 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.
