Question: Python homework Calculating a trajectory Callista Cherry Bomb Davidson is at it again. Her scheme this week is to break last week's world record. To
Python homework
Calculating 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.
First, define a figure-of-merit function dist( angle,m_prop ) which accepts the angle of launch and the mass of propellant used m_prop (in kilograms) and returns the distance traveled (in m). This will be very similar to much of your code from hw10. You may also use the reference answer from hw10 to compose dist.
A reference case for dist is:
assert np.isclose( dist( 30,0.10 ),134.7136 )
For this particular cannon and Callista's weight, consider the initial velocity to be a function of propellant as follows:
v0(mprop)=1500(mprop65kg)0.45v0(mprop)=1500(mprop65kg)0.45
Your solution should include a function dist.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
