wolffd@0: function s = checkpsd(s) wolffd@0: wolffd@0: if (any(isnan(s) | isinf(s) | ~isreal(s))) wolffd@0: warning('S contains complex numbers, Inf, or NaN'); wolffd@0: end wolffd@0: % Drop any negative eigenvalues. wolffd@0: [V, D] = eig(full(s)); wolffd@0: d = real(diag(D)); wolffd@0: if (any(d < 0)) wolffd@0: warning(sprintf(['S is not positive semidefinite (min. eig. =' ... wolffd@0: ' %0.5g); projecting.'], min(d))); wolffd@0: d(find(d < 0)) = 0; wolffd@0: D = diag(d); wolffd@0: s = V * D * V'; wolffd@0: end