In [this](https://groups.google.com/d/topic/comp.soft-sys.matlab/mwk1yXTuFWc/discussion) thread on MATLAB Central, I found a discussion on finding the nearest matrix with real eigenvalues. The first hypothesis was to simply truncate the complex part of the eigenvalues. So, given matrix $A$, the closest matrix to $A$ in some norm would be 


$$A' = V \; \mathrm{real}(D)\; V^{-1}$$


where $A= V D V^{-1}$ is the eigendecomposition of $A$ (assuming $A$ is diagonalizable). This has been found to be false, however, with the counterexample


$$A = \begin{bmatrix} 
 1& 1& 0 \\
 -1& 0& 0 \\
 0& 0& 0 \\
\end{bmatrix}$$ 


The procedure above would produce 


$$A'=\begin{bmatrix} 
 0.5& 0& 0 \\
 0& 0.5& 0 \\
 0& 0& 0 \\
\end{bmatrix}$$ 


but there is another matrix 


$$A''=\begin{bmatrix} 
 0.9& 0& 0 \\
 -2& -0.1& 0 \\
 0& 0& 0 \\
\end{bmatrix}$$


that has real eigenvalues and is closest to $A$ both in spectral and Frobenius norm.


Now, let $ A = U T U' $ be the real Schur decomposition of $A$, with $U$ orthogonal and $T$ quasi-upper triangular (there are 2-by-2 blocks on the diagonal corresponding to complex eigenvalues). Consider $ A\_s = U \; \mathrm{triu}(T) \; U' $ where triu returns the upper triangle part. By numerical simulations $A\_s$ it is always closer to random $A$ than $A'$ and on the counterexample it is also closest to $A$ than $A''$ (in Frobenius and spectral norm).


My conjecture is that $A\_s$ is the closest matrix with real eigenvalues to $A$ in Frobenius (or spectral) norm.
Unfortunately I could not prove or disprove this conjecture. Can anybody?


A starting point can be 


$$||A-A\_s||\_F = ||T-\mathrm{triu}(T)||\_F$$



Finding the nearest matrix with real eigenvalues
I have no idea what is going on, but your conjecture is not correct. This is more transparent perhaps in the complex version. Consider
$$
A = \begin{pmatrix} i & a \\ 0&-i \end{pmatrix} , \quad a>0.
$$
This matrix is already in (complex) Schur form, and the obvious procedure to make the eigenvalues real and similar in spirit to what you propose would be to make the diagonal entries real (that is, set them equal to zero here). However, this is not optimal: we can also achieve real spectrum by setting $a\_{21}=b$, $b>1/a$, and in fact this is a very small perturbation if $a$ was large. (So the general message is that even eigenvalues that aren't close to the real axis might need only a small perturbation to get them there.)


A real version of this example also works, it just gets somewhat messier computationally. Take
$$
A = \begin{pmatrix} 0 & 1 & 0 & 0 \\ -1 & 0 & a & 0\\ 0&0&0&1 \\ 0&0&-1&0 \end{pmatrix} ,\quad a>0 .
$$
Your proposal is to remove the $-1$'s, but we can also get real eigenvalues by putting $a\_{32}=b$ as long as $ab>4$.


