2013-07-24 4 views
1

나는 MutableDenseMatrix가 Q입니다. theta1theta2은 SymPy 유형 symbol이다. 내가 역을 호출 할 때symPy의 inv()가 적절한 값을 반환하지 않습니다.

In[12]: Q 
Out[12]: [cos(theta1), -sin(theta1), 0, 0] 
     [sin(theta1), cos(theta1), 0, 0] 
     [   0,   0, 1, 980] 
     [   0,   0, 0, 1] 

, 내가 얻을 :

In[13]: Q_inv=Q.inv() 
Out[13]: [-sin(theta1)**2/cos(theta1) + 1/cos(theta1), sin(theta1), 0, 0] 
     [        -sin(theta1), cos(theta1), 0, 0] 
     [           0,   0, 1, -980] 
     [           0,   0, 0, 1] 

때 내가 점점해야하는 것은 : 여기에 잘못 갈 수있는 무엇에

Out[X]: [cos(theta1), sin(theta1), 0, 0] 
     [-sin(theta1), cos(theta1), 0, 0] 
     [   0,   0, 1, -980] 
     [   0,   0, 0, 1] 

어떤 생각?

답변

5

실제로 그것에 대해 잘못된 것은 없습니다. 첫 번째 매트릭스 항목에서는 출력에 -sin(theta1)**2/cos(theta1) + 1/cos(theta1), 예상 결과에 cos(theta1)이 있으며 실제로는 표준 삼각법 ID가 1 - sin(theta1)**2 = cos(theta1)**2이므로 동등합니다.

sympy에는 trigsimp이라는 함수가있어 원하는 수식으로 줄일 수 있습니다.

>>> Q 
[cos(theta1), -sin(theta1), 0, 0], 
[sin(theta1), cos(theta1), 0, 0], 
[   0,   0, 1, 980], 
[   0,   0, 0, 1] 
>>> Q.inv() 
[-sin(theta1)**2/cos(theta1) + 1/cos(theta1), sin(theta1), 0, 0], 
[        -sin(theta1), cos(theta1), 0, 0], 
[           0,   0, 1, -980], 
[           0,   0, 0, 1] 
>>> 
>>> sympy.trigsimp(Q.inv()) 
[ cos(theta1), sin(theta1), 0, 0], 
[-sin(theta1), cos(theta1), 0, 0], 
[   0,   0, 1, -980], 
[   0,   0, 0, 1] 
+0

감사합니다. 나는 엑셀의 차이점을 평가했고 그들은 다르게 나오고 있었고, 뭔가 잘못된 것을 복사했을 것입니다. – Chris

관련 문제