经典例题循环
import matplotlib.pyplot as plt
h,v0,g=3000,200,9.8
t,n=0,30
tmax=(2*h/9)**0.5
delta=tmax/(n-1)
xt,yt=[],[]
while t<=tmax:
xt.append(v0*t)
yt.append(h-1/2*g*t**2)
t=t+delta
plt.plot(xt,yt,'r-')
plt.grid('on')
plt.axis([0,5000,0,h])
plt.show()
import matplotlib.pyplot as plt
h,v0,g=3000,200,9.8
t,n=0,30
tmax=(2*h/9)**0.5
delta=tmax/(n-1)
xt,yt=[],[]
for i in range(n):
t=delta*i
xt.append(v0*t)
yt.append(h-1/2*g*t**2)
plt.plot(xt,yt,'r-')
plt.grid('on')
plt.axis([0,5000,0,h])
plt.show()

浙公网安备 33010602011771号