#DON'T CHANGE ANYTHING IN THIS CELL
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
import pandas as pd
#DON'T CHANGE ANYTHING IN THIS CELL
#Method makeplots() plots the data in the dataframe. It makes three line plots
#Plot 1: y position vs. x position of the projectile
#Plot 2: x (and y) velocities of the projectile vs. time ploted on the same axis
#Plot 3: x (and y) acceleration of the projectile vs. time ploted on the same axis
def makeplots():
df.plot(x ='x', y='y', kind = 'line', title='Path of Projectile [m]')
plt.xlabel('Horizontal Postion')
plt.ylabel('Vertical Postion')
df.plot(x='t', y={'vx','vy'}, kind = 'line', title='Velocities [m/s] vs. Time [s]')
plt.xlabel('Time')
plt.ylabel('Velocity')
df.plot(x='t', y={'ax','ay'}, kind = 'line', title='Accelerations [m/s/s] vs. Time [s]');
plt.xlabel('Time')
plt.ylabel('Acceleration')
#DO NOT CHANGE THE NAMES OF THE METHODS OR THE VARIABLES
#THAT ARE GETTING PASSED TO THESE METHODS
#Method getaccelerationx has inputs of the current s_y (height)
#and the current v_x and v_y. It returns the current value of
#the x acceleration. It will call getdensity(height)
def get_acc_x(height,vx,vy):
# Put your code between the lines
#_________________________________________________
#_________________________________________________
return #make sure to return a value here
#Method getaccelerationx has inputs of the current s_y (height)
#and the current v_x and v_y. It returns the current value of
#the y acceleration. It will call getdensity(height)
def get_acc_y(height,vx,vy):
# Put your code between the lines
#_________________________________________________
#_________________________________________________
return #make sure to return a value here
#Method getdensity has inputs of the current s_y (height)
#and uses the equation for the density of air provided
#in the description to return the density at the input height
def getdensity(height):
# Put your code between the lines
#_________________________________________________
#_________________________________________________
return #make sure to return a value here
#DON'T CHANGE ANYTHING IN THIS CELL
#NOTICE THIS METHOD RETURNS THE RANGE (THIS WILL BE HELPFUL IF YOU ATTEMPT LEVEL 2)
#Method takeshot(v,theta) takes inputs of an initial launch velocity in
#(m/s) and launch angle in (degrees)it returns the range of the projectile in (m).
#It initialze the data lists and then updates the lists with each timestep.
def takeshot(v,theta):
# convert angle to radians
theta = theta*np.pi/180
#initialize all lists
t=0
x=0
y=0
vx=v*np.cos(theta)
vy=v*np.sin(theta)
ax=get_acc_x(y,vx,vy)
ay=get_acc_y(y,vx,vy)
data = [[t,x,y,vx,vy,ax,ay]] #make a list of lists
#iterate system
while (y >= 0 ):
# Put your code between the lines
#___________________________________________________
#___________________________________________________
data.append([t,x,y,vx,vy,ax,ay])
return data
#ONLY CHANGE THE VALUES OF V AND T IN THE FOLLOWING CODE
#this is the main code for level 1
#you have to provide the initial conditions V = speed, and T = theta
#it then calls takeshot(v,t) which outputs a big list of lists of all
#the data. We then convert that big list of lists into a pandas dataframe
#that we can use to view the data or make nice looking plots.
V=1600
T= 50
data = takeshot(V,T)
df = pd.DataFrame(data, columns = ["t","x","y","vx","vy","ax","ay"])
print('Time of Flight = ',df['t'].iloc[-1], ' seconds')
print('Range of Projectile is: ',df['x'].iloc[-1], ' meters')
makeplots()
#Method find_optimal_angle() has an input of the initial speed (v) and returns the
#the optimal launch angle for that speed and the range of that optimal launch. It
#should make use of method takeshot().
def find_optimal_angle(v):
# Put your code between the lines
#___________________________________________________
#___________________________________________________
return #don't forget to return the optimal angle
#this is the main code for level 2
#it makes a call to find_optimal_angle, which returns an angle
#then the range and angle are printed, followed by graphs of
#the optimal conditions.
V=1600 #set intitial launch speed
(R,T)=find_optimal_angle(V) #make call to main method
print('Optimal Launch angle is: ', T, 'degrees') #print angle
print('Range is: ',R,'meters') #print range
makeplots() #make plots