Sympy:“Mul”对象没有分层函数的“cos”属性

2024-10-01 07:36:03 发布

您现在位置:Python中文网/ 问答频道 /正文

摘要

我有一个Jupyter实验室的笔记本,我一直试图用它来开发机械臂的Jacobian符号。我有表达式,然后在后面的表达式中使用,等等。我在尝试运行lambdified final表达式时收到消息“Mul”对象没有属性“cos”

我所做的一切

以下是其他问题,如

Sympy to numpy causes the AttributeError: 'Symbol' object has no attribute 'cos'

What causes this error (AttributeError: 'Mul' object has no attribute 'cos') in Python?

我一定要打电话给sympy使用:

import sympy as sp

然后用sp前缀调用所有内容:

^{pr2}$

这是我的代码(我为长代码道歉)

^{3}$

预期产量

包含数值的3x6矩阵

实际产量

以下错误归因于最后一行:

AttributeError: 'Mul' object has no attribute 'cos'

我想这与我如何把函数和多个表达式扭曲在一起有关,但我不太确定如何去发现它到底在哪里失败。在

回溯

它有点庞大;我用...删除了表达式的其余部分

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-d0f45c1787c2> in <module>
----> 1 current_jacobian = jacobian_numeric(0,sp.pi/2,0,0,0,0,0,0,0,1,0.3,0.1) # add pi/2 to theta2 because of the initial offset between x_2 and x_3
      2 current_jacobian

<lambdifygenerated-1> in _lambdifygenerated(theta1, theta2, theta3, theta4, theta5, theta6, a1, a2, a3, d1, d4, d6)
      1 def _lambdifygenerated(theta1, theta2, theta3, theta4, theta5, theta6, a1, a2, a3, d1, d4, d6):
----> 2     return (array([[array([[-a1*sin(theta1) - a2*sin(theta1)*cos(theta2) + a3*sin(theta1)*sin(theta2)*sin(theta3) - a3*sin(theta1)*cos(theta2)*cos(theta3) +...

AttributeError: 'Mul' object has no attribute 'cos'

Tags: noinobject表达式attributesincossp
1条回答
网友
1楼 · 发布于 2024-10-01 07:36:03

我不完全确定为什么,但是当我用jacobian_numeric(0,np.pi/2,0,0,0,0,0,0,0,1,0.3,0.1)最后一行中的sp.pi替换np.pi时,错误就消失了。我已经看到了其他几个问题,有类似的问题,但在这一点上没有好的答案。这可能是simpy中的一个错误,或者希望其他人有更好的解释。在

相关问题 更多 >