Question

In: Computer Science

1. Write a function named ”ThreeDicesAdd” to perform the following ”experiment” 1000 times: roll 3 six-sided...

1. Write a function named ”ThreeDicesAdd” to perform the following ”experiment” 1000 times: roll 3
six-sided dice and add their values. Put the outcomes in a list called addDiceList. So addDiceList should
have length 1000, and each of the 1000 elements should be an integer from 3 to 18. Plot the histogram of
the outcomes.
2. For the same experiment as in question 1, write a function named ”ThreeDicesAdd2” to increase the
experiment times (N) and see how the histogram of the outcomes changes. For each N, you will have one
histogram plot. Output all plots as a GIF file. (Choose N= 1000 : 10,000 : 1,000,000). matlab question

Solutions

Expert Solution

I have coded the following problem in MATLAB that solves the above problem. I have coded the two functions ThreeDicesAdd and ThreeDicesAdd2 and also attached the required histograms.

ThreeDicesAdd screenshot

ThreeDicesAdd code to copy

function addDiceList = ThreeDicesAdd()
    % Initializing an one-dimensional array with size 1000 
    addDiceList = zeros(1, 1000);
    for n = 1:1000
        % The first throw of the dice
        firstThrow = randi([1, 6]);
        % The second throw of the dice
        secondThrow = randi([1, 6]);
        % The third throw of the dice
        thirdThrow = randi([1, 6]);
        % The total of all the throws
        total = firstThrow + secondThrow + thirdThrow;
        % We add that throw to the list.
        addDiceList(n) = total;
    end
end

ThreeDicesAdd2 screenshot

ThreeDicesAdd2 code to copy

function addDiceList = ThreeDicesAdd2(N)
    % Initializing an one-dimensional array with size 1000 
    addDiceList = zeros(1, N);
    for n = 1:N
        % The first throw of the dice
        firstThrow = randi([1, 6]);
        % The second throw of the dice
        secondThrow = randi([1, 6]);
        % The third throw of the dice
        thirdThrow = randi([1, 6]);
        % The total of all the throws
        total = firstThrow + secondThrow + thirdThrow;
        % We add that throw to the list.
        addDiceList(n) = total;
    end
end

Driver code screenshot

Driver code to copy

res = ThreeDicesAdd(1000);
h = histogram(res);

Histograms:

  • N = 1000

  • N = 10000

  • N = 1000000


Related Solutions

You roll a six- sided die. Find the probability of each of the following scenarios a....
You roll a six- sided die. Find the probability of each of the following scenarios a. Rolling a 6 or a number greater than 3 b. Rolling a number less than 5 or an even number c. Rolling a 2 or an odd number
PROJECT C Roll a 6-sided die 800 times. If you do not desire to roll a...
PROJECT C Roll a 6-sided die 800 times. If you do not desire to roll a die manually, STATDISK can be used to simulate the process. To use STATDISK, go to “Data” at the top of the STATDISK window, and then choose “Dice Generator”. The “Dice Roll Random Sample Generator” window will appear. Then in that window, put 800 in for “Sample Size”, put 1 in for “Num Dice”, and put 6 in for “Num Sides”. Please disregard the “Random...
Suppose that you are offered the following "deal." You roll a six sided die. If you...
Suppose that you are offered the following "deal." You roll a six sided die. If you roll a 6, you win $15. If you roll a 3, 4 or 5, you win $1. Otherwise, you pay $4. a. Complete the PDF Table. List the X values, where X is the profit, from smallest to largest. Round to 4 decimal places where appropriate. Probability Distribution Table X P(X) b. Find the expected profit. $ ____ (Round to the nearest cent) c....
1) Imagine you roll a fair 4 sided dice 4 times. what is the number of...
1) Imagine you roll a fair 4 sided dice 4 times. what is the number of possible outcomes as a sum of successes? 2) What is the probability you will roll 3 successes, if the result of a 4 is considered a success? 3) what is the probability you will roll 3 or 4 successes, of the results of a 4 is considered a success? 4) what is the probability you will roll 3 or 4 successes. of the result...
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions....
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions. 1. P(sum=2) 2. P(sum is less than or equal to 4) 3. P(sum=13) 4. P(product)= 20 (Product means multiply) 5. P(product less than or equal to 12)
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions....
You roll TWO six-sided die. Find the probability of each of the following scenarios in fractions. 1. P(sum=2) 2. P(sum is less than or equal to 4) 3. P(sum=13) 4. P(product)= 20 (Product means multiply) 5. P(product less than or equal to 12)
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2...
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2 or 3 b) 6 and 4 c) At least one 5 d) Two of the same number (two 1s, or two 2s, or two 3s, etc.) e) An even number on both dice f) An even number on at least one die
An experiment consists of rolling six-sided dice twice.                                  &
An experiment consists of rolling six-sided dice twice.                                      (10) List the sample space for this experiment. Find the probability distribution for this experiment where x represents the number of even numbers in the 2 rolls. Find the mean of the probability distribution. Find the standard deviation of the probability distribution. Would it be unusual to get 2 even numbers? Why or why not? (show your work)
Write a function named timesOfLetter that reads an array and returns the number of times of...
Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase letter and each uppercase letter appear in it, using reference parameter. • Write a function named timesOfNumber that reads an array and returns the number of times of each odd number, and each even number appear in it, using reference parameter. • Write a function named isChar() that determines if the input is alphabetic or not during inputting. • Write a function...
17#13 Suppose we roll a fair six-sided die and sum the values obtained on each roll,...
17#13 Suppose we roll a fair six-sided die and sum the values obtained on each roll, stopping once our sum exceeds 289. Approximate the probability that at least 76 rolls are needed to get this sum.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT