0% found this document useful (0 votes)
6 views2 pages

Tut 06

The document contains code to generate random numbers and calculate their mean and covariance. It generates random vectors X and Y, calculates their theoretical and empirical covariance, and shows that cov(aX+b,X) = a*cov(X,X).

Uploaded by

Anuj Said
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Tut 06

The document contains code to generate random numbers and calculate their mean and covariance. It generates random vectors X and Y, calculates their theoretical and empirical covariance, and shows that cov(aX+b,X) = a*cov(X,X).

Uploaded by

Anuj Said
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

(a)

N=10000;
x=rand(N,1);
F=zeros(N,1);
% F(Y|X)=e^(x)*(e^(-x)-e^(-y))
for i=1:N
F(i)=2-log(1-x(i));
end
mean(F)

ans = 3.0029

%Numerically and theoretically we optimal predictor of Y|X=2 is 3.


%We did this by through MMSE predictor Linear Predictor

(b) 1

a=2

a = 2

b=3;
X = randn(N,1);
Y = randn(N,1);
% As cov(X,Y) = E(XY) - E(X)E(Y)
Z=X.*Y

Z = 10000×1
0.0768
-0.0004
-2.0947
-0.5937
-0.3483
-0.2673
0.1809
-0.0157
-0.0441
-0.0034

cov_th_matrix=zeros(2,2);
cov_th_matrix(1,2)=mean(Z)-mean(X)*mean(Y);
cov_th_matrix(2,1)=mean(Z)-mean(X)*mean(Y);
cov_th_matrix(1,1)=var(X);
cov_th_matrix(2,2)=var(Y);
cov_th_matrix

cov_th_matrix = 2×2
0.9942 -0.0083
-0.0083 0.9856

cov_emp=cov(X,Y)

1
cov_emp = 2×2
0.9942 -0.0083
-0.0083 0.9856

Z=a*X+b;
cov(Z,X)

ans = 2×2
3.9766 1.9883
1.9883 0.9942

You might also like