function [coordinates,vaf,vectors,roots] = guttman(prox,numdim)

n = size(prox,1);

amatrix = zeros(n,n);

proxsums = sum(prox);

for i = 1:n
    for j = 1:n
      
        if(i == j)
            amatrix(i,j) = proxsums(i);
        else
            amatrix(i,j) = -prox(i,j);
        end
      
    end
end


[vectors,roots] = eig(amatrix);

[vals,inds] = sort(diag(roots));

inds = flipud(inds);
vals = flipud(vals);

vectors = vectors(:,inds);
roots = diag(vals);

coordinates = vectors(:,1:numdim)*diag(sqrt(vals(1:numdim)));

distances = pdist(coordinates);

proximities = squareform(prox);

corrmatrix = corrcoef(distances',proximities');

vaf = corrmatrix(1,2)^2;



