spm_sqrtm.m 705 B

12345678910111213141516171819
  1. function [K] = spm_sqrtm(V)
  2. % Matrix square root for sparse symmetric positive semi-definite matrices
  3. % FORMAT [K] = spm_sqrtm(V)
  4. %
  5. % This routine covers and extends sqrtm functionality by using a
  6. % computationally expedient approximation that can handle sparse
  7. % symmetric positive semi-definite matrices.
  8. %__________________________________________________________________________
  9. % Copyright (C) 2005-2013 Wellcome Trust Centre for Neuroimaging
  10. % Karl Friston
  11. % $Id: spm_sqrtm.m 5892 2014-02-23 11:00:16Z karl $
  12. %--------------------------------------------------------------------------
  13. [u,s] = spm_svd(V,0);
  14. s = sqrt(abs(diag(s)));
  15. m = length(s);
  16. s = sparse(1:m,1:m,s);
  17. K = u*s*u';