How to solve matrix equation with sympy?

风格不统一 提交于 2019-12-09 18:08:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!