On Thursday, October 10, 2013 7:49:14 PM UTC-5, Aaron Meurer wrote:
>
> Is there a function in SymPy that makes it easy to convert from a 
> system of linear equations in symbolic form to a Matrix? I'm asking 
> because solve_linear_system takes a Matrix as input. 
>
>
You can just pass the system to solve and let it call solve_linear_system, 
can't you?  Otherwise

>>> s
(x + 2*y == 4, y/2 == -2*c)
>>> sym = (x, y)
>>> m = []
>>> rhs = []
>>> for si in s:
...   if isinstance(si, Equality): si = si.lhs - si.rhs
...   i, d = si.as_independent(*sym)
...   m.append(d)
...   rhs.append(-i)
...
>>> Matrix(m).jacobian(sym)
Matrix([
[1,   2],
[0, 1/2]])
>>> Matrix(rhs)
Matrix([
[ 4],
[-2*c]])

(This doesn't check that the system is linear, but you could just check 
that it is symbol-free:

>>> Matrix(m).jacobian(sym).atoms(Symbol)
set([])

[There is no free_symbols attribute for it: AttributeError: 
MutableDenseMatrix has no attribute free_symbols.]

-- 
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