我试图得到每个时间值的向量和度的值,但是我被这个错误困住了:
TypeError:不支持的操作数类型为+:'int‘和'tuple’
如果我追踪到x= -0,3*(t**2)+(7,2*t)+28,那为什么是int = tuple呢?
回溯:
Traceback (most recent call last):
File "testgraph.py", line 53, in <module>
vector, degrees = vector_position(t)
File "testgraph.py", line 14, in vector_position
x = function_positionX(t)
File "testgraph.py", line 5, in function_positionX
x = -0,3*(t**2)+(7,2*t)+28 代码:
import numpy as np
import math
def function_positionX(t):
x = -0,3*(t**2)+(7,2*t)+28
return x
def function_positionY(t):
y = 0,22*(t**2)-(9,1*t)+30
return y
def vector_position(t):
x = function_positionX(t)
y = function_positionY(t)
v = math.sqrt((x**2)+(y**2))
d = np.arctan2(y/x)
return v,d
def function_speedX(t):
x = -0,62*t+7,2
return x
def function_speedY(t):
y = 0,44*t-9,1
return y
def vector_speed(t):
x = function_speedX(t)
y = function_speedY(t)
v = math.sqrt((x**2)+(y**2))
d = np.arctan2(y/x)
return v,d
def function_accelX():
a = -0,62
return a
def function_accelY():
a = 0,44
return a
def vector_accel(t):
x = function_accelX()
y = function_accelY()
v = math.sqrt((x**2)+(y**2))
d = np.arctan2(y/x)
return v,d
for t in range(0,15):
print("For time: ", t)
vector, degrees = vector_position(t)
print(vector,degrees)
vector, degrees = vector_speed(t)
print(vector,degrees)
vector, degrees = vector_accel(t)
print(vector,degrees)发布于 2018-03-23 05:07:30
我不是专家,但当你写0,3时,你指的是0.3吗?我们通常不会用逗号表示小数点!
这就是为什么你要得到提到的错误,所以把逗号改为点,然后再试一次。
在深入研究更高级的东西之前,试着花些时间来适应python本身和编程。
https://stackoverflow.com/questions/49442689
复制相似问题