import numpy as np
fx = np.zeros([6])
fy = np.zeros([6])
ax = np.zeros([6])
ay = np.zeros([6])
x = np.zeros([6])
y = np.zeros([6])
vy = np.zeros([6])
vx = np.zeros([6])
x[0] = 11
x[1] = 13
x[2] = 10
x[3] = 6
x[4] = 5
x[5]= 7.1
vx[0] = 1
vy[0] = 1
y[0] = 1
y[1] = 2
y[2] = 4
y[3] = 6
y[4] = 5
y[5]= 7.1
sigma = 1.01
e = 1.1
dt = 0.1
def LJ(x,y):
for i in range(0,6):
for j in range(0,6):
if i == j:
continue
rx = x[i]-x[j]
ry = y[i]-y[j]
fx[i] = 24*e*(((2/rx)*sigma/rx**12)-((1/rx)*sigma/rx**6))
fy[i] = 24*e*(((2/ry)*sigma/ry**12)-((1/ry)*sigma/ry**6))
return fx, fy
def verlet():
for i in range(0,10):
ax[i], ay[i] = -LJ(x[i],y[i])
x[i+1] = x[i] + dt*vx[i]+0.5*dt**2*ax[i]
y[i+1] = y[i] + dt*vy[i]+0.5*dt**2*ay[i]
ax[i+1],ay[i+1] = -LJ(x[i+1],y[i+1])
vx[i+1] = vx[i] + 0.5*dt*(ax[i]+ax[i+1])
vy[i+1] = vy[i] + 0.5*dt*(ay[i]+ay[i+1])
t[i+1] = t[i]+dt
print x,y
verlet()
我尝试使用verlet alghoritm来计算力,位置,速度和加速度。 当我开始我的程序时,我收到错误
ax[i], ay[i] = LJ(x[i],y[i])
rx = x[i]-x[j]
IndexError: invalid index to scalar variable.
我不明白这个错误。怎么了??我的verlet alghoritm是否正确?