Suppose the matrices $A$ and $B$ commute. Do there exists sequences $A\_n$ and $B\_n$ of matrices such that


1. $A\_n \rightarrow A$, $B\_n \rightarrow B$.
2. Each $A\_n$ is diagonalizable and the same for each $B\_n$.
3. For every $n$, $A\_n$ commutes with $B\_n$.


Moreover, it would be nice if the following property was additionally satisfied: if $A,B$ are real, then $A\_n,B\_n$ can be chosen to be real as well. 


P.S. I [asked this question](https://math.stackexchange.com/questions/227842/approximating-commuting-matrices-by-commuting-diagonalizable-matrices) on math.SE a couple of days ago. 



Approximating commuting matrices by commuting diagonalizable matrices
Over the complex numbers the answer is yes. It was proved by Gerstenhaber that the variety of pairs of commuting matrices is irreducible. This variety has an open subset the set of pairs $(A,B)$ such that $A$ and $B$ are commuting diagonalizable matrices.


**Edit:** I'm fairly sure M. Gerstenhaber was the first to prove that the irreducibility result. His paper is: *On dominance and varieties of commuting matrices*, Annals Math. **73** (1961), 324-348. However the result asked for in the question was already known from Theorem 5 in T. S. Motzkin, Olga Taussky, *Pairs of matrices with property L II*, Trans. Amer. Math. Soc. **80** (1955), 387-401. There is a short account of this work after Remark 3.4 in the paper by Meara and Vinsonhaler mentioned in SJ's answer. 


**Further edit for real case:** It is sufficient to prove that if $A$ and $B$ are commuting real matrices then there exist matrices $E$ and $F$ such that for all sufficiently small non-zero $\epsilon$, the matrices $A + \epsilon E$ and $B + \epsilon F$ commute and are diagonalizable. This can be done using some details from the proof by Motzkin and Taussky.


*Outline:* Since $A$ and $B$ commute they preserve each others primary decompositions. This reduces to the case where $A$ and $B$ are primary matrices. I'll deal here with the case where neither $A$ nor $B$ have real eigenvalues. By adding a multiple of the identity matrix to $A$ and $B$ we can assume that $A$ has characteristic polynomial $(x^2 + \theta^2)^m$ and $B$ has characteristic polynomial $(x^2 + \phi^2)^m$. There is a decomposition


$$ V = \left< u\_1, v\_1 \right> \oplus \cdots \oplus \left< u\_m, v\_m \right> $$


and matrices $S$, $T$, $M$ and $N$ such that 


* $S$, $T$, $M$, $N$ commute,
* $A = S(I+M)$ and $B = T(I+N)$,
* $S$ and $T$ preserve each $2$-dimensional summand $\langle u\_i,v\_i \rangle$, acting as the matrices

$$ \left( \begin{matrix} \cos \theta & \sin \theta \newline -\sin \theta & \cos \theta \end{matrix} \right) \quad\text{and}\quad
\left( \begin{matrix} \cos \phi & \sin \phi \newline -\sin \phi & \cos \phi \end{matrix} \right) $$

respectively. 
* $M$ and $N$ are nilpotent and $u\_i M \in \langle u\_{i+1}, v\_{i+1}, \ldots, u\_m , v\_m \rangle$ and similarly for $v\_i M$. (The action of $N$ could be more complicated.)


If $A$ is cyclic then there exists $f \in \mathbf{R}[x]$ such that $B = f(A)$. If $E$ is such that $A + \epsilon E$ is diagonalizable for all sufficiently small non-zero $\epsilon$ then we can define the required perturbation $F$ by $B + \epsilon F = f(A+ \epsilon E)$.


If $A$ is not cyclic then there exists $r > 1$ such that the projection $E\_r$ 
with image $\langle u\_r, v\_r, \ldots, u\_m, v\_m \rangle$ and kernel $\langle u\_1, v\_1, \ldots, u\_{r-1}, v\_{r-1} \rangle$ commutes with $A$. Then $T(I + N + \epsilon E\_r)$ commutes with $A$. Moreover, $E\_r$ commutes with $T$, and since $N$ and $M$ commute, the eigenvalues of $N + \epsilon E\_r$ are either $0$ or $\epsilon$. The characteristic polynomial of $T(I+N + \epsilon E\_r)$ splits into a product of powers of the distinct irreducibles $x^2 + \phi^2$ and $x^2 + \phi^2 - \epsilon$. So we get a further decomposition of $\mathbf{R}^{2m}$, still preserved by $A$, and the result follows by induction on the dimension.


