Please type it in MatLab or on a computer if possible. Thank you so much Questio
ID: 3884233 • Letter: P
Question
Please type it in MatLab or on a computer if possible. Thank you so much Question 1 (10 Points) When a fair die is rolled, the number uppermost is equally likely to be any integer between 1 and 6. MATLAB randi fúnction generates uniformly distributed pseudorandom integers. Use this documented MATLAB program (dietoss.m) to simulate a fair die roll of N- 10, 100, 1000 and 10,000 times For each trial, count the number of stxes thrown by constructing a logical vector and counting the number of times 6 appears. Use MATLAB's vectorizing commands for logical operators in your solution. Estimate the probability of throwing a stx by dividing the number of sixes by 10, 100, 1000 and 10,000 respectiyely. Compare each to the theoretical expected value of 1/6.
Explanation / Answer
%% MATLAB Code for die toss simulation
clc;
clear all;
close;
%% Program starts here
p=1;
probability_6=zeros(1,4);
for N=[10 100 1000 10000];
DATA=randi(6,N);
count=0;
for i=1:N
if DATA(i)==6
count=count+1;
end
end
probability_6(p)=count/N;
p=p+1;
end
disp('The theoretical probability is 1/6 i.e 0.16667')
disp(' The Simulated Values of probability for diff number of Samples is :')
disp(' N=10 N=100 N=1000 N=10000');
disp(probability_6)
OUTPUT:
The theoretical probability is 1/6 i.e 0.16667
The Simulated Values of probability for diff number of Samples is :
N=10 N=100 N=1000 N=10000
0.2000 0.1600 0.1740 0.1749