[英]sympy Matrices not aligned
I'm trying to use sympy to help me isolate a vector in a matrix expression. 我正在尝试使用sympy帮助我隔离矩阵表达式中的向量。 I have written this code:
我写了这段代码:
import sympy
from sympy import symbols, MatrixSymbol, Matrix
from sympy import Identity
Xp = MatrixSymbol('Xp', 3,1)
t = MatrixSymbol('t', 3,1)
n = MatrixSymbol('n', 3,1)
H = n.T*Xp*Identity(3) - t*n.T
my intention is to isolate n. 我的意图是隔离n。 I'm not sure if sympy can do that, but I already get a 'ShapeError: Matrices n'*Xp and I are not aligned', I think this error should not happen as n'*Xp is a scalar so it should be able to multiply with a matrix.
我不确定sympy是否可以这样做,但是我已经得到了'ShapeError:Matrices n'* Xp and I notaligned',我认为应该不会发生此错误,因为n'* Xp是标量,因此应该能够与矩阵相乘。
How can I get the expression nT*Xp*Identity(3)
to be valid? 如何使表达式
nT*Xp*Identity(3)
有效? and, can sympy help me to isolate the vector n in this equation? 并且,sympy可以帮助我隔离该方程式中的向量n吗?
n.T*Xp*Identity(3)
has the dimension signature 具有尺寸签名
(1,3)*(3,1)*(3,3)
which obviously will not work. 这显然是行不通的。
n*Xp.T*Identity(3)
could work. 可以工作。
If you want to solve 如果你想解决
H=(n.T*X)*I-t*n.T
for n
then the first remark is that this is not always possible. 对于
n
那么第一句话是这并不总是可能的。 Assuming that a solution exists, remark that 假设存在解决方案,请注意
1/(t.T*t)*t.T*H=1/(t.T*t)*(n.T*X)*t.T-n.T
so that 以便
n = a*t - b*H.T*t
where a
is unknown and b=1/(tT*t)
. 其中
a
是未知的并且b=1/(tT*t)
。 Inserting into the original equation gives 插入原始方程式可得出
H = (a*t.T*X-b*t.T*H*X)*I - a*t*t.T + b*t*t.T*H
or 要么
H - b*t*t.T*H +b*(t.T*H*X)*I = a*((t.T*X)*I - t*t.T)
which in each non-trivial component of the right side matrix will give a value of a
, but a solution only exists if all those values are the same. 这在右侧矩阵的每个非平凡部件将给予的值
a
,但是,如果所有这些值相同的溶液中仅存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.