| |

Question: It is often useful to be able to simulate the throw of a fair die. Write a MATLAB function, dice.m, that simulates the throw of a fair die by returning some random integer between 1 and 6 every time that it is called. (Hint: Call rand to generate a random number. Divide the possible values out of rand into six equal intervals and return the number of the interval that a given random value falls into.) Write a script, test_dice.m, that simulates 10,000 times with drawing a histogram figure and displays the first 30 values in the dice. The histogram must have title, x-label, and y-label. Show the function dice.m, the script test_dice.m, and the testing result and figure – Free Chegg Question Answer

It is often useful to be able to simulate the throw of a fair die. Write a MATLAB function, dice.m, that simulates the throw of a fair die by returning some random integer between 1 and 6 every time that it is called. (Hint: Call rand to generate a random number. Divide the possible values out of rand into six equal intervals and return the number of the interval that a given random value falls into.) Write a script, test_dice.m, that simulates 10,000 times with drawing a histogram figure and displays the first 30 values in the dice. The histogram must have title, x-label, and y-label. Show the function dice.m, the script test_dice.m, and the testing result and figure

Transcribed text From Image: 

Expert Chegg Question Answer:

free chegg question answer
Smart Teacher From Answerie.com
Answer:

Answer


File: dice.m

function rval dice() rval randi ( [ 1 6] ) ; 3- end

File: test_dice.m


———————————————–

Sample Output:

Fiqure 1 1回 File Edit View Insert Tools Desktop Window Help 200 180 160 140 120 100 80 40 20 4
>> test_dice ans -


———————————————–

CODE TO COPY:

% dice.m
function rval = dice()
    rval = randi([1 6]);
end

———————————————–

% test_dice.m

function getDiceArray()
    arr = 0;
    x = 1:1:6;
  
    for j = 1:1000
        arr(j) = dice();
    end
  
    arr(1:30)
  
    hist(arr, x);
end


Free Chegg Question Answer

Leave a Reply

Your email address will not be published. Required fields are marked *