function [pc_vec, pc_coeff] = prcomp(X)

n = size(X, 1); 
Xm = X - repmat(mean(X,1), [n, 1]);

% by SVD, to avoid computing the covariance...
% pc_vec will contain the eigenvectors of cov(Xm) and
% diag(S).^2 will be the corresponding eigenvalues
[U,S,pc_vec] = svd(Xm, 'econ');
pc_coeff = diag(S).^2 / (n-1);

return

