ECE 2331 – Programming Assignment 3 The Kessel Run
The problem Your job is to create an algorithm that can plot a course through a black hole cluster. You will load a series of black hole positions and masses: 𝑋𝑋= [𝑥𝑥1,𝑥𝑥2,𝑥𝑥3,⋅⋅⋅,𝑥𝑥𝑁𝑁] 𝑌𝑌= [𝑦𝑦1,𝑦𝑦2,𝑦𝑦3,⋅⋅⋅,𝑦𝑦𝑁𝑁] 𝑀𝑀= [𝑚𝑚1,𝑚𝑚2,𝑚𝑚3,⋅⋅⋅,𝑚𝑚𝑁𝑁] where (𝑥𝑥𝑖𝑖,𝑦𝑦𝑖𝑖) is the position of gravity well 𝑖𝑖 and 𝑚𝑚𝑖𝑖 is its mass. These black holes will be placed on a 20x20 parsec plane with the origin at the center: ( [−10,10]× [−10,10] ). The starting point 𝑝𝑝0 can be anywhere along a 10 parsec line centered at the bottom of the playing field: 𝑝𝑝0= (𝑝𝑝𝑥𝑥,𝑝𝑝𝑦𝑦), where 𝑝𝑝𝑥𝑥∈[−5, 5] and 𝑝𝑝𝑦𝑦=−10. The starting velocity 𝑣𝑣(𝑡𝑡0)=𝒗𝒗0 is given by the direction vector 𝒗𝒗𝟎𝟎 with magnitude |𝒗𝒗𝟎𝟎|: 𝒗𝒗0=|𝒗𝒗0|⋅𝒗𝒗0 The starting trajectory 𝒗𝒗�0 is specified by a normal distribution with a standard deviation of 𝜋𝜋 4 radians from the positive 𝑦𝑦- axis: [0, 1] . The initial state of the playing field is shown in the following figure:
Software Your software will compute the shortest path through the black hole cluster and return the optimal start point 𝑝𝑝 0 and velocity 𝒗𝒗0 to make the trip. This optimal start state will be estimated using a Monte -Carlo simulation. Each start state will be tested using a physically -based model of the black hole cluster using a n explicit Runge -Kutta integration method (ex. Euler’s method) . Output
You are required to use Matlab, and may use any functions available in the standard distribution. Turn your program in as a single *.m file. Display the following using a scatter plot: • The gravity well positions (files of positions will be provided) • The shortest path found as a color -mapped curve (blue = start, red = end) • The longest path found as a color -mapped curve (blue = start, red = end)
Write your code to perform the following functions:
For each Monte -Carlo sample ----------------
- Select a starting position 𝑝𝑝(𝑡𝑡0)=𝑝𝑝0 for your ship a. The start position is a randomly selected position at 𝑦𝑦=−10 and 𝑥𝑥 ∈ [−5, 5] b. Draw the random position from a uniform distribution
- Select a starting velocity 𝑣𝑣(𝑡𝑡0)=𝒗𝒗𝟎𝟎=|𝒗𝒗𝟎𝟎|⋅𝒗𝒗�0 a. The orientation vector 𝒗𝒗 �0 is a normalized trajectory from the start point i. Select 𝒗𝒗�0 to be pointing outward from 𝑝𝑝0 ii. Draw this trajectory from a normal distribution with a standard deviation of 𝜋𝜋 4 iii. T he mean of this distribution is along the 𝑦𝑦-axis: usually expressed as 𝜃𝜃=𝜋𝜋 2 in polar coordinates b. The scalar magnitude |𝒗𝒗𝟎𝟎| is the starting speed of your ship relative to the start point i. Select |𝒗𝒗𝟎𝟎|∈[2, 5] ii. Draw this random speed from a uniform distribution
- Simulate the passage of the ship a. For each time step i. Determine the force incident on the ship (see below)
- Terminate if the maximum net acceleration exceeds ‖𝑎𝑎(𝑡𝑡)‖2= 4 ii. Update the ship’ s velocity using an explicit method (ex. Euler’s method) iii. Update the ship’s position using an explicit method (ex. Euler’s method)
- Terminate (successfully) if the ship reaches its des tination: 𝑦𝑦>10
System of Differential Equations In step (3), y ou are solving for the ship position as a function of time 𝑝𝑝(𝑡𝑡) using the following system of differential equations: 𝑑𝑑𝑝𝑝 𝑑𝑑𝑡𝑡=𝑣𝑣(𝑡𝑡)
𝑑𝑑𝑣𝑣 𝑑𝑑𝑡𝑡=𝑎𝑎(𝑡𝑡)
�𝐹𝐹𝑖𝑖𝑁𝑁 𝑖𝑖=1=𝑚𝑚𝑠𝑠⋅𝑎𝑎(𝑡𝑡)
The net force 𝐹𝐹 applies an acceleration to your ship. The net force applied is the sum of forces applied by all black holes. The force applied by a black hole is proportional to the distance between your ship and the black hole. The vector from your ship and a black hole is given by: 𝒓𝒓 𝑖𝑖=[𝑥𝑥𝑖𝑖 𝑦𝑦𝑖𝑖]𝑇𝑇−𝒑𝒑𝑠𝑠 where 𝒑𝒑𝑠𝑠 is the position of your ship and 𝑖𝑖 is the index of the black hole. The distance between your ship and the black hole is |𝒓𝒓𝑖𝑖|, where the vector magnitude is given by the Euclidean norm : |𝒃𝒃|=�𝑏𝑏𝑥𝑥2+𝑏𝑏𝑦𝑦2 The force that a single b lack hole applies to your ship is: 𝑭𝑭𝑖𝑖=𝒓𝒓𝑖𝑖 |𝒓𝒓𝑖𝑖|⋅𝑚𝑚𝑠𝑠𝑚𝑚𝑖𝑖 |𝒓𝒓𝑖𝑖|2=𝒓𝒓𝑖𝑖𝑚𝑚𝑠𝑠𝑚𝑚𝑖𝑖 |𝒓𝒓𝑖𝑖|3 Wh ere 𝑚𝑚𝑠𝑠 is the mass of your ship and 𝑚𝑚𝑖𝑖 is the mass of the 𝑖𝑖 th black hole. Therefore, the force applied by all of the black holes is given by: 𝐹𝐹=�𝒓𝒓𝑖𝑖𝑚𝑚𝑠𝑠𝑚𝑚𝑖𝑖 |𝒓𝒓𝑖𝑖|3𝑁𝑁 𝑖𝑖=1 Programming Assignment 4 – Runge -Kutta Methods (Matlab)
Name____ Correct result __ / 30 shortest path found __ / 20 longest path found __ / 10 Physics __ / 25 evaluation of force __ / 10 force in differential equations __ / 5 comments and readability __ / 10 Euler Integration __ / 45 correct formulas for velocity __ / 10 correct formulas for position __ / 15 code is correct / robust __ / 10 comments and readability __ / 10
Total __ / 100