Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Now consider a different terrain where ha lf of the outer periphery from [ 10, 1

ID: 3577655 • Letter: N

Question

Now consider a different terrain where ha lf of the outer periphery from [ 10, 1] to [10, 7] is blocked by mountain s (Fig.2). This means that if the explorer reaches this segment he can no longer escape. 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 o f the outer periphery given by [ 10, j ] wit h 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 e xplorer escapes or dies. A sample result is shown below: Mountain barr

>>SurvivalMount([9,6])

ans =

9 6

10 6

9 6

9 5

9 6

8 6

8 7

8 8

7 8

8 8

8 7

9 7

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

[10, 91 [10, 10] [10, 11] [10, 81 [10, 12] [10, 7] [10, 1] [10, 6] [10, 2] [10, 5] [10, 4] [10, 3]

Explanation / Answer

function ret = SurvivalMount(arr)
   x = arr(1);
   y = arr(2);
   i = 0;
   while true
       i += 1;
       ret(i, 1) = x;
       ret(i, 2) = y;
       choice = randi([1 4], 1, 1);
        if choice == 1
            x -= 1;
        elseif choice == 2
            x += 1;
        elseif choice == 3
            y -= 1;
            if y < 1
                y += 12;
            end                  
        elseif choice == 4
            y += 1;
            if y > 12
                y -= 12;
            end
        end
       while x >= 10
           i += 1;
            ret(i, 1) = x;
            ret(i, 2) = y;
           if y >= 8 && y <= 12
               break;   % got out
           else
               choice = randi([1 3], 1, 1);
               if choice == 1
                   x -= 1;
               elseif choice == 2
                   y -= 1;
               elseif choice == 3
                   y += 1;
               end
           end
       end
       if x == 0
           i += 1;
            ret(i, 1) = x;
            ret(i, 2) = y;
           break;   % got out
       end
   end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote