1

高さ h から落下するボールのシミュレーションをプロットし、運動方程式 y = y_0 を使用して経時的な位置のグラフを作成するコードを作成しようとしています。私のコードは次のとおりです。

matplotlib.pylab import show, xlabel, ylabel, scatter, plot from numpy import empty

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()

ただし、グラフが曲線のように見えるはずのときに、グラフの各隅に 3 つのドットが 1 つずつプロットされ、どの変数も変化していないため、グラフは毎回変化してはなりません。

4

1 に答える 1