2014-09-28 53 views
-3

现在我一直在研究这个程序来模拟python中滑块曲柄机构的运动。 我遇到这个错误时遇到了死胡同。这是无缘无故抛出错误的方法。TypeError:'int'对象不可调用,滑块曲柄机制

def returnSliderAcceleration(a,b,theta_1,omega_1,alpha_1): 
    rad_temporary = theta_1 * np.pi/180 
    rad_temporary_2 = returnConnectorAngle(a,b,theta_1) 
    omega_2 = returnConnectorVelocity(a,b,theta_1,omega_1) 
    alpha_2 = returnConnectorAcceleration(a,b,theta_1,omega_1,alpha_1) 
    part_1 = a((alpha_1 * np.sin(rad_temporary)) + ((omega_1**2)*np.cos(rad_temporary))) 
    part_2 = b((alpha_2 * np.sin(rad_temporary_2)) + ((omega_2**2)*np.cos(rad_temporary_2))) 
    slider_acceleration = -1*(part_1 + part_2) 
    return slider_acceleration 

它利用的另一方法是:

def returnConnectorAngle(a,b,theta_1): #Returns the angle(in degrees) made by the connector corresponding to the crank angle, CCW taken as positive 
    rad_temporary = theta_1 * np.pi/180 
    x = (a/b) * np.sin(rad_temporary) 
    connector_angle = np.arcsin(x) 
    return (connector_angle* np.pi/180) 

def returnConnectorVelocity(a,b,theta_1,omega_1): #Returns the angular velocity of the connector, CCW taken as positive 
    rad_temporary = theta_1 * np.pi/180 
    rad_temporary_2 = returnConnectorAngle(a,b,theta_1) 
    Nr = a * omega_1 * np.cos(rad_temporary) 
    Dr = b * np.cos(rad_temporary_2) 
    connector_velocity = Nr/Dr 
    return connector_velocity 

def returnConnectorAcceleration(a,b,theta_1,omega_1,alpha_1): #Returns the angular acceleration of the connector arm, CCW taken as positive 
    rad_temporary = theta_1 * np.pi/180 
    rad_temporary_2 = returnConnectorAngle(a,b,theta_1) 
    omega_2 = returnConnectorVelocity(a,b,theta_1,omega_1) 
    Nr_1 = a * ((alpha_1 * np.cos(rad_temporary)) - ((omega_1**2)*np.sin(rad_temporary))) 
    Dr_1 = b * np.cos(rad_temporary_2) 
    part_2 = (omega_2**2) * np.tan(rad_temporary_2) 
    return (Nr_1/Dr_1) + part_2 

的错误:

slider_acceleration = -1*(a((alpha_1 * np.sin(rad_temporary)) + ((omega_1**2)*np.cos(rad_temporary)))+ b((alpha_2 * np.sin(rad_temporary_2)) + ((omega_2**2)*np.cos(rad_temporary_2)))) 
TypeError: 'int' object is not callable 
+0

请格式化你的代码,这是一个真正的痛苦,这样做... – 2014-09-28 05:37:29

+0

对不起。我对这个地方很陌生,当你为我做的时候我只是在编辑。谢谢! – 2014-09-28 05:49:42

回答

3

之前,我们甚至看你的代码,让我们在错误仔细看看Python是给你:

TypeError: 'int' object is not callable 

In thi s case,你的错误是TypeError。这意味着某些Python类型使用不正确。更详细的描述告诉我们另外两个事实:

  1. 使用不正确的类型是一个int
  2. 的问题是,我们试图呼叫int,但我们不能做但─我们可以调用functionsmethods,但不ints

下面就来产生相同的问题,一个简单的办法:

$ python 
>>> x = 3 
>>> y = x(10) 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
TypeError: 'int' object is not callable 

我们得到了这个错误,因为我们试图使用x作为参数10的函数,但x只是一个int。现在我们明白了这个错误的含义,让我们来看看您的代码。这里的问题的行,分裂了几行字:

slider_acceleration = -1 * (
    a(
     (alpha_1 * np.sin(rad_temporary)) + \ 
      ((omega_1**2)*np.cos(rad_temporary)) 
    ) + b(
     (alpha_2 * np.sin(rad_temporary_2)) + \ 
      ((omega_2**2)*np.cos(rad_temporary_2)) 
    ) 
) 

它看起来像你使用ab的功能,但他们?快速看看它们是如何用于其他功能的,我不会怀疑。也许你的意思是乘他们是这样的:

slider_acceleration = -1 * (
    a * (
     (alpha_1 * np.sin(rad_temporary)) + \ 
      ((omega_1**2)*np.cos(rad_temporary)) 
    ) + b * (
     (alpha_2 * np.sin(rad_temporary_2)) + \ 
      ((omega_2**2)*np.cos(rad_temporary_2)) 
    ) 
) 
+1

啊,解释所有这一切。我只是搞砸了基本的语法。我在纸上解决了问题,然后在转换为代码时,我只是在纸上键入了那些内容。万分感谢! – 2014-09-28 07:01:37