Mercurial > hg > camir-aes2014
annotate 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 |
rev | line source |
---|---|
wolffd@0 | 1 function s = checkpsd(s) |
wolffd@0 | 2 |
wolffd@0 | 3 if (any(isnan(s) | isinf(s) | ~isreal(s))) |
wolffd@0 | 4 warning('S contains complex numbers, Inf, or NaN'); |
wolffd@0 | 5 end |
wolffd@0 | 6 % Drop any negative eigenvalues. |
wolffd@0 | 7 [V, D] = eig(full(s)); |
wolffd@0 | 8 d = real(diag(D)); |
wolffd@0 | 9 if (any(d < 0)) |
wolffd@0 | 10 warning(sprintf(['S is not positive semidefinite (min. eig. =' ... |
wolffd@0 | 11 ' %0.5g); projecting.'], min(d))); |
wolffd@0 | 12 d(find(d < 0)) = 0; |
wolffd@0 | 13 D = diag(d); |
wolffd@0 | 14 s = V * D * V'; |
wolffd@0 | 15 end |