Oh, of course. B is on the rhs. This is probably more natural to me too. Should we make a convenience function that does this? I think this use of jacobian would be lost on most people.
Aaron Meurer On Sat, Jun 14, 2014 at 6:29 PM, James Crist <[email protected]> wrote: > It's just the convention I'm most used to. Systems that can be expressed as > A*x = B I usually solve for x, or if A isn't square, the least squares > solution x. In both cases you need A and B in this form. I suppose Ax + B > could seem more natural though. > > On Friday, June 13, 2014 6:45:48 PM UTC-5, Aaron Meurer wrote: >> >> That's a clever trick. I should have thought of that. >> >> Is there any reason you let system = A*x - B instead of A*x + B? The >> latter seems more natural. >> >> Aaron Meurer >> >> On Sat, Jun 7, 2014 at 12:28 AM, James Crist <[email protected]> wrote: >> > I just answered this on gitter earlier today, but you can just take the >> > jacobian of the system to get its matrix form. For example: >> > >> > In [1]: from sympy import * >> > >> > In [2]: a, b, c, d = symbols('a, b, c, d') >> > >> > In [3]: x1, x2, x3, x4 = symbols('x1:5') >> > >> > In [4]: x = Matrix([x1, x2, x3, x4]) >> > >> > In [5]: system = Matrix([a*x1 + b*x2 + c, >> > ...: c*x1 + d*x3 + 2, >> > ...: c*x3 + b*x4 + a]) >> > >> > In [6]: A = system.jacobian(x) >> > >> > In [7]: B = A*x - system >> > >> > In [8]: A >> > Out[8]: >> > Matrix([ >> > [a, b, 0, 0], >> > [c, 0, d, 0], >> > [0, 0, c, b]]) >> > >> > In [9]: B >> > Out[9]: >> > Matrix([ >> > [-c], >> > [-2], >> > [-a]]) >> > >> > In [10]: assert A*x - B == system >> > >> > The functionality I'm adding for my GSoC for linearizing a system of >> > equations will also be able to return these matrices in a convenient >> > form. >> > But it's not terribly difficult to solve for these arrangements using >> > the >> > current functionality. >> > >> > >> > >> > >> > >> > >> > >> > On Thursday, June 5, 2014 4:22:52 PM UTC-5, Andrei Berceanu wrote: >> >> >> >> 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/8fb2dae4-9f46-4c1b-b96f-83033278c27d%40googlegroups.com. >> > >> > For more options, visit https://groups.google.com/d/optout. > > -- > 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/a9c5f7ba-1c2d-4673-a8d4-b1253c150054%40googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. -- 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/CAKgW%3D6LeSTp276i8U3CLpapxown9ZX5N3fvK8EinhNsKpd7bUw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
