Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB Some random processes involve more than just two possible (dichotomous) outcomes. One example is rolling a normal die, which can result in integer outcomes

MATLAB

  1. Some random processes involve more than just two possible (dichotomous) outcomes. One example is rolling a normal die, which can result in integer outcomes from 1 to 6. Remember that in MATLAB, we can either use rounding or use the randi function (or randint for some versions of the software) in order to generate random integers. In this particular example, no further comparisons or decision-making are needed to simulate the event.

  1. Write a function roll that simulates the roll of a die, and returns the result as output argument (no input arguments). Call roll from the command line to see the result.

  2. In order to evaluate the relative frequency of the different rolls on the die, it is useful to create a histogram of the outcomes. Write a program that uses a for loop to call the roll function Nrolls times, and stores the result from each roll in a vector variable (so if you simulate 50 rolls, the vector will have 50 elements).

After the loop, plot a histogram of the outcomes. Note that if hist(y) is called with a single vector input argument y, it uses a default value of 10 equally-spaced bins for counting the values of y. One can specify the bins with a second vector input argument. For example, hist(y, 1:6) would use bins centered on 1, 2, , 6 (one for each possibility).

Run your program a number of times with Nrolls = 50. Is it possible to say for certain that all rolls have equal probability? Now set Nrolls = 10000 and run several times. Use the histogram to prove to yourself that you should use the expression on the left below rather than the one on the right to create uniformly distributed random integers:

floor( rand * (high low + 1) + low ) round( rand * (high low) + low )

  1. If a pair of dice are rolled, the outcome of each is independent of the other. This means that a random number must be generated separately for each. Modify your function above to simulate the roll of a pair of dice, and return the total of the two dice as output. Call your function a number of times from the command line and observe the outcomes.

Use the histogram approach above to analyze the relative frequency for the different roll totals (note that there are now 11 possibilities: 2, 3, , 12). Which total is most common when rolling a pair of dice? Which rolls are least common?

  1. A more interesting type of simulation is one in which the program branches, depending upon the outcome of the random events. A classic example of this is the game craps often played in casinos. Although the betting can be quite complicated, the rules of the game are fairly simple for the person rolling the dice (called the shooter). The game is essentially played in two phasesthe come-out phase and the point phase:

Come-out phase: The shooter rolls a pair of dice once, with the following outcomes

2, 3, or 12 = craps; the shooter loses.

7 or 11 = natural; the shooter wins.

Anything else = point; the game advances to the second phase

Point phase: The shooter rolls the pair of dice repeatedly, with the following outcomes

point = value from come-out phase above; the shooter wins.

7 = the shooter loses.

Anything else = the shooter continues rolling.

Write a program that simulates a game of craps. From within the program, call your function roll anytime you need to roll the dice, and store the output in a variable. Your program should output the result of each roll during the game, and also provide the appropriate messages regarding whether the shooter wins, loses, or continues rolling.

You should use a while loop for the point phase of the game. You can use either a switch-case structure or if-elseif structure for the come-out phase.

After debugging your program and getting it to execute successfully, test it a number of times. Does it appear that the shooter wins or loses the majority of the time?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss five types of employee training.

Answered: 1 week ago

Question

Identify the four federally mandated employee benefits.

Answered: 1 week ago