首页 >
> 详细

HW 3- The Odds of Successfully Navigating an

Asteroid Field are Approximately 3,720 to 1!

ENGR 3H

Due 11:59 PM, Wednesday, May 2

1 Never Tell Me the Odds (50 Points)

This week, we are going to use recursion to find a safe path through a treacherous asteroid field! Download from Gauchospace the files mf.png, asteroids.mat, and animate system.m.

The file asteroids.mat contains (in order) the x- and y- coordinates for

the centers of a series of circles and the radii for these circles. These circles will

represent our asteroids. Our ship, the Millennium Falcon, may not look like

much, but she’s got it where it counts–but more importantly for our purposes,

she’ll be represented by a circle as well, with radius .5 and initially at the

coordinates (10, 0).

At each time step, the Millennium Falcon moves 1 space in the y-direction.

It can move either 1 space left, 1 space right, or maintain the same x-coordinate.

So, for example, on the first turn, the Falcon can go from (10, 0) to (9, 1), (10, 1)

or (11, 1). For this assignment, we also require that our ship’s x-coordinate stay

between 0 and 20, that is, 0 ≤ xMF ≤ 20.

If the Falcon overlaps with an asteroid, it crashes. We want to avoid that!

Two circles overlap if the distance between their centers is less than the sum of

their radii. The distance between centers is given by the Pythagorean theorem:

d = q(xMF F xAst)2 + (yMF F yAst)2. (1)

1.1 Making the Kessel Run in 12 Parsecs (30 Points)

To find our way through the asteroid field, we’re going to write a recursive

function called find path.m. The function should take as an input the current

position, the maximum depth of the tree, and the array of asteroid coordinates.

It should return an array of coordinates for the ship’s trajectory and the ycoordinate reached by the ship (for example, if it crashes at y = 9, it should

return 8; if it makes it to the end, it should return the value of the maximum

depth). The function should recursively find the a path that avoids asteroids

up to the maximum depth. The process for this function should look as follows:

1

1. Check if, at the current coordinates, the ship has hit an asteroid. If it has,

return the current coordinates and a value of yMF F 1.

2. If the ship has not crashed, check if the maximum depth has been reached.

If it has, return the current coordinates and a value of yMF .

3. If neither of the first two conditions are met, find the path that results

from moving left in the next step, moving right, and moving in neither

direction. The function should return the value of whichever path had

the greatest value (calculated recursively) and an array of the current

coordinates followed by the coordinates of each step in the highest-value

path.

Remember: if we are at one of the boundaries (0 or 20), our options are

limited and we cannot go left or right, respectively.

1.2 It’ll Take a Few Moments to Get the Coordinates from

the Navicomputer (15 Points)

We want to get our ship to make it safely to y = 20. Write a script that

implements your recursive function to find the best path, with a maximum depth

of 20. Then, use that path to animate the system using animate system.m,

which takes as inputs the coordinates at each time step for the Falcon and the

array of asteroid coordinates. Your script should be self-contained–the matrix

containing the asteroid coordinates should be loaded within the script. Also,

create a global counter variable in the script, initialized to zero. Run the script

using run and time, and note how many times your recursive function is called.

How does it compare to the maximum number of times it could be called given

the maximum depth? Please note that this will take a little bit of time–on my

laptop, it took just over 6 minutes. I recommend trying a smaller maximum

depth first to verify everything is working as intended.

Hopefully you got through the asteroid field, but there’s no way we’d have

six minutes to calculate the correct coordinates! Let’s modify our script now:

at each time step, we compute the next 10 steps with the best value, rather

than the full 20. That means we’re going to compute the next 10 steps 20 times

instead of the full 20 steps once.

As before, calculate the maximum number of possible paths and compare

to the number of times your function was actually called according to run and

time. As you can see, we significantly reduced the number of time it took to

calculate the route. Be warned, we can’t guarantee we find success with fewer

paths considered!

1.3 The Weekly Challenge- I’ve Made a Lot of Special

Modifications, Myself (5 Points)

The goal of this week’s weekly challenge is to successfully reach a distance of

50 units starting from a different starting point with the fewest evaluations of

2

your recursive function. You essentially have two variables you can adjust:

1. The depth find path.m goes to;

2. How many steps the ship moves before calculating a new best path.

Your script should be written with these two variables able to be readily rede-

fined (that is, they should be declared at the beginning of the script, and any

time they’re required later on, these variables are referenced). For the weekly

challenge, submit your values for these two variables; the person who makes it

to the end in the fewest calculations (or, if no one makes it, the person who

made it the farthest in the fewest) wins!

联系我们

- QQ：99515681
- 邮箱：99515681@qq.com
- 工作时间：8:00-23:00
- 微信：codinghelp

- Comp 3005作业代写、代写c++语言作业、代做database作业、C 2020-02-16
- Beng0019作业代做、代写java编程设计作业、代做c/C++，Pyth 2020-02-16
- Ug3 Operating Systems 2020-02-16
- Homework 1 Use Marching Cubes Algori... 2020-02-16
- Module Ics-33 Quiz #2: File Reading, E... 2020-02-16
- S&As: Stat1603 Introductory Statistics 2020-02-16
- Fit5145 - Introduction To Data Scienc... 2020-02-16
- Stat 440作业代写、R编程设计作业调试、代做data课程作业、代写r语 2020-02-15
- 代写mpi Programming作业、Python编程语言作业调试、Pyt 2020-02-15
- Pricing Analytics作业代写、代做r课程设计作业、代写r程序语 2020-02-14
- 代写pol 850作业、代做r编程语言作业、代写script留学生作业、代写 2020-02-14
- 06-30175作业代做、Data Structures作业代做、代写jav 2020-02-14
- Csci 3151作业代做、代写data留学生作业、Python语言作业代写 2020-02-14
- Ec451 Ch4作业代做、代做r编程设计作业、代写data留学生作业、代做 2020-02-13
- 代做programming作业、C++程序语言作业调试、C++课程设计作业代 2020-02-13
- 代写csci 3136作业、代做c++编程语言作业、代写programmin 2020-02-13
- Stat 440课程作业代做、代写r Code作业、代写bootstrap作 2020-02-12
- 代做mthe/Stat 353作业、代写r语言作业、Matlab程序语言作业 2020-02-12
- 代做cmsc 498作业、代写deep Learning作业、Python, 2020-02-12
- 代写stat 445作业、代做matlab程序语言作业、Matlab,Pyt 2020-02-12