TITLE: Projecting a symmetric matrix onto the space of linear operators with a particular eigenvalue
QUESTION [5 upvotes]: Specifically, I am interested in the case where one eigenvalue is exactly $0$.  Given an $n \times n$ symmetric matrix, I would like to find the closest $n\times n$ symmetric matrix that has one eigenvalue that is equal to $0$. 
Although the $n\times n$ matrices form a Hilbert space, the set of symmetric matrices with a zero eigenvalue is probably not convex, because the eigenvalues of a sum of two matrices has a complex relationship with the original matrices.  Thus, the classic projection theorem does not guarantee a unique solution.  However, I only need a solution.  Since the eigenvalues of a matrix are continuous in the entries, the set of $n\times n$ matrices with a zero eigenvalue should be closed, and so the set of solutions shouldn't be totally insane.
In any case, how can I find the closest $n\times n$ symmetric matrix(es) with a zero eigenvalue to an arbitrary given $n\times n$ symmetric matrix?

REPLY [7 votes]: Any (real) symmetric matrix may be diagonalised by an orthogonal matrix. So let your matrix be $A$ and let $O$ be an orthogonal matrix such that $D=OAO^{-1}$ is diagonal. Note that the transformation $A\mapsto OAO^{-1}$ is distance preserving. Now get $D'$ by replacing whichever diagonal entry of $D$ has least absolute value, and let $A'=O^{-1}D'O$.
(Nathaniel Johnston's comment let me find the related paper "Low-Rank Positive Approximants of Symmetric Matrices" by Achiya Dax.)