Was this implemented into sympy at any point? It could be the equivalent of Mathematica's CoefficientArrays function.
On Thursday, November 14, 2013 5:56:22 AM UTC+1, Chris Smith wrote: > > I forgot that as_independent, without the as_Add=True flag will treat Muls > differently. The following will be more robust: > > def eqs2matrix(eqs, syms, augment=False): > """ > >>> s > [x + 2*y == 4, 2*c + y/2 == 0] > >>> eqs2matrix(s, (x, c)) > (Matrix([ > [1, 0], > [0, 2]]), Matrix([ > [-2*y + 4], > [ -y/2]])) > >>> eqs2matrix([2*c*(x+y)-4],(x, y)) > (Matrix([[2*c, 2*c]]), Matrix([[4]])) > """ > s = Matrix([si.lhs - si.rhs if isinstance(si, Equality) else si for si > in eqs]) > sym = syms > j = s.jacobian(sym) > rhs = -(s - j*Matrix(sym)) > rhs.simplify() > if augment: > j.col_insert(0, rhs) > else: > j = (j, rhs) > return j > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/e07851d4-632f-4976-b6fd-e3bd7f584127%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
