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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
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