comparison toolboxes/FullBNT-1.0.7/KPMtools/checkpsd.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function s = checkpsd(s)
2
3 if (any(isnan(s) | isinf(s) | ~isreal(s)))
4 warning('S contains complex numbers, Inf, or NaN');
5 end
6 % Drop any negative eigenvalues.
7 [V, D] = eig(full(s));
8 d = real(diag(D));
9 if (any(d < 0))
10 warning(sprintf(['S is not positive semidefinite (min. eig. =' ...
11 ' %0.5g); projecting.'], min(d)));
12 d(find(d < 0)) = 0;
13 D = diag(d);
14 s = V * D * V';
15 end