# How to find the nearest/a near positive definite from a given matrix?

I'm given a matrix. How do I find the nearest (or a near) positive definite from it?

The matrix can have complex eigenvalues, not be symmetric, etc. However, all its entries are real valued. The resulting matrix from the algorithm must be positive definite, with all its entries real valued only. Symmetry is a plus, but not necessary. I have no preference toward the metric used. I prefer a pragmatic(relatively easy to programme) approach. It doesn't have to be optimal.

• The most common definition of "positive definite" includes symmetric. Are you specifically looking for a symmetric matrix, or would a non-symmetric matrix with eigenvalues that are real and positive be acceptable? What about a matrix that has complex eigenvalues with positive real parts? – Brian Borchers Dec 3 '18 at 3:39
• What definition of "nearest" are you interested in? With respect to the spectral norm? Frobenius norm? Some other measure? – Brian Borchers Dec 3 '18 at 3:59
• @BrianBorchers I've edited the question. I have no preference for the norm, as long as the requirements explained above are satisfied. – An old man in the sea. Dec 3 '18 at 9:45
• Is this the sort of thing you're looking for? stat.ethz.ch/R-manual/R-devel/library/Matrix/html/nearPD.html (Incidentally, nearPD replaces $X$ with $\frac12(X+X^\top)$ for non-symmetric $X$.) – Kirill Dec 3 '18 at 13:30
• @Kirill Yes. ;) Thanks – An old man in the sea. Dec 3 '18 at 14:07

1. Replace $$X$$ with the closest symmetric matrix, $$Y=\frac12 (X+X^\top)$$.
2. Take an eigendecomposition $$Y=QDQ^\top$$, and form the diagonal matrix $$D_+=\max(D,0)$$ (elementwise maximum).
3. The closest symmetric positive semidefinite matrix to $$X$$ is $$Z=QD_+Q^\top$$.
4. The closest positive definite matrix to $$X$$ does not exist; any matrix of the form $$Z+\varepsilon I$$ is positive definite for $$\varepsilon>0$$. There is no minimum, just an infimum. Positive definite matrices are not a closed set.