如何用sympy求解矩阵方程? [英] How to solve matrix equation with sympy?

查看:410
本文介绍了如何用sympy求解矩阵方程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sympy中,给出了矩阵方程

In sympy, given a matrix equation

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

M * x + N * y = 0 (or more complicated..)

如何解决x的问题? (M,N =矩阵,x,y =向量)

how to solve this for x? (M,N = matrices, x,y = vectors)

我尝试使用普通符号进行此操作,但显然失败了.使用MatrixSymbol效果不佳.有什么方法可以做到吗,或者sympy无法做到?

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?

推荐答案

正如MRocklin指出的那样,MatrixExpressions还不支持此功能,但是非可交换符号支持:

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  ⎦

与MatrixExpressions不同,非可交换符号没有形状的概念,因此您需要自己对其进行跟踪.但这也表明为MatrixExpression实现此功能的基本条件已经存在.这可能很容易实现.

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.

这篇关于如何用sympy求解矩阵方程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆