function Mar15()
% Given a symmetric matrix, find a nearest symmetric matrix B that has a 
% repeated eigenvalue...
clc
n = 6;
A = randn(n,n); A = A + A';
[Q,D] = eig(A);
dA = diag(D)
% the eigs range from most negative  to most positive
[alfa,k] = min(dA(2:n)-dA(1:n-1));
% alfa = d(k+1)-d(k) is the smallest gap
dB = dA; dB(k+1)=dB(k+1)-alfa/2; dB(k) = dB(k) + alfa/2
B = Q*diag(dB)*Q'; 
HowClose= norm(A-B)

