Thanks a lot for your answer, Leonid!
I think I'm starting to see the problem ...
When I'm solving the system of equations, I get many solutions, most
of them containing a0, a1, a2 and a3.
However, I'm just interested in exactly one of those solutions where
all occurrences of a0, a1, a2 and a3 cancel out and the resulting
matrix only consists of concrete numbers.
Is there a (simple) way to tell this to SymPy?
In the meantime, I've found a different way to get the desired result.
Let me first repeat the original setup:
>>> import sympy as sp
>>> a0, a1, a2, a3 = sp.symbols('a:4')
>>> a = sp.Matrix([a3, a2, a1, a0])
>>> b = sp.Matrix([a0, a3 + a2 + a1 + a0, a1, 3 * a3 + 2 * a2 + a1])
>>> M = sp.MatrixSymbol('M', 4, 4)
>>> sp.Eq(a, M * b)
Eq(Matrix([[a3], [a2], [a1], [a0]]), M*Matrix([
[ a0],
[a0 + a1 + a2 + a3],
[ a1],
[ a1 + 2*a2 + 3*a3]]))
I stumbled upon
https://groups.google.com/forum/#!searchin/sympy/linear_eq_to_matrix/sympy/Wqs1OhTBexg/eGoKjrWHBwAJ,
which mentions sympy.solvers.solveset.linear_eq_to_matrix().
http://docs.sympy.org/latest/modules/solvers/solveset.html#linear-eq-to-matrix
With this I can get my expected solution:
>>> from sympy.solvers.solveset import linear_eq_to_matrix
>>> linear_eq_to_matrix(list(b), list(a))
(Matrix([
[0, 0, 0, 1],
[1, 1, 1, 1],
[0, 0, 1, 0],
[3, 2, 1, 0]]), Matrix([
[0],
[0],
[0],
[0]]))
>>> _[0].inv()
Matrix([
[ 2, -2, 1, 1],
[-3, 3, -2, -1],
[ 0, 0, 1, 0],
[ 1, 0, 0, 0]])
This still involves the extra step of inverting the result.
Is this already the best way to get this result with SymPy?
cheers,
Matthias