I am in Introduction to MATLAB and I dont know how to solve
I am in Introduction to MATLAB and I don\'t know how to solve this problem. Please explain each step legibly on how to program the code. Thanks!
Part II (MATLAB implementation) (a) write and test a MATLAB program that simulates the experiment of rolling two die N times and generates estimates of the following statistics a. The relative probability that the number of spots is equal to (2, 3, 11, 12) b. The percentage difference between the most frequent and the least frequent of the 36 possible outcomes. (b) Run the program with N 31,000, 10,000, 100,000 and 1,000,000 (c) What do you observe about the behavior of the estimated statistics as Nincreases?Solution
clc;
close all;
clear all;
%% Program starts here
N=1000
EXP_DATA=ceil(rand(1,N)*11+1);
max(EXP_DATA);
min(EXP_DATA);
[bins]=hist(EXP_DATA,11);
probability=bins/N
min_pro=min(probability);
max_pro=max(probability);
error_pct=(max_pro-min_pro)*100/max_pro
N=10000
EXP_DATA=ceil(rand(1,N)*11+1);
max(EXP_DATA);
min(EXP_DATA);
[bins]=hist(EXP_DATA,11);
probability=bins/N
min_pro=min(probability);
max_pro=max(probability);
error_pct=(max_pro-min_pro)*100/max_pro
N=100000
EXP_DATA=ceil(rand(1,N)*11+1);
max(EXP_DATA);
min(EXP_DATA);
[bins]=hist(EXP_DATA,11);
probability=bins/N
min_pro=min(probability);
max_pro=max(probability);
error_pct=(max_pro-min_pro)*100/max_pro
N=1000000
EXP_DATA=ceil(rand(1,N)*11+1);
max(EXP_DATA);
min(EXP_DATA);
[bins]=hist(EXP_DATA,11);
probability=bins/N
min_pro=min(probability);
max_pro=max(probability);
error_pct=(max_pro-min_pro)*100/max_pro
OUTPUT:
N =
1000
probability =
Columns 1 through 10
0.0750 0.0920 0.0940 0.1010 0.0810 0.0840 0.1010 0.0910 0.1060 0.0870
Column 11
0.0880
error_pct =
29.2453
N =
10000
probability =
Columns 1 through 10
0.0878 0.0918 0.0891 0.0898 0.0947 0.0905 0.0918 0.0899 0.0876 0.0953
Column 11
0.0917
error_pct =
8.0797
N =
100000
probability =
Columns 1 through 10
0.0911 0.0908 0.0916 0.0908 0.0920 0.0889 0.0908 0.0907 0.0913 0.0926
Column 11
0.0894
error_pct =
3.9317
N =
1000000
probability =
Columns 1 through 10
0.0908 0.0912 0.0913 0.0901 0.0910 0.0912 0.0910 0.0908 0.0910 0.0908
Column 11
0.0909
error_pct =
1.3350
c) Error Decreases as we increase the N value. THis is in accordance with the theory. The ideal values of error percentage for infinite number of sample is 0%.


