Using Matlab Suppose you are a board game maker and you want
Using Matlab:
Suppose you are a board game maker, and you want to give players a higher probability of rolling larger numbers. Originally you had them roll three six-sided dice and add their results. The new approach will have the player roll four dice and add the totals of the three highest valued dice. Write a program that performs multiple die rolls using a random number generator. Each die must be assigned an integer value between 1 and 6 inclusive, with uniform probability for each value. For each simulated roll, find the total of the three highest valued dice. Keep a count of the number of times each outcome occurs. Plot a histogram of the totals when the number of iteration is 10,000 Plot a histogram of the totals when the number of iteration is 1,000 Plot a histogram of the totals when the number of iteration is 300 Include your code in 12 point Courier New font.Solution
We define a rollDice funtion as follows:
file: rollDice.m
function sum = rollDice()
% Create a 1x4 matrix with random integer from 1 to 6
a = randi(6,1,4);
% Sort the matrix
b = sort(a);
% Remove the smallest element from matrix
b(:,1) = [];
%Find sum of elements
sum = sum(b);
end;
Now we will create the histogram using from the count obtained from the above method. This can be done from command promt self as:
A) For 10000 iterations:
>> count = zeros(18,1);
>> for k = 1:10000
count(rollDice())++;
end;
>> bar(count);
B) For 1000 iterations:
>> count = zeros(18,1);
>> for k = 1:1000
count(rollDice())++;
end;
>> bar(count);
C) For 300 iterations:
>> count = zeros(18,1);
>> for k = 1:300
count(rollDice())++;
end;
>> bar(count);
