function rank = msv(SG,Juu)
%Function that calculates the minimum singular value of combinations 
%of 2 controlled variables.
%Run script main.m
%DEH - 2010

[ny,nu] = size(SG);
rank = zeros(nchoosek(ny,nu),nu+1);

k=1;
for a = nchoosek(1:ny,nu)'
    tempSG = [SG(a(1),:);SG(a(2),:)];
    minsingval = min(svd(tempSG*inv(sqrtm(Juu))));
    rank(k,:) = [a(1) a(2) minsingval];
    k=k+1;
end

rank = sortrows(rank,-3);