Problem calculating a empirical covariance matrix

Hello,
I am trying to compute an empirical covariance matrix from a sample matrix. I need to use it later on with other function which calls chol. The data is 16 dimensional. I tried the following:
D = size(SAMPLE_MATRIX,2); COV = zeros(D,D); for i = 1:D COV = COV + SAMPLE_MATRIX(:,i)*SAMPLE_MATRIX(:,i)'; end COV = COV/D;
However, COV is not positive definite at the end (it has a large first positive eigenvalue and then negative eigenvalues of the order exp(-20)). Consequently I cannot use this matrix as a covariance matrix in the chol (or cholcov) function.
I tried the most obvious cov(SAMPLE_MATRIS'), with the same result. Am I doing something wrong, or there is a problem in how matlab computes covariances???

Categories

Find more on Linear Algebra in Help Center and File Exchange

Asked:

on 10 Feb 2012

Community Treasure Hunt

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

Start Hunting!