-
Notifications
You must be signed in to change notification settings - Fork 0
/
LawofLargeNumbers.m
89 lines (69 loc) · 2.08 KB
/
LawofLargeNumbers.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
%%SET 2
%(a) The law of large numbers states that with more realizations and a
%bigger sample size, we are able to generate an average that is closer to
%the expected value. So with N = 1000, we are able to approximate the
%distribution with a Gaussian pdf. Also note the mean of this Gaussian curve is
%sqrt(pi/2), which is mean of Rayleigh random variable. So sample mean equals distribution mean.
sigma_squared = 1;
N = 100;
U= rand(N,1000);
R = sqrt(-2*(sigma_squared)*log(U));
X = mean(R); % X is Mn = Sn/N = (X1 + X2 +...X100)/100
hist(X)
xlabel('Value'); ylabel('Count');
title('PDF of X with N = 100')
%(b) With N = 10000, the sample size is even larger. We see that the curve is an even better approximate of a gaussian curve.
sigma_squared = 1;
N = 10000;
U= rand(N,1000);
R = sqrt(-2*(sigma_squared)*log(U));
X = mean(R); % X is Mn = Sn/N = (X1 + X2 +...X1000)/1000
figure
hist(X)
xlabel('Value'); ylabel('Count');
title('PDF of X with N = 10000')
%(c) With a sample space of 1000 samples of Y, we start to approach a Gaussian
%Distribution.
lambda = 1;
N = 100;
X = rand(N,1000);
E = -log(X)*lambda;
Y = mean(E);
figure
hist(Y)
xlabel('Value'); ylabel('Count');
title('PDF of Y with N = 100')
%(d) With a samples space of 10000 samples of Y, we get a better Gaussian
%approximation of the pdf.
lambda = 1;
N = 10000;
X = rand(N,1000);
E = -log(X)*lambda;
Y = mean(E);
figure
hist(Y)
xlabel('Value'); ylabel('Count');
title('PDF of Y with N = 10000')
%(e)The sample mean that is calculated is E{Z} = E{X/Y} = sqrt(pi/2) = 1.253. We
%get a better approximation of our mean with greater N values. With N =
%100, we have 1.2420 and with N = 10000, we have 1.2527.
N = 100;
U= rand(N,1000);
R = sqrt(-2*(1)*log(U));
X = sum(R); % X is Sn = (X1 + X2 +...X100)/100
N = 100;
U = rand(N,1000);
E = -log(U)*(1);
Y = sum(E);
Z= X/Y;
mean(Z)
N = 10000;
U= rand(N,1000);
R = sqrt(-2*(1)*log(U));
X = sum(R); % X is Sn = (X1 + X2 +...X100)/100
N = 10000;
U = rand(N,1000);
E = -log(U)*(1);
Y = sum(E);
Z= X/Y;
mean(Z)