-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRayleigh_Distribution.m
177 lines (135 loc) · 4.29 KB
/
Rayleigh_Distribution.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
%{
%%SET 1
sigma_squared = 1; %Scale parameter
N = 1000;
nbins = 100;
%1(b):
R = sqrt(-2*(sigma_squared)*log(1- rand(N,1)));
figure
hist(R, nbins);
xlabel('Value'); ylabel('Count');
title('Rayleigh distribution with sigmasquared of 1')
sample_mean = 0;
for k = 1:length(R)
sample_mean = sample_mean + (R(k)/length(R));
end
disp(['N = 1000, Sigma^2 = 1, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(R) - 1
sample_var = sample_var + (((R(k) - sample_mean))^2 )/ (length(R) - 1);
end
disp(['N = 1000, Sigma^2 = 1, Sample variance: ', num2str(sample_var)]);
%1(c)
sigma_squared = 0.5;
R = sqrt(-2*(sigma_squared)*log(1- rand(N,1)));
figure
hist(R, nbins);
xlabel('Value'); ylabel('Count');
title('Rayleigh distribution with sigmasquared of 0.5')
sample_mean = 0;
for k = 1:length(R)
sample_mean = sample_mean + (R(k)/length(R));
end
disp(['N = 1000, Sigma^2 = 0.5, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(R) - 1
sample_var = sample_var + (((R(k) - sample_mean))^2 )/ (length(R) - 1);
end
disp(['N = 1000, Sigma^2 = 0.5, Sample variance: ', num2str(sample_var)]);
sigma_squared = 5;
R = sqrt(-2*(sigma_squared)*log(1- rand(N,1)));
figure
hist(R, nbins);
xlabel('Value'); ylabel('Count');
title('Rayleigh distribution with sigmasquared of 5')
sample_mean = 0;
for k = 1:length(R)
sample_mean = sample_mean + (R(k)/length(R));
end
disp(['N = 1000, Sigma^2 = 5, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(R) - 1
sample_var = sample_var + (((R(k) - sample_mean))^2 )/ (length(R) - 1);
end
disp(['N = 1000, Sigma^2 = 5, Sample variance: ', num2str(sample_var)]);
sigma_squared = 10;
R = sqrt(-2*(sigma_squared)*log(1- rand(N,1)));
figure
hist(R, nbins);
xlabel('Value'); ylabel('Count');
title('Rayleigh distribution with sigmasquared of 10')
sample_mean = 0;
for k = 1:length(R)
sample_mean = sample_mean + (R(k)/length(R));
end
disp(['N = 1000, Sigma^2 = 10, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(R) - 1
sample_var = sample_var + (((R(k) - sample_mean))^2 )/ (length(R) - 1);
end
disp(['N = 1000, Sigma^2 = 10, Sample variance: ', num2str(sample_var)]);
%1(d) As sigma_squared increases, the tail of the Rayleigh Distribution
%becomes longer and it becomes more flat at the end.
%}
%%SET 2
lambda = 1; %Rate parameter
N = 1000;
nbins = 100;
X = rand(N,1);
E = -log(X)*lambda;
figure
hist(E, nbins);
xlabel('Value'); ylabel('Count');
title('Exponential distribution with lambda of 1')
%2(b)
sample_mean = 0;
for k = 1:length(E)
sample_mean = sample_mean + (E(k)/length(E));
end
disp(['N = 1000, Lambda = 1, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(E) - 1
sample_var = sample_var + (((E(k) - sample_mean))^2 )/ (length(E) - 1);
end
disp(['N = 1000, Lambda = 1, Sample variance: ', num2str(sample_var)]);
%2(c)
lambda = 0.5; %Rate parameter
N = 1000;
nbins = 100;
X = rand(N,1);
E = -log(X)*lambda;
figure
hist(E, nbins);
xlabel('Value'); ylabel('Count');
title('Exponential distribution with lambda of 0.5')
sample_mean = 0;
for k = 1:length(E)
sample_mean = sample_mean + (E(k)/length(E));
end
disp(['N = 1000, Lambda = 0.5, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(E) - 1
sample_var = sample_var + (((E(k) - sample_mean))^2 )/ (length(E) - 1);
end
disp(['N = 1000, Lambda = 0.5, Sample variance: ', num2str(sample_var)]);
lambda = 5; %Rate parameter
N = 1000;
nbins = 100;
X = rand(N,1);
E = -log(X)*lambda;
figure
hist(E, nbins);
xlabel('Value'); ylabel('Count');
title('Exponential distribution with lambda of 5')
sample_mean = 0;
for k = 1:length(E)
sample_mean = sample_mean + (E(k)/length(E));
end
disp(['N = 1000, Lambda = 5, Sample mean: ', num2str(sample_mean)]);
sample_var = 0;
for k = 1:length(E) - 1
sample_var = sample_var + (((E(k) - sample_mean))^2 )/ (length(E) - 1);
end
disp(['N = 1000, Lambda = 5, Sample variance: ', num2str(sample_var)]);
%2(d) As Lambda increases, the tail of the Exponential Distribution
%becomes longer and it becomes more flat at the end.