经典例题循环

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

  

posted @ 2025-08-07 08:37  华腾智算  阅读(6)  评论(0)    收藏  举报
https://damo.alibaba.com/ https://tianchi.aliyun.com/course?spm=5176.21206777.J_3941670930.5.87dc17c9BZNvLL