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

Write a MATLAB script that will simulate the rolling of a single six-sided die 1

ID: 3776406 • Letter: W

Question

Write a MATLAB script that will simulate the rolling of a single six-sided die 100 times and store it in a onedimensional array. Think of this as having each roll of the die corresponding to an event whose result is recorded at index j. This can be achieved by calling randi() with appropriate parameters (check the help doc). Use the histogram() function to create a histogram of the results. Specify your number of bins appropriately (default is 10).

Part B (optional):

Modify your MATLAB script to simulate rolling a set of three six-sided dice 100 times. Hint: In Part A you generated an array (vector) of events for a single die. In MATLAB, how would you combine the events of the three dice together without using loops?

Explanation / Answer

% generate random numbers between 1 and 6, with 1 row and 100 columns
X = randi(6,1,100);

% histcounts of binsize 10.
[N,edges] = histcounts(X,10);
disp(N);
disp(edges);

% generate random numbers between 1 and 6, with 3 rows and 100 columns, each row corresponds to a die.
Y = randi(6,3,100);
disp(Y);

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