放物運動
from matplotlib import pyplot as plt
import math
def draw_graph(x,y): #グラフの生成
plt.plot(x,y)
plt.xlabel('距離')
plt.ylabel('高さ')
plt.title('放物運動')
def frange(start, final, interval): #時間間隔
numbers =
while start < final:
numbers.append(start)
start = start + interval
return numbers
def draw_trajection(u,theta): #放物運動
theta = math.radians(theta)
g = 9.8
t_flight = 2*u*math.sin(theta)/g
interval = frange(0, t_flight,0.001)
x=
y=[]
for t in interval:
x.append(u*math.cos(theta)*t)
y.append(u*math.sin(theta)*t-0.5*g*t*t)
draw_graph(x,y)
if __name__ == '__main__':
try:
u = float(input('速度を入力m/s:'))
theta = float(input('角度を入力:'))
except ValueError:
print('エラーな入力です。')
else:
draw_trajection(u,theta)
plt.show()