Question
Optimizing a trajectory Callista Cherry Bomb Davidson is at it again. Her scheme this week is to break last week's world record. To this end,
Optimizing a trajectory
Callista "Cherry Bomb" Davidson is at it again. Her scheme this week is to break last week's world record. To this end, she has purchased a new cannon rig, which can accommodate greater, perhaps even dangerous, amounts of propellant. Since there are so many variables to track, rather than try to brute-force a solution, she asks you to optimize the launch for her again.
Your solution should seek to optimize distance traveled by varying the angle of launch (090) and the amount of propellant (0.050.12). You may have some suspicions about the best-case scenario, but you should adopt a hill-climbing procedure to be certain.
This problem is _convex_, meaning that a hill-climbing approach should be able to find the globally optimal solution. This makes it a great candidate for this optimization technique.
Use 0.05 kg as the initial guess for the propellant mass. Use a starting height of 5m5m and assume an acceleration due to gravity of g=9.8ms2g=9.8ms2. Use a starting angle of 0. Treat drag and xx and yy components as in hw10, as well as collision with the ground.
It's worth noting that the physics in hw10 were a bit off. The calculation for the force in the xxxx-direction was specified there as Fx=CDv2xFx=CDv2xFx=CDvx2Fx=CDv2x; it should rather have been based on the component of total velocity, Fx=CDv2||vxv||Fx=CDv2vxvFx=CDv2|vxv|Fx=CDv2vxv. This means that if you have a line like
ax = -( 0.5*rho*C*A/mass ) * vx[ j-1 ] ** 2
you should replace it with something like
v = np.sqrt( vx[ j-1 ]**2 + vy[ i,j-1 ]**2 ) ax = -( 0.5*rho*C*A/mass ) * v**2 * ( vx[ i,j-1 ] / v )
for hw11. You will need to perform this transformation for the y-component as well.
For a given launch (with angle and propellant), calculate the distance Callista travels in ten seconds with 1,000 time steps (so 1,001 states including the initial condition).
Next, change the launch angle iteratively in steps of 1 until distance is maximized. Accept the change if it improves on the solution; if it does not, end this step.
Next, change the mass of propellant iteratively in steps of 0.001 kg used until distance is maximized.
We could cycle repeatedly to guarantee optimality. In this case, one cycle of each does pretty well, yielding a distance within about 0.5% of the true value.
You may vary the angle of launch from 090 and the amount of propellant between 0.050.12 kg. When no improvement is possible, the hill-climbing solution is complete.
Finally, your code should define three variables max_dist, the maximum distance traveled; max_angle, the corresponding launch angle; and max_m_prop, the amount of propellant which should be used in the attempt.
(Note that you will need to convert from degrees to radians before using the numpy sin and cos functions.)
Your solution should include result variables max_dist, max_angle, and max_m_prop. Assume that dist is provided.
Extras
I enjoyed both of the following articles while composing this example:
"The ballistic performance of the bombard Mons Meg"
"Estimating propellant charge weights"
Starter code (click to view)
guess_dist = 0 # m guess_angle = 0 # deg guess_m_prop = 0.05 # kg max_dist = 0.0 # change angle iteratively until improvement stops old_guess_dist = guess_dist - 1 while guess_dist >= old_guess_dist: old_guess_dist = guess_dist guess_angle += ??? guess_dist = dist( guess_angle,guess_m_prop ) # ??? # then change m_prop iteratively until improvement stops old_guess_dist = guess_dist - 1 while guess_dist >= old_guess_dist: pass # similar to the above but in guess_m_prop # do not change the angle at all here; just use max_angle # now you should know max_dist, max_angle, max_m_prop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started