Я пытаюсь написать код, который будет отображать симуляцию шара, выпавшего с высоты h, и составить график положения во времени с использованием кинематических уравнений y = y_0 Моего код заключается в следующем:Шаг падения шага по времени с помощью python
из 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 переменных меняется