错误“不能将序列乘以'int'类型的非int”

时间:2017-11-27 22:26:23

标签: python numpy

在下面的代码中,当我尝试运行“x01 = rk4(x01,t1 [-1],h1,fallParabola)”时,“弹出一个错误”说“不能将序列乘以非int输入'float'。“我想知道为什么会这样,因为我认为将numpy数组中的每个项乘以数字乘以数字中的每个项乘以该数字。

** slope1和intercept1已经在别处定义,所以这不是问题

def rk4(f,t,h,g):
    k1 = h*g(t,f)
    k2 = h*g(t+0.5*h, f+0.5*k1)
    k3 = h*g(t+0.5*h, f+0.5*k2)
    k4 = h*g(t+h, f+k3)
    return f + k1/6. + k2/3. + k3/3. + k4/6.

def fallParabola(t,f):
    g = 10
    px = f[0]
    py = f[1]
    vx = f[2]
    vy = f[3]
    slope = slope1 * (px-shift1)
    theta = sp.arctan(np.abs(slope))
    acc = np.array([vx,vy,g*sp.sin(theta)*sp.cos(theta), 
        g*sp.sin(theta)*sp.sin(theta)])
    return acc,slope

x01 = np.array([0.0,intercept1,0.0,0.0])
t01 = 0.
px1 = [x01[0],]
py1 = [x01[1],]
vx1 = [x01[2],]
vy1 = [x01[3],]
t1 = [t01,]
h1 = 0.1
while py1[-1] > 0:
    x01 = rk4(x01,t1[-1],h1,fallParabola)
    px1.append(x01[0])
    py1.append(x01[1])
    vx1.append(x01[2])
    vy1.append(x01[3])
    t1.append(t1[-1]+h1)

0 个答案:

没有答案