% Tony Hyun Kim
% EE 278B: PS#4, Problem 2
clear all; close all;

N = 5000;
XY = rand(N,2);   % Uniform RVs
XY = norminv(XY); % Jointly distributed Gaussian, with
                  %     mean  = [0 0]'
                  %     Sigma = [1 0; 0 1]

% Specified covariance
sx = 2;
sy = 1;
rho = 0.5;
Sigma = [sx^2 sx*sy*rho;
         sx*sy*rho sy^2];
SigmaSqrt = chol(Sigma)'; % Coloring matrix (lower triangular)
XY = XY*SigmaSqrt;        % Apply coloring matrix
XY = kron(ones(N,1),[3 2])+XY; % Offset the mean

plot(XY(:,1),XY(:,2),'.');
grid on;
axis equal;
xlabel('X');
ylabel('Y');
title('EE 278B, Problem 2');