function Feb19()

% Generate a symmetric indefinite matrix...
n = 100;
X = randn(n,n);
m = floor(n*rand(1)); 
D = diag([-m:-1 1:(n-m)]); 
A = X*D*X';    
% A has m negative eigs and n-m positive eigs

% Compute P'AP = LDL', i.e., A = PLDL'P'..
[L,D,P] = ldl(A);
% Because they are congruent, D should have the same number of positive
% eigenvalues as A.

% D is block diagonal with 1x1 and 2x2 diagonal blocks. Visit each
% one and count how many positive eigenvalues that you see...

k = 1;
pos = 0;
while (k<=n)
    if k==n || D(k+1,k) == 0
       % 1x1
       pos = pos + (D(k,k)>0);
       k = k+1;
    else
        % 2x2
        pos = pos + sum(eig(D(k:k+1,k:k+1))>0);
        k = k+2;
    end
end
n_minus_m = n-m
pos  = pos
end