import numpy as np # from numpy import* not required to write np
import pandas as pd # from pandas import*
import matplotlib.pyplot as pltfrom # from matplotlib import*
%matplotlib inline
def projectile(u,theta):
g=9.8 # acceleration due to gravity
R = u**2*np.sin(2*np.pi*theta/180)/g # range
H= u**2*np.sin(np.pi*theta/180)**2/(2*g) # max. height
TF = 2*u*np.sin(np.pi*theta/180)/g # time of flight
return [R,H,TF]
p=projectile(100,60)
p
[883.699391616774, 382.6530612244897, 17.67398783233548]
Angle=[] #list for angle
R=[] #list for range
H=[] # list for height
TF=[] #list for time of flight
for angle in range(1,91):
a=projectile(100,angle)
Angle.append(angle)
R.append(a[0]) # added element in list R
H.append(a[1]) # added element in list H
TF.append(a[2]) # added element in list TF
plt.plot(Angle,R,'g-.',label='Range')
plt.plot(Angle,H,'b^',label='Max.height')
plt.xlabel('Angle(degree)')
plt.ylabel('Distance(m)')
plt.title('Projectile')
plt.legend()
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-5-2812d7921713> in <module> ----> 1 plt.plot(Angle,R,'g-.',label='Range') 2 plt.plot(Angle,H,'b^',label='Max.height') 3 plt.xlabel('Angle(degree)') 4 plt.ylabel('Distance(m)') 5 plt.title('Projectile') NameError: name 'plt' is not defined
plt.plot(Angle,TF,'k*')
plt.xlabel('Angle(degree)')
plt.ylabel('Time of flight(sec)')
plt.title('Projectile')
plt.savefig('projective.eps')
plt.show()
data={} # dictionary
data.update({"Angle":Angle,"Range":R ,"Time of flight":TF,"Max.Height": H})
DF = pd.DataFrame(data)
DF
DF.to_csv("projectile.csv") #save data in csv format in excel