# Projectile Motion¶

Recall that the equation for projectile motion when acceleration is constant can be written as $$y=y_{0}+v_{0}t+\frac{a}{2}t^{2}.$$

1. Create a Matlab or Python function that generates a plot of $y(t)$. You should be able to easily change the initial velocity, the initial position, and the acceleration. Be sure to include axis labels as appropriate. The function should take $y_{0}$, $v_{0}$, $a$ and a vector of $t$ as arguments. The function should:

(a) Plot $y(t)$ with labeled axes and a grid on the plot.

(b) Return the vector $y(t)$.

2. Determine $t_{\mathrm{end}}$ such that $y(t_{\mathrm{end}})=0$. In the event that there are two times that produce $y=0$ you should use the larger of the two. HINT: Solve the quadratic equation for the projectile.

You do not need to submit a report for this problem - only your Matlab or Python files.

# Solution¶

## Question 1¶

Create a Matlab or Python function that generates a plot of $y(t)$. You should be able to easily change the initial velocity, the initial position, and the acceleration. Be sure to include axis labels as appropriate. The function should take $y_{0}$, $v_{0}$, $a$ and a vector of $t$ as arguments. The function should:

(a) Plot $y(t)$ with labeled axes and a grid on the plot.

(b) Return the vector $y(t)$.
In [8]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

In [18]:
def projectile(y0,v0,a,t):
"""The method's docstring
params:
y0: value
v0: value 2
"""
result = y0 + v0 * t + a/2.0 * t * t
plt.title('Projectile')
plt.xlabel('time (s)', fontsize=18)
plt.ylabel('Height (m)', fontsize=16)
plt.plot(t,result)
return result

In [20]:
y0=0.1
v0=10
a=-9.81
t = np.linspace(0,2,200)
y = projectile(y0,v0,a,t)


## Question 2¶

Determine $t_{\mathrm{end}}$ such that $y(t_{\mathrm{end}})=0$. In the event that there are two times that produce $y=0$ you should use the larger of the two. HINT: Solve the quadratic equation for the projectile.

What we can do here is use numpy's roots function

In [23]:
tend = np.max(np.roots([a/2,v0,y0]))
print('The Projectile will reach the ground in:', tend)
t = np.linspace(0,tend,200)
y = projectile(y0,v0,a,t)

The Projectile will reach the ground in: 2.048687409049999