I have two matricies, X and Y, with each column representing multiple realizations of a random variable;
X = [x_11 x_21 .... x_n1
x_12 x_22 .... x_n2
. . .... .
. . .... .
x_1m x_2m .... x_nm]
And where Y is a function of X: Y = f(X)
Y = [y_11 y_21 .... y_n1
y_12 y_22 .... y_n2
. . .... .
. . .... .
y_1m y_2m .... y_nm]
I want to find the covariance matrix between the variables x_n and y_n;
E{(X - E{Y}) * (Y - E{Y})^H}
Where ()^H denotes the Hermitian Transpose of the vector
In matlab, when I run cov(X,Y) on the matricies, (each 1000 trials of 20 variables) I only get a 2×2 matrix back, which leads me to believe that it is treating each matrix as a single “variable” somehow. If I concatenate the two matricies and call cov on the result:
cov( [X Y] )
I get a 40×40 matrix, with the result of cov( X ) in the top left, the result of cov( Y ) in the bottom right, and the matrix I want in the top right and bottom left, but is there a way to calculate this without having to resort to this?
Thanks
cov(X,Y)is equivalent tocov([x(:) y(:)]). But[x(:) y(:)]is 20000 by 2 for you, andcov()treats rows as observations and columns as dimensions, so you get a 2 by 2 covariance matrix.I would just implement it myself by the definition:
If you have an older version of matlab that doesn’t support
bsxfun(), just userepmat().