问题
In sympy, given a matrix equation
M * x + N * y = 0 (or more complicated..)
how to solve this for x? (M,N = matrices, x,y = vectors)
I tried this with normal symbols, but obviously this failed. Using MatrixSymbol was not working as well. Is there some way to do it, or is sympy not capable of doing it?
回答1:
As MRocklin noted, MatrixExpressions don't support this yet, but noncommutative symbols do:
In [13]: M, N, x, y = symbols('M N x y', commutative=False)
In [15]: solve(M*x + N*y, x)
Out[15]:
⎡ -1⎤
⎣-N⋅y⋅M ⎦
Unlike MatrixExpressions, noncommutative symbols don't have a notion of shape, so you'll need to keep track of that yourself. But this also shows that the basic things to implement this for MatrixExpression are already there. It will probably be easy to implement.
来源:https://stackoverflow.com/questions/22820000/how-to-solve-matrix-equation-with-sympy