Write a function called dieRoll that takes a single argument
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.
Solution
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
