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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to