第1關:繪制一個坐標點
1.某轟炸機在h=3km的高空以200m/s的速度水平勻速飛行,到達A點是投下一枚無動力炸彈,不考慮空氣阻力,重力加速度g的值取9.8,我們可以通過如下公式得到炸彈在任意時候的位置,
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt #匯入matplotlib.pyplot
h, v0, g = 3000, 200, 9.8
for t in [10, 15, 20, 24]:
xt = v0*t
yt = h-1/2*g*t**2
plt.ylim((0, 3000))
plt.xlim((0, 5000))
plt.grid('on')
######## begin ############
# 請使用plot函式,繪制一個坐標點
plt.plot(xt, yt, 'ro')
######## end ##############
plt.savefig('./student result/%s秒后.png' % str(t))
plt.close()
第2關:繪制n個坐標點
2.某轟炸機在h=3km的高空以200m/s的速度水平勻速飛行,到達A點是投下一枚無動力炸彈,不考慮空氣阻力,重力加速度g的值取9.8,我們可以通過如下公式得到炸彈在任意時候的位置,
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt #匯入matplotlib.pyplot
h, v0, g = 3000, 200, 9.8
t, n = 0, 30 #n為要繪制的坐標點數量,假設為30
tmax = (2*h/g)**0.5
delta = tmax/(n-1) #delta為相鄰兩時刻之間的間隔
while t<=tmax: #t從0變到tmax,每次加delta
###### begin ##########
# 請在此填寫運算式,計算時間為t時,x軸與y軸的位置,并命名為xt與yt
xt = v0*t
yt = h-1/2*g*t**2
######### end ############
plt.plot(xt,yt,'ro')
t = t+delta
plt.grid('on')
plt.axis([0, 5000, 0, h])
plt.savefig('./student result2/%s個點.png' % str(n))
plt.close()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/250128.html
標籤:其他
下一篇:h5貪吃蛇
