Statistic Matlab Example
Statistic Matlab Example
SUBJECT
ACTIVITY
STUDENT
: ADANG PRIANTO
: 26520338
Tutorial Question
1. X & y is Random Variable
Mean E[X] = mx
E[Y] = my
Covariance = E[(X-mx) (Y-my)
= E[X Y*] mx my
Covariance E [ X Y ] m x m y
CrossCorrelation=
=
Std Dev x , y
x y
2. Bernoulli Random Variable :Trial variable that give exact 2 possible outcome (success
or not success).
3. Probability Distribution Function, is a statistical function that describes all the
possible values and likelihoods that a random variable can take within a given range.
Probability density function (PDF), or density of a continuous random variable, is
a function that describes the relative likelihood for this random variable to take on a
given value.
4. Expectation random variable x = ak
Given P(x = ak)
E[ X ]= a k P ( x=a k )
k
Given fx()
E [ X ] = f x ( ) d
5. Importance of:
Mean Squared value: it measure average power of random variable.
Standard Deviation: it makes a difference whether the distribution is spread out over
a broad range or bunched up closely around the mean.
1
1( x )
1
exp
2
2
Variance
= 2
___________________________________________________________________________
Exercise 1
Step 1 to 6
Syntax
Function Syntax
X=1.*randn(1,1000)+0;
%% Generate R.V. with variance=1, mean=0
plot(X);
title('Plot of Random Variable');
xlabel('x');
ylabel('y');
[Mean_Data,Variance_Data]=mean_var(X);
Step 7
True Mean
=0
True variance = 1
= 0.0383
= 1.0110
Compared to true value of mean and variance, generated value have an error or difference
0.0383 and 0.0110 for mean and variance respectively.
Step 8
Increase sample e.g. up to 100000 sample
m
= -0.0012
0.9956
The difference is much smaller, calculated value of mean and variance is closer to the true
value. Larger sample will give more accurate estimation.
___________________________________________________________________________
Exercise 2
1. Random vector Y with mean = 2 and variance = 4
E[Y] = a E[X] + b
2 = a . (0) + b
b =2
Var (Y)= a2 Var (X) + 0
3
4 = a2 (1)
a =2
2. Matlab calculation of mean and variance
m
= 2.0188
v
= 3.9627
CDFVec=mycdffunc(X,x);
plot(CDFVec)
hold on
title('Cumulative Distribution Function')
X=randn(1,20); %% Sample change for N=20,200,2000
CDFVec=mycdffunc(X,x);
4
plot(CDFVec)
hold on
legend('N=20','N=200','N=2000')
___________________________________________________________________________
Exercise 4
Syntax
Beta=3;
X=rand(1,1000);
Y=(-1/Beta)*log(X);
[Ng,n]=hist(Y,50);
Bin_width=n(3)-n(2);
Pvec=Ng/Bin_width/50;
Tpdf=3.*exp(-3*n);
plot(Pvec,n);
hold on
plot(Tpdf);
title('Transform Uniform to Exponential')
legend('Calculated Py(y)','True Value Py(y)')
Bin
1
2
3
4
5
5
Total
23
20
20
14
22
Bin
11
12
13
14
15
Total
24
18
17
23
28
Bin
21
22
23
24
25
Total
0
1
1
1
0
Bin
31
32
33
34
35
Total
1
0
0
0
1
Bin
41
42
43
44
45
Total
0
0
0
0
0
6
7
8
9
10
25
20
15
21
18
16
17
18
19
20
17
23
27
26
26
26
27
28
29
30
1
0
0
1
1
36
37
38
39
40
0
0
0
0
0
46
47
48
49
50
0
0
0
0
1
Bin_width = 0.0199
_____________________________________________________________________
Exercise 5
sigma_R = 3;
N = 10000;
U = rand(1,N);
R = sqrt(-2*sigma_R*log(U))
[Ng,n] = hist(R,20);
size(Ng)
p_hist=Ng/10000/(n(3)-n(2));
size(p_hist)
plot(n,p_hist);
Ray_pdf = (n/sigma_R).*exp(-n.^2/2/sigma_R);
hold on
plot(n,Ray_pdf,'r')
title('Uniform to Rayleigh Transform')
legend('Calculated PDF','True PDF')