On Sat, Feb 23, 2013 at 7:31 AM, David Mashburn <[email protected]> wrote: > Chris, > > Thanks! I took your suggestion of using "as_independent" and made a function > that now behaves the way I described in the first post: > > import sympy > from sympy import S,N,sqrt,Poly > x,y = S('x'),S('y') > > def GetCoefficientsOfFreeVariables(eq): > if eq.__class__==sympy.Mul: > coeffs,vars = zip(eq.as_independent(*eq.free_symbols,as_Add=False)) > elif eq.__class__==sympy.Add: > coeffs,vars = zip(*(i.as_independent(*i.free_symbols,as_Add=False) > for i in eq.args)) > return coeffs,vars
Looks ok to me...you might write it as: ``` return zip(*(i.as_independent(*i.free_symbols, as_Add=False) for i in Mul.make_args(eq))) ``` Be aware that you can get some complex "numbers", too: >>> eq=Integral(sqrt(2)*x,(x,1,3)) >>> list(zip(*(i.as_independent(*i.free_symbols, as_Add=False) for i in Mul.make _args(eq)))) [(Integral(sqrt(2)*x, (x, 1, 3)),), (1,)] /chris -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
