# 0. Place your necessary imports here. You may find it useful to be able to plot when debugging and visualizing your result.
import numpy as np
# 1. Create a 1D vector named `t` and 2D arrays named `vx`, `vy`, `x`, and `y` to hold the state variables, of size 90 x 1001.
t = np.linspace(0,10,1001)
print(len(t))
vx = np.empty((90,1001))
vy = np.empty((90,1001))
x = np.empty((90,1001))
y = np.empty((90,1001))
# 2. Store the angles from 1 to 90 degrees as radians in a variable called `radians`. Use this to initialize the state variables for `vx` and `vy`.
angles = np.arange(1,91)
radians = angles * 2*np.pi/360
# 3. Define properties like gravity, Callista's surface area, and Callista's mass, and any other parameters you may need as they come up.
A = 0.8 # m^2
g = -9.8 # m/s^2
m = 65 # kg
Cd = 1.4 # drag coeffiency
D = 1.225 # kg/m^3
# etc. Note that I expect an `initial_height` and `initial_velocity` below.
# 4. At this point, you should have defined `t`, `x`, `y`, `vx`, `vy`, `radians`, and the properties you need. Now, initialize the starting condition in each array:
initial_height = 5 # m
initial_velocity = 70 # m/s
for i in range(len(radians)):
x[ i,0 ] = 0
y[ i,0 ] = initial_height
vx[ i,0 ] = initial_velocity * np.cos( radians[ i ] )
vy[ i,0 ] = initial_velocity * np.sin( radians[ i ] ) # (see "Angles" above)
# 5. Now you are ready to begin the simulation proper. You will need two loops, one over every angle, and one over every time step for that angle's launch.
for i in range(len(radians)): # loop over each angle
#i=k+1
for j in range(len(t)): # loop over each time step
#j=l+1
# check that the location isn't below the ground; if so, adjust as specified above
if j>0:
if y[i,j-1]==0:
x[i,j]=x[i,j-1]
y[i,j]=0
vx[i,j]=0
vy[i,j]=0
else:
# calculate the acceleration including drag (for both x and y, x shown)
v = np.sqrt( vx[ i,j-1]**2 + vy[ i,j-1]**2 )
ax = -( 0.5*D*Cd*A/m ) * v**2 * ( vx[ i,j-1 ] / v )
ay = -( 0.5*D*Cd*A/m ) * v**2 * ( vy[ i,j-1 ] / v )+g
# calculate the change in position at time `ts` using the current velocities (`vx[ i,j ]`) and the previous positions (`x[ i,j-1 ]`). This is slightly different from the previous example you solved in an earlier homework.
ts=t[j]-t[j-1]
vx[i,j]=vx[i,j-1]+ax*ts
vy[i,j]=vy[i,j-1]+ay*ts
y[i,j] = y[i,j-1]+vy[i,j]*ts+0.5*ay*ts**2
x[i,j] = x[i,j-1]+vx[i,j]*ts+0.5*ax*ts**2
# check that the location isn't below the ground (again!); if so, adjust
if y[i,j]<=0:
x[i,j]=x[i,j-1]
y[i,j]=0
vx[i,j]=0
vy[i,j]=0
# 6. The purpose of these calculations was to show which angle yielded the farthest distance. Find this out and store the result in a variable named `best_angle`.
max= np.max(x)
maxi=np.where(max==x[:,1000])
print(maxi)