Vous êtes sur la page 1sur 17

Scanned by CamScanner

Scanned by CamScanner
Scanned by CamScanner
Question 4
Table of Contents
part i ................................................................................................................................. 1
part ii .............................................................................................................................. 10
Step 1 .............................................................................................................................. 10
Step 2 .............................................................................................................................. 11
Step 4 .............................................................................................................................. 12

part i
x = -5:.2:5; y = -5:.2:5;
[X,Y] = meshgrid(x,y);

% for (sigma_x)^2=1 , (sigma_y)^2=1 , p_xy=0

Mean = [0 0];
C_xy = [1 0; 0 1];

Gaussian_dist = mvnpdf([X(:) Y(:)],Mean,C_xy);


Gaussian_dist = reshape(Gaussian_dist,length(y),length(x));
figure;
mesh(X,Y,Gaussian_dist);
colorbar;
axis([-5 5 -5 5 0 .2]);
xlabel('x');
ylabel('y');
zlabel('Gaussian distribution');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0');
figure;
contour(x,y,Gaussian_dist);
axis([-3 3 -3 3]);
xlabel('x');
ylabel('y');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0');
grid on;

% for (sigma_x)^2=1 , (sigma_y)^2=5 , p_xy=0

Mean = [0 0];
C_xy = [1 0; 0 5];

Gaussian_dist = mvnpdf([X(:) Y(:)],Mean,C_xy);


Gaussian_dist = reshape(Gaussian_dist,length(y),length(x));
figure;
mesh(X,Y,Gaussian_dist);
colorbar;
xlabel('x');
ylabel('y');

1
Question 4

zlabel('Gaussian distribution');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=5 , p_x_y=0');
figure;
contour(x,y,Gaussian_dist);
xlabel('x');
ylabel('y');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=5 , p_x_y=0');
grid on;

% for (sigma_x)^2=1 , (sigma_y)^2=1 , p_xy=0.25

Mean = [0 0];
C_xy = [1 0.25; 0.25 1];

Gaussian_dist = mvnpdf([X(:) Y(:)],Mean,C_xy);


Gaussian_dist = reshape(Gaussian_dist,length(y),length(x));
figure;
mesh(X,Y,Gaussian_dist);
colorbar;
xlabel('x');
ylabel('y');
zlabel('Gaussian distribution');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0.25');
figure;
contour(x,y,Gaussian_dist);
xlabel('x');
ylabel('y');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0.25');
grid on;

% for (sigma_x)^2=1 , (sigma_y)^2=5 , p_xy=0.25

Mean = [0 0];
C_xy = [1 0.25*sqrt(5); 0.25*sqrt(5) 1];

Gaussian_dist = mvnpdf([X(:) Y(:)],Mean,C_xy);


Gaussian_dist = reshape(Gaussian_dist,length(y),length(x));
figure;
mesh(X,Y,Gaussian_dist);
colorbar;
xlabel('x');
ylabel('y');
zlabel('Gaussian distribution');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=5 , p_x_y=0.25');
figure;
contour(x,y,Gaussian_dist);
xlabel('x');
ylabel('y');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=5 , p_x_y=0.25');
grid on;

% for (sigma_x)^2=1 , (sigma_y)^2=1 , p_xy=0.5

Mean = [0 0];

2
Question 4

C_xy = [1 0.5; 0.5 1];

Gaussian_dist = mvnpdf([X(:) Y(:)],Mean,C_xy);


Gaussian_dist = reshape(Gaussian_dist,length(y),length(x));
figure;
mesh(X,Y,Gaussian_dist);
colorbar;
xlabel('x');
ylabel('y');
zlabel('Gaussian distribution');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0.5');
figure;
contour(x,y,Gaussian_dist);
xlabel('x');
ylabel('y');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0.5');
grid on;

% for (sigma_x)^2=1 , (sigma_y)^2=1 , p_xy=0.98

Mean = [0 0];
C_xy = [1 0.98; 0.98 1];

Gaussian_dist = mvnpdf([X(:) Y(:)],Mean,C_xy);


Gaussian_dist = reshape(Gaussian_dist,length(y),length(x));
figure;
mesh(X,Y,Gaussian_dist);
colorbar;
xlabel('x');
ylabel('y');
zlabel('Gaussian distribution');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0.98');
figure;
contour(x,y,Gaussian_dist);
xlabel('x');
ylabel('y');
title('The case for (sigma_x)^2=1 , (sigma_y)^2=1 , p_x_y=0.98');
grid on;

% When p_xy=0, there is no relation between x and y values. That is, x and
% y are independent from each other. If p_xy value increases, the
% dependency between x and y increases positively. Furthermore, by
% increasing the variance of a variable, the spread in the distribution
% expands as seen in the figures.

3
Question 4

4
Question 4

5
Question 4

6
Question 4

7
Question 4

8
Question 4

9
Question 4

part ii
Step 1
x = randn(2,1000);

%x is a combination of columns and each column has a form of [x1 x2]^T

z1 = x(1,:);
z2 = x(2,:);

figure;
scatter(z1,z2);
xlabel('x_1');
ylabel('x_2');
title('Scattering of the columns of x for Step1');
grid on;

%As seen in the scatter plot, the mean of the randomly generated vectors
%are zero and the variances are the same and 1 for x_1 and x_2. They are
%also identically distributed.

10
Question 4

Step 2
A = [4 3 ; 1 2];

y = A*x;

z1 = y(1,:);
z2 = y(2,:);

figure;
scatter(z1,z2);
xlabel('y_1');
ylabel('y_2');
title('Scattering of the columns of y for Step2');
grid on;

%The plot now looks like a line. It can be understood from the scatter plot
%that the mean is again zero but the y_1 and y_2 elements are positively
%correlated to each other.

%Now, we calculate r_xy=h/sqrt(m*n)


h=0;
m=0;
n=0;

for k=1:1:1000;

h=y(1,k)*y(2,k)+h; %Summing operation


end

for k=1:1:1000;

m=y(1,k)*y(1,k)+m; %Summing operation


end

for k=1:1:1000;

n=y(2,k)*y(2,k)+n; %Summing operation


end

r_xy=h/sqrt(m*n)

% The correlation coefficient is about 0.9 which is correct since the


% column elements of y are positively correlated to each other.

r_xy =

0.9011

11
Question 4

Step 4
B = [4 -3 ; -1 2];

meann = linspace(4,4,1000);

mean = [meann ; meann];

z = (B*x) + mean;

z1 = z(1,:);
z2 = z(2,:);

figure;
scatter(z1,z2);
xlabel('z_1');
ylabel('z_2');
title('Scattering of the columns of z for Step4');
grid on;

% The plot now looks like a line. The column elements of z is negatively
% correlated to each other.

%Now, we calculate r_xy=h/sqrt(m*n) of z.


h=0;

12
Question 4

m=0;
n=0;

for k=1:1:1000;

h=z(1,k)*z(2,k)+h; %Summing operation


end

for k=1:1:1000;

m=z(1,k)*z(1,k)+m; %Summing operation


end

for k=1:1:1000;

n=z(2,k)*z(2,k)+n; %Summing operation


end

r_xy=h/sqrt(m*n)

% The correlation coefficient is about 0.2 which is correct since the


% column elements of z are negatively correlated to each other as seen
% in the figure.

r_xy =

0.2268

13
Question 4

Published with MATLAB R2014b

14

Vous aimerez peut-être aussi