简体   繁体   English

如何用sympy求解矩阵方程?

[英]How to solve matrix equation with sympy?

In sympy, given a matrix equation 同情,给出一个矩阵方程

M * x + N * y = 0 (or more complicated..) M * x + N * y = 0(或更复杂..)

how to solve this for x? 如何为x解决这个问题? (M,N = matrices, x,y = vectors) (M,N =矩阵,x,y =向量)

I tried this with normal symbols, but obviously this failed. 我用普通符号尝试了这个,但显然失败了。 Using MatrixSymbol was not working as well. 使用MatrixSymbol也不行。 Is there some way to do it, or is sympy not capable of doing it? 有没有办法做到这一点,或者是否有能力做到这一点?

As MRocklin noted, MatrixExpressions don't support this yet, but noncommutative symbols do: 正如MRocklin所指出的,MatrixExpressions尚不支持,但非交换符号可以:

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. 与MatrixExpressions不同,非交换符号没有形状概念,因此您需要自己跟踪它。 But this also shows that the basic things to implement this for MatrixExpression are already there. 但这也表明为MatrixExpression实现这一点的基本内容已经存在。 It will probably be easy to implement. 它可能很容易实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM