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

Write a function called dieRoll that takes a single argument, an integer (>0) nu

ID: 3800005 • Letter: W

Question

Write a function called dieRoll that takes a single argument, an integer (>0) number of times to roll a die. The function uses randi to randomly generate integers representing that many rolls of a 6-sided die. The function should then calculate the average of all the rolls, and calculate the absolute value of the difference between that average and the expected average of 3.5. The function returns the absolute value of the difference (also called the random trial error) Create a test table and write a function to solve the problem. Design will be done in lecture or lab.

Explanation / Answer

Code:

function diff=roll(i)
for n=1:1:i
    x(n)=randi(6);
end

s=sum(x)/i;
diff=abs(s-3.5);
end

Example:

>> roll(6)

ans =

    0.6667

>> roll(10)

ans =

    0.5000

>> roll(100)

ans =

    0.0300

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