covariance matrix from a random vector?

조회 수: 166(최근 30일)
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016년 10월 26일
댓글: Kanike Sreekanth 2021년 4월 15일
Given a random vector, Y=[y1,y2,...,yn]; its covariance matrix look like this:
According to this definition, How can I calculate covariance matrix in matlab? N.B. cov() function makes me confusion....

채택된 답변

Honglei Chen
Honglei Chen 2016년 10월 26일
cov should be the function you use, what about it makes you confusing?
  댓글 수: 3
K M Ibrahim Khalilullah
K M Ibrahim Khalilullah 2016년 11월 2일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변(3개)

Christopher Smith
Christopher Smith 2018년 1월 28일
I know this question is old but I came across this page looking for the same answer. If the cov() function in Matlab had an input element option for the expected value of the two functions then it would work but it does not. The cov() function appears to be designed for a large data set where the mean value can be determined. In your case you will need to know the expected value of each of the random variables in your vector ahead of time. Then the covariance of that vector would be calculated with nested for loops iterating through the array and computing the elementwise covariance manually. The built in function cov() does not provide any options here. This is the video link that helped me: https://m.youtube.com/watch?v=0W8hTzU1ZMM It assumes that you have a vector of random variable values (instances) where each element represents the functions to be compared with covariance and that for each element in the vector you already know the expected value. Then it is easy to take an Nx1 vector and compute the NxN covariance matrix but tedious.
  댓글 수: 1
Anna M
Anna M 2019년 7월 3일
I am also looking for the same answer, and that video helped a lot! Thanks

댓글을 달려면 로그인하십시오.


Roger Stafford
Roger Stafford 2016년 10월 27일
With just a vector, Y, you can calculate its variance but there is no significance to calculating its covariance. That would always be zero.
Covariance has a significance only with a set of vectors. Matlab’s ‘cov’ function will obtain the covariance of a matrix where the different columns are different components of random variables and the rows are different variations of those rows. Applied to your problem, the result would be a row of zeros since there is no variation (though that is not what matlab does). If you start with a single column vector the result is simply the variance which will be a scalar.

Allen Goldstein
Allen Goldstein 2021년 4월 3일
Let me see if I have this right, if I run cov(z) where z is a vector, I'll just get a vector. The covarinace matrix has the variances (cov(z1,z1)) on the diagonal and the covariances symetrically in the upper and lower triangles.
I think to get the covarinace matrix, you need to create a vector of differences bewteen each point and the mean of all points, multiply it with it's transpose, then divide by the number of points.
So if z is a vector of random variables, C will be the covariance matrix
M = ones(1,length(z))*mean(z); % vector of mean values
Zc = z - M; % distances to the mean
C = (Zc'*Zc)./length(z); % covariance matrix
  댓글 수: 1
Kanike Sreekanth
Kanike Sreekanth 2021년 4월 15일
if they are zero mean random variables, can we just perform "xcorr" to the matrix??

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by