我想写一个代码,将绘制一个球从高度h下降的模拟,并使用运动方程y = y_0 我的代码是这样的:随着时间的推移随着时间的推移球的位置下降的情节
从matplotlib.pylab进口展,xlabel,ylabel,散布,情节 从numpy的进口空
def drop():
"""
This function calculates and creates arrays for the velocity at eac time interval as well as the position and plots it. Assuming no drag.
"""
#Define the constants in the problem
h_0 = 10
g = -9.8 #gravitational constant N
dt = 0.1 #timestep
#Now need to create arrays to hold the positins, time, and velocities
vel = empty(1000,float)
time = empty(1000,float)
y = empty(1000,float)
time[0] = 0
vel[0] = 0
y[0] = h_0
#code for the kinematic equations for the calculation of time, velocity and position
for i in range of (1000-1):
time[i+1] = time[i] + dt
vel[i+1] = vel[i] + (g * dt)
y[i+1] = time[i] + (vel[i+1] * dt)
if y[i] > 0:
#ensures that the graph will not keep going when the ball hits the ground
break
plot(time,y, '.')
xlabel("Time(s)")
ylabel("Position")
show()
但是我的图形绘制三个点之一的图时的每个角落它应该看起来像一条曲线,我的图形每次都会改变,因为不是ne的变量正在变化