matlabrandomcovariancegaussianiid

Clarifying the Process of Generating iid Gaussian Random Vectors in MATLAB


This may be a silly question I just wanted to double check my understanding of random vector creation in MATLAB.

I would like to generate 100 two-dimensional iid random vectors using a gaussian distribution of mean 0 and standard deviation 1. I did this using the code

iid_gaussian_vectors = normrnd(0, 1, 100, 2);

I believe that the row vectors of the output will be my iid gaussian vectors, is this correct? I tried to check the covariance and and it is small but not exactly 0 (probably due to numerical error?). Any insight is greatly appreciated. Thanks!


Solution

  • First, (theoretically) when you generate random samples from a Gaussian distribution (mean 0, std. dev. 1), each dimension is (or should be) perfectly independent of each other and the covariance between any two dimensions is (or should be) exactly zero. However, in practice, due to the finite precision of floating-point arithmetic used in computers, tiny numerical errors accumulate during calculations and its these errors that lead to very small non-zero values in the off-diagonal elements of the covariance matrix. That's why you are seeing a very small value of covariance.

    Secondly, Yes the iid_gaussian_vectors will indeed be a 100x2 matrix, where each row represents a random vector.