Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Instructions

This is the online MATLAB coursework assignment for the LI Engineering Mathematics 2 Module.It will be submitted and marked using MATLAB Grader. The problem is described fully below. You should write your MATLAB script offline and run it in MATLAB to ensure the program does as you expect.

Once you are happy with your solution you can copy and paste your entire script into the "Script" window. From here you can select "Run script" to ensure the script still runs as expected (any output will be shown).

Once you are happy with your program select "Submit" to submit your script for marking.

You may make multiple submissions. After each submission you will be able to see what you have got right and wrong and be able to change your script appropriately.

IMPORTANT

The variable names you use must be exactly the same as you are told in the question. MATLAB grader will check the content of your variables against the correct answer. An incorrect variable name will result in 0 marks  scored. Please check, carefully, that they match. The varibale names in the question are highlighted in bold.

The Problem

You have been asked to analyse a short format version of the board game "Snakes and Ladders". The makers of the game want to know on average how many dice rolls are required for a single player to complete the game. You will need to use your knowledge of Markov models to answer this question.

As this is a short format of the "Snakes and Ladders" game, the board is only 4 by 3 and the rules are slightly different. The board and the rules for the game are described below:

Snakes and Ladders Rules:

1. Aplayer starts on the "Start Square" and aims to get to the "End Square".

2. To move, a player rolls an unbiased 3 sided dice (ie., the outcomes from the dice are either 1, 2 or 3 with equal probability) and moves the number of squares shown on the dice.

3. If the player lands on the head of a snake, then the player travels down the snake to the square indicateed by the snake's tail. This move happens instantaneously so that the player starts their next go on the square indicated by the snake's tail.

4. If the player lands on the foot of a ladder, then the player travels up the ladder to the square indicated by the top of the ladder. This move happens instantaneously so that the player starts their next go on the square indicated by the top of the ladder.

5. To end the game, the player needs to rollthe number equivalent to the number of squares to reach the end else they remain on their current square. For example, if a player is 2 squares from the end, then they need to roll a 2 to end. If they roll a 1 or 3, they remain on their current square. This rule only applies when the player is 3 squares or less from the end square.

Pretest:

Set the probability, pdice, of rolling any one of the three numbers with the 3 sided dice to 1/3.

Q1) Create a new variable "P" that defines the probability of being in each state at the start of the game. (1 mark)

Create a variable P which contains the probability of being in each state at the start of the game when no dice has been rolled. You are free to choose if P is a column or row vector.

Q2) Create the transition matrix "A" for this game of Snakes and Ladders. (5 marks)

Create a variable A that represents the transition matrix for your Markov model. Each entry in A, denoted aij, represents the probability of transitioning from statei to state j after the dice has been rolled. Note the hints below to help you with this task.

Q3) Determine the minimum number of dice rolls need to complete the game and compute the probability of rolling this sequence of dice rolls. (2 mark)

Create a variable Dmin which contains the minimum number of dice rolls needed to complete the game and create a variable Pmin which contains the probability of completing the game using Dmin rolls of the dice.

Q4)Determine the expected number of dice rolls needed to complete the game with a probability higher than 95%. (1 mark)

Create a variable Daverage which contains the expected number of rolls of the dice needed to complete the Snakes and Ladders game with a probability higher than 95%.

Q5)Plot the probability of being in the "End Square" as the number of dice rolls increases from 0 to 50. (1 mark)

Your plot should have labels for both axes.

Hint:

1. Create/draw the transition state diagram for the game. Should all of the squares on the game board be states in your Markov model?

2. If you choose P to be a column vector then from the lectures you have Pk=ATpk-¹for the kth dice roll. If you choose P to be a row vector then from the matlab tutorials you have Pk=p-¹A for the kth dice roll. Both approaches will work but make sure you are consistent once you have chosen one.