import matplotlib.pyplot as plt
import numpy as np
n = 5000 # number of data points to plot
start = 0.0 # start time, s
end = 4500.0 # ending time, s
g = -8.87 # acceleration, m*s**-2
t = np.linspace( start,end,n+1,dtype=np.float(64) # time, s
y = np.zeros( n+1 ) # height, m
v = np.zeros( n+1 ) # velocity, m*s**-1
y[ 0 ] = 250000 # initial condition, m
v[ 0 ]=0
bounce=0.0
for i in range( 1,n+1 ):
v[ i ] = v[ i-1 ] + g*( t[ i ]-t[ i-1 ] )
y[ i ] = y[ i-1 ] + v[ i-1 ] * ( t[ i ]-t[ i-1 ] )
if y[ i ] <= 0:
bounce+=1
v[ i ] = -0.9*v[ i-1 ]
y[ i ]=0
plt.plot( t,y )
plt.show()
为什么y = np.zeros(n + 1)的语法无效? 我想计算球从250公里的高度在1小时15分钟内弹跳多少次,每次弹跳时都会失去10%的速度
答案 0 :(得分:2)
你在这一行上错过了一个人:
t = np.linspace( start,end,n+1,dtype=np.float(64)
应该是:
t = np.linspace( start,end,n+1,dtype=np.float(64))