这个python程序应该模拟一个物体从50米的建筑物上抛出,具有一些初始速度和恒定的重力加速度。 我正在使用数组来存储不同的组件,但是当我需要做计算的时候,我的结果矩阵并不像它应该那样。事实上,由此产生的矩阵大部分仍然是空的。什么可能导致这个问题?Python模拟中的逻辑错误
x = z = vz = vy = ax = ay = time = 0.0
y = 50 #Initial Height: 50 meters
vx = 25 #Initial velocity in the x direction: 25 m/s
az = -9.8 #Constant acceleration in the z direction: -9.8 m/s^2
deltaTime = .000001
#Initializes a matrix with 3 columns and 1000 rows for each column: Will hold the corresponding x,y,z coordinate of the particle at time t
positionMatrix = [[None]*1000 for x in range(3)]
posArray = [x, y, z]
velArray = [vx, vy, vz]
accArray = [ax, ay, az]
timeArray = [i*deltaTime for i in range(1000)]
j = 1 #time increment
for j in range (1,500): #j is the time increment
for i in range (1,3): #i is each component (x, y, z)
#x = x + vx*time + .5*ax*(time*time); #y = y + vy*time + .5*ay*(time*time); #z = z + vz*time + .5*az*(time*time)
positionMatrix[i][j] = posArray[i] + velArray[i] * timeArray[j] + 1/2*accArray[i] * timeArray[j] * timeArray[j]
print(positionMatrix)
哪里z和VZ界定? – Nix
@Nix:我修复了这个部分,但仍然没有得到更好的结果 – kachilous
个人(这不会是你的问题),如果使用它3次,我会缓存timeArray [j]。 – cwallenpoole