Я пытаюсь написать код, который будет отображать симуляцию падения мяча с высоты h и строить график положения во времени с использованием кинематических уравнений y = y_0. Мой код таков:
из matplotlib.pylab import show, xlabel, ylabel, scatter, график из пустого импорта 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()
Однако мой график отображает три точки по одной в каждом углу графика, когда он должен выглядеть как кривая, и мой график меняется каждый раз, когда он не должен, поскольку ни одна из переменных не меняется.