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

(a) Write a MATLAB program that rolls a fair 10-sided dice (whose faces go from

ID: 3857882 • Letter: #

Question

(a) Write a MATLAB program that rolls a fair 10-sided dice (whose faces go from 0 to 10) for
some given number of times. In other words, you will pick a number uniformly at random on
from {1, 2, 3, . . . 10} a number of times independently.

(b) Roll the dice 100 times, and meanwhile count the number of times you obtain each face. Write
down the frequency of each face. For example, if you got 13 1s out of the 100 rolls, your result
would be 0.13 for 1. Plot a graph that shows the face in the X-axis vs frequency in the Y-axis.

(c) Repeat (b) for 1000000 (one million) rolls.

(d) What we have done so far can be considered as the use of computer to and an approximation to the PMF of the dice roll. Compare the results you obtained in (b) and (c) with the "actual" PMF of the roll of the 10-sided fair dice. This so-called Monte Carlo method is pretty powerful and can be used to approximate the probabilities of events that are hard to calculate using formal methods.

(d) As another exercise, using one million rolls of the dice, approximate the PMF of X + |X-6|, where X is the random variable that is uniform on {1,2,3 ....10} (Rolls of the 10-sided dice). Compare what you obtain with the exact PMF of X + |X-6|. Plot both the approximate PMF and the actual PMF.

*hint

a) Type x = rand, and hit enter. Nice; the function rand is like a continuous random variable that
is uniformly distributed on [0, 1]. We now need to nd a way to obtain a discrete random variable
out of this continuous random variable.

b) Think about what type of numbers would you get from x = ceil(10*rand). Type help ceil
to the command line to see what ceil does.

Explanation / Answer

Hi,

You can proceed to solve the problem in the following way as I have stated with the example:

function [ X ] = Dice( N, S, T, R ) % Dice simulates a random selection of numbers which is similar to how a % dice is rolled % % N is the number of dice the user wants to roll % S is the number of sides on the dice % T is the number of trials that the user wants to run. % R is the number of rolls that the user wants to roll each dice.

D =ceil(S*rand(1,N))

% I used this for one roll of the dice

Counts = hist(D,[1:S]);

% Then I used this to count how many of each number showed up.

Each slice (on the third dimension) is a trial.

Each column is a dice rolled 3 times.

I hope it will solve your problem.