Subject | Computer |
Due By (Pacific Time) | 12/12/2016 10:59 pm |
Part A
An explorer is trapped inside a circularly shaped forest with quicksand at its center (Fig 1). The trails in the forest go either in the radial or in the angular direction creating a maze as shown in the figure where each crossing is represented as a grid point. There are 11 grid points on a radial line denoted consecutively by numbers 0 to 10, whereas there are 12 points on each circle identified by numbers 1 to 12. Hence, every grid position is defined by a 2-dimensional row vector [i j], where the integer i (between 0 and 10) indicates the radial location, and the integer j (between 1 and 12) shows the angular orientation.
Fig 1: Forest grid
If positioned at a certain grid point, the explorer chooses his next position randomly by rolling a 4-faced dice. If he
rolls a 1 he decides to move radially inward (towards the center), rolls a 2 he decides to move radially outward (away from the center), rolls a 3 he decides to move clockwise,
rolls a 4 he decides to move anti-clockwise.
This means that if the present position is [3 5], the explorer can go to one of the following: [2 5] (with a 1 on the dice)
[4 5] (with a 2 on the dice)
[3 4] (with a 3 on the dice)
[3 6] (with a 4 on the dice)
pg 3/7
Part A, continued
Similarly, if the present location is [6 1], the next step will bring him to either of the following: [5 1] (with a 1 on the dice)
[7 1] (with a 2 on the dice)
[6 12] (with a 3 on the dice)
[6 2] (with a 4 on the dice)
Write a MATLAB function Survival that randomly generates moves until the explorer either escapes from the forest by reaching the radial position 10 or dies after falling in the quicksand by reaching the radial location 0. Provide a starting position (i, j) as the input to the program. The output will be a matrix containing the explorer’s position in all the subsequent steps until the explorer escapes or dies.
Examples of input and output are given below. >> Survival([1 7]) ans =
17 27 28 38 28 18 08
>> Survival([8 1]) ans =
81 8 12 81 82 81 91 9 12 91 10 1
Input Restrictions & special cases:
The function should halt and return a red error message for the following conditions. • The input is not a 1x2 array
• Any element of the input is not a legal grid position.
This means that the radial position index must be an integer between 1 and 9, inclusive and the angular position index must be an integer between 1 and 12.
DO NOT use the break command
This is an example when the explorer ultimately escapes. The first move is clockwise angular motion from (8, 1) to (8, 12). Ultimately, he escapes by landing on (10, 1)
ME 2115 Fall 2016 Final Project, due December 12, 2016 (11:59PM) pg 4/7
This is an example when the explorer ultimately fell into quicksand. The first move is radially outward from (1, 7) to (2, 7). The second move is an example of anticlockwise angular motion from (2, 7) to (2, 8). The last move is radially inward from (1, 8) to (0, 8) so that he lands in the quicksand.
Part A, continued
Testing & Submission
Submit to Cody for correctness verification, and publish as pdf the sample case with start=[8 1].
Your results will not be identical to the sample above. Upload Survival.m and Survival.pdf to Blackboard
This function will be used in part B
Part B
Write a MATLAB script file SurvivalProbability that uses function Survival (from part A) and runs 1000 independent trials for each of the grid positions (i= 1 to 9) on the radial line 1 (i, 1) as starting position. Determine how many times the explorer escapes and how many times he falls into quicksand for each of the starting positions on the selected line. Present the results to the screen as follows (your results may vary):
Start [1 1], probability of escape=10.00%,probability of death=90.00 % Start [2 1], probability of escape=21.20%,probability of death=78.80 % Start [3 1], probability of escape=30.00%,probability of death=70.00 % Start [4 1], probability of escape=38.20%,probability of death=61.80 % Start [5 1], probability of escape=48.70%,probability of death=51.30 % Start [6 1], probability of escape=61.10%,probability of death=38.90 % Start [7 1], probability of escape=71.00%,probability of death=29.00 % Start [8 1], probability of escape=79.00%,probability of death=21.00 % Start [9 1], probability of escape=89.90%,probability of death=10.10 %
Code Requirements:
• The script file must use the function Survival. No credit will be given if the moves are determined in any other way.
Testing & Submission:
Publish as a pdf.
Upload both SurvivalProbability.m & SurvivalProbability.pdf to Blackboard.
Part C
Now consider a different terrain where half of the outer periphery from [10, 1] to [10, 7] is blocked by mountains (Fig.2). This means that if the explorer reaches this segment he can no longer escape.
Fig. 2: Forest grid with mountain barrier
For these blocked peripheral points, he must choose one of the three available options for the next step by the roll of a three-sided dice.
1) Roll of 1 means he moves radially inward,
2) Roll of 2 means he moves angularly clockwise,
3) Roll of 3 means he moves angularly counter clockwise.
Write a MATLAB function SurvivalMount that randomly generates moves until the explorer either escapes from the forest by reaching the permeable part of the outer periphery given by [10, j ] with j being 8 to 12 or falls in the quicksand by reaching the radial location 0.
Provide a starting position [ i, j ] as the input to the program. The output is a matrix containing the explorer’s position in all the subsequent steps until the explorer escapes or dies. A sample result is shown below:
pg 6/7
Part C continued
>>SurvivalMount([9,6])
ans = 96 10 6 96 95 96 86 87 88 78 88 87 97 10 7 10 8
Input Restrictions & special cases:
The function should halt and return a red error message for the following conditions. • The input is not a
1x2 array
• Any element of the input is not a legal grid position.
This means that if the angular position index is an integer between 1 and 7 (inclusive), then the radial position index can be an integer between 1 and 10 (inclusive). If the angular position index is an integer between 8 and 12( inclusive) then the radial position index must be an integer between 1 and 9 (inclusive). The angular position index must be an integer between 1 and 12.
DO NOT use the break command
Testing & Submission
Submit to Cody for correctness verification, and publish the sample case start=[9 6] as a pdf. Upload SurvivalMount.m and SurvivalMount.pdf to Blackboard.
This function will be used in part D
Cannot escape due to mountains even though radial position index 10 is reached Finally, can escape as the mountain barrier is absent in angular position index 8 Part D
Write a MATLAB function M-file named SurvivalMountProb.m that will take as inputs the starting position and a specified number of trials for survival on the modified terrain of Part C and will generate as outputs the probabilities of escaping and of falling in quicksand.
The inputs are
i) a 1x2 array representing the initial position of the adventurer on the modified forest grid.
ii) Number of trials
The outputs are
i) Chances of survival, in percentage
ii) Chances of dying, in percentage
Write a script file EscapeMountProb that uses this function to plot the probabilities of escape as a function of all possible initial radial positions on two radial lines represented by
[i 4] (with i=1:10)
&
[i 10] (with i=1:9)
on the modified terrain. Use number of trials=1000. Sample plots shown on next page.
Code requirements:
The function M file must use the function SurvivalMount as a subfunction. No credit will be given if
the moves are generated in any other way.
Input Restrictions & special cases:
The function should halt and return a red error message for the following conditions.
The input is not a 1x2 array
Any element of the input is not a legal grid position.
This means that if the angular position index is an integer between 1 and 7 (inclusive), then the radial position index can be an integer between 1 and 10 (inclusive). If the angular position index is an integer between 8 and 12 ( inclusive) then the radial position index must be an integer between 1 and 9 (inclusive). The angular position index must be an integer between 1 and 12.
The error checking on the sub function may be removed.
Tutor | Rating |
---|---|
pallavi |
out of 1971 reviews |
amosmm |
out of 766 reviews |
PhyzKyd |
out of 1164 reviews |
rajdeep77 |
out of 721 reviews |
sctys |
out of 1600 reviews |
sharadgreen |
out of 770 reviews |
topnotcher |
out of 766 reviews |
XXXIAO |
out of 680 reviews |