在sympy中求解这个方程式
我正在使用sympy玩旋转矩阵和类似概念。我正在尝试从以下矩阵中提取alpha,beta,gamma:
⎡ α - γ⋅sin(θ) ⎤
⎢ ⎥
⎢β⋅cos(φ) + γ⋅sin(φ)⋅cos(θ) ⎥
⎢ ⎥
⎣-β⋅sin(φ) + γ⋅cos(φ)⋅cos(θ)⎦
这样我就可以获得此矩阵
⎡1 0 -sin(θ) ⎤
⎢ ⎥
⎢0 cos(φ) sin(φ)⋅cos(θ)⎥
⎢ ⎥
⎣0 -sin(φ) cos(φ)⋅cos(θ)⎦
基本上求解方程f(x)= ax
,但对于矩阵而不是x。其中f(x)是第一个矩阵,第二个矩阵和x是alpha,beta,伽马向量。 我天真地用sympy.solve
进行了测试,但它输出矩阵A和X不对准
。从我通常看到的是因为矩阵的尺寸不正确,但在我的情况下,我认为这是因为使用solve
不是正确的方法。
我该如何解决这个问题?
I'm playing with rotational matrices and similar concepts using sympy. I'm trying to extract alpha, beta, gamma from the following matrix:
⎡ α - γ⋅sin(θ) ⎤
⎢ ⎥
⎢β⋅cos(φ) + γ⋅sin(φ)⋅cos(θ) ⎥
⎢ ⎥
⎣-β⋅sin(φ) + γ⋅cos(φ)⋅cos(θ)⎦
so that I get this matrix
⎡1 0 -sin(θ) ⎤
⎢ ⎥
⎢0 cos(φ) sin(φ)⋅cos(θ)⎥
⎢ ⎥
⎣0 -sin(φ) cos(φ)⋅cos(θ)⎦
Basically solve the equation F(x) = Ax
, but for A matrix instead of x. Where F(x) is the first matrix, A the second matrix and x is the alpha, beta, gamma vector.
I naively tested with sympy.Solve
but it outputs Matrices A and x are not aligned
. From what I've seen usually is because the dimensions of the matrices are not correct but in my case I think it's because using solve
is not the correct way.
How could I solve this with simpy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用sympy的
linear_eq_to_matrix
函数:https://docs.sympy.org/latest/modules/solvers/solveset.html#linelear-eq-to-matrix
You can use SymPy's
linear_eq_to_matrix
function:https://docs.sympy.org/latest/modules/solvers/solveset.html#linear-eq-to-matrix
这是我最接近的。如您所知
f(x)
(在下面称为bres
)和x
,您正在寻找a
矩阵是9个变量(a11
,a12
等)。乘以X乘以您的3个方程式具有自变量。我们知道ax -b = 0
,但是要找到每个系数,您需要添加约束。例如,要查找a11
,您需要求解a11
的第一个方程添加β
和γ
的约束是0(subs
函数)。请参阅我对您的答案的评论,因为这可能不是解决该问题的最佳方法。
结果:
This is the closest I could come up with. As you know
F(x)
(calledbres
below) andx
, you're looking forA
matrix which are 9 variables (a11
,a12
, etc.). Multiplying A by x gives you 3 equations with independent variables. We knowAx - b = 0
, but to find each coefficient you need to add constrains. For example to finda11
, you need to solve the first equation fora11
but as you're looking for theα
coefficient, you need to add the constraint thatβ
andγ
are 0 (subs
function).Please also see my comment to your answer, as this is probably not the best way to solve it.
Result: