STARTER CODE: # 0. Place your necessary imports here. You may find it useful to be able
Question:
STARTER CODE:
# 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 = ???
# 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`. m = 90 # angles to fire at angles = ??? 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 # 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: for i in range(m): y[ i,0 ] = initial_height vx[ i,0 ] = initial_velocity * np.cos( radians[ i ] ) vy[ i,0 ] = ??? # (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 ???: # loop over each angle for j in ???: # loop over each time step # check that the location isn't below the ground; if so, adjust as specified above # 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*rho*C*A/mass ) * v**2 * ( vx[ i,j-1 ] / v ) # 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.
# 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`.
Discrete Mathematics and Its Applications
ISBN: 978-0073383095
7th edition
Authors: Kenneth H. Rosen