You are on page 1of 10

Problem-2

(B)
MATLAB Code:
clear all;
clc;
close all;
% Ask user for a number of random numbers to generate.
userPrompt = 'Enter an integer number of random numbers to generate';
caNumberOfRandoms = inputdlg(userPrompt, 'Enter an integer',1, {'100000'});
numberOfRandoms = str2num(cell2mat(caNumberOfRandoms));
%Plot Empirical CDF
k=asin(2*rand(1,numberOfRandoms)-1);
cdfplot(k);
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-2

-1.5

-1

-0.5

0
x

0.5

1.5

(D)
MATLAB Code:
clear all;
clc;
close all;
k=cell(1000,1);
sample_mean=[];
case_number=1;
N=1;
iteration=1000;
z=1;

%
%
%
%

one of 6 specified cases


Number of random variables
1000 iteration for each N
Figure number

%Here, the expected value is zero, so diatance between that and sample mean
would be
%sample mean itself
for case_number=1:1:6
for iteration=1:1000
if case_number == 1
N=1;
elseif case_number ==2
N=10;
elseif case_number ==3
N=100;
elseif case_number ==4
N=1000;
elseif case_number ==5
N=10000;
else
N=100000;
end
k{iteration,1}=asin(2*rand(1,N)-1);
sample_mean(1,iteration)=mean(k{iteration,1});
figure(z);
end
cdfplot(sample_mean);
%cdfplot for each of 6 case
z=z+1;
end

The figures for each case have been plotted in the next pages.

Case: 1: N=1
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-2

-1.5

-1

-0.5

0
x

0.5

1.5

0.2

0.4

0.6

0.8

Case: 2: N=10
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-0.8

-0.6

-0.4

-0.2

0
x

Case: 3: N=100
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-0.25

-0.2

-0.15

-0.1

-0.05

0
x

0.05

0.1

0.15

0.2

0.25

Case: 4: N=1000
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-0.08

-0.06

-0.04

-0.02

0
x

0.02

0.04

0.06

0.08

Case: 5: N=10000
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-0.025 -0.02 -0.015 -0.01 -0.005

0
x

0.005

0.01

0.015

0.02

0.025

Case: 6: N=100000
Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-8

-6

-4

-2

0
x

8
-3

x 10

(E)
MATLAB Code:
clear all;
clc;
close all;
% Ask user for a number of sets of random numbers to generate
userPrompt_one = 'Enter an integer number of sets of random numbers';
caSets = inputdlg(userPrompt_one, 'Enter an integer',1, {'100000'});
K = str2num(cell2mat(caSets));
% Ask user for a number of random numbers to generate.
userPrompt_two = 'Enter an integer number of random numbers to generate';
caNumberOfRandoms = inputdlg(userPrompt_two, 'Enter an integer',1,
{'100000'});
L = str2num(cell2mat(caNumberOfRandoms));
k=cell(K,1);
sample_mean=[];
%Here, the expected value is zero, so diatance between that and sample mean
would be
%sample mean itself
for iteration=1:K
k{iteration,1}=asin(2*rand(1,L)-1);
sample_mean(1,iteration)=(sum(k{iteration,1}))/sqrt(L);
end
figure(1);
cdfplot(sample_mean);
figure(2);
hist(sample_mean);

Figures of HISTIGRAM and CDF for three different values of L and K have
been given on the next pages.

1)L=10000, K=1000;
250

200

150

100

50

0
-2.5

-2

-1.5

-1

-0.5

0.5

1.5

2.5

Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-3

-2

-1

0
x

2) L=1000, K =1000
250

200

150

100

50

0
-2

-1.5

-1

-0.5

0.5

1.5

2.5

1.5

2.5

Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-2

-1.5

-1

-0.5

0.5
x

3) L = 100, K = 100
9
8
7
6
5
4
3
2
1
0
-1.5

-1

-0.5

0.5

1.5

0.5

1.5

Empirical CDF
1
0.9
0.8
0.7

F(x)

0.6
0.5
0.4
0.3
0.2
0.1
0
-1.5

-1

-0.5

0
x

Thus we can conclude that, for large values of L and K, the


distribution approaches Normal Distribution.