Prove that $AB=BA$ if $A, B$ are diagonal matrices Could you confirm my proof?
A fixed Proof (Confirm please):
Let $A, B$ be two diagonal matrices of order $n$. Then, both $AB,BA$ are defined and are of the same order $n$ (i.e. sizes match). Also, $A_{ij},B_{ij}=0$ whenever $i\ne j$.
Consider the case $i\ne j$:
$$\eqalign{
  & {\left( {AB} \right)_{ij}} = \sum\limits_{k = 1}^n {{A_{ik}}{B_{kj}}}  = \sum\limits_{i \ne k = j} {{A_{ik}}{B_{kj}}}  + \sum\limits_{i = k \ne j} {{A_{ik}}{B_{kj}}}  + \sum\limits_{i \ne k \ne j} {{A_{ik}}{B_{kj}}}  = \sum\limits_{i \ne k = j} {0 \cdot {B_{kj}}}  + \sum\limits_{i = k \ne j} {{A_{ik}} \cdot 0}  + \sum\limits_{i \ne k \ne j} 0   \cr 
  &  = 0 + 0 + 0 = 0 = \sum\limits_{i = k \ne j} {{B_{ik}} \cdot 0}  + \sum\limits_{i \ne k = j} {0 \cdot {A_{kj}}}  + \sum\limits_{i \ne k \ne j} 0  = \sum\limits_{i = k \ne j} {{B_{ik}} \cdot {A_{kj}}}  + \sum\limits_{i \ne k = j} {{B_{ik}} \cdot {A_{kj}}}  + \sum\limits_{i \ne k \ne j} {{A_{ik}}{B_{kj}}}   \cr 
  &  = \sum\limits_{k = 1}^n {{B_{ik}}{A_{kj}}}  = {\left( {BA} \right)_{ij}} \cr} $$
Consider the case  $i=j$
$$\eqalign{
  & {\left( {AB} \right)_{ij}} = {\left( {AB} \right)_{ii}} = \sum\limits_{k = 1}^n {{A_{ik}}{B_{ki}}}  = \sum\limits_{k \ne i} {{A_{ik}}{B_{ki}}}  + \sum\limits_{k = i} {{A_{ik}}{B_{ki}}}  = \sum\limits_{k \ne i} {0 \cdot 0}  + {A_{ii}}{B_{ii}} = 0 + {A_{ii}}{B_{ii}}  \cr 
  &  = 0 + {B_{ii}}{A_{ii}} = \sum\limits_{k \ne i} {0 \cdot 0}  + {B_{ii}}{A_{ii}} = \sum\limits_{k \ne i} {{B_{ik}}{A_{ki}}}  + \sum\limits_{k = i} {{B_{ik}}{A_{ki}}}  = \sum\limits_{k = 1}^n {{B_{ik}}{A_{ki}}}  = {\left( {BA} \right)_{ii}} = {\left( {BA} \right)_{ij}} \cr} $$
Hence, corresponding entries are equal.
Thus, $AB=BA$. 
Quod Erat Demonstrandum.
Thanks in advance
 A: Here is a much quicker proof: Let $e_n$ be the nth basis vector, $a_n$, $b_n$ the entries of the $n^{th}$ column of $A$, $B$, respectively. Then $ABe_n=A(b_ne_n)=b_nAe_n=b_na_ne_n=a_nb_ne_n=a_nBe_n=Ba_ne_n=BAe_n\,.$ Since the matrices agree on all basis vectors, they are equal.
A: Yes, this is perfectly correct, though you may want to note that you use the fact that diagonal matrices have a diagonal product. There are cleaner ways to do this, but there aren't any fundamental issues with this one.
A: In fact I d'ont think that your provf is correct. In your proof, you have $(AB)_{ij}=A_{ii}B_{ii}$, clearly it's not correct.
$$(AB)_{ij}=\sum_{k=1}^nA_{ik}B_{kj}$$
for $k\neq i$, $A_{ik}=0$, and for $k\neq j$, $B_{kj}=0$. So $(AB)_{ij}=A_{ii}B_{ij}+A_{ij}B_{jj}$, then when $i\neq j$, $(AB)_{ij}=A_{ii}*0+0*B_{jj}=0$, and when $i=j=k$, $(AB)_{ij}=(AB)_{kk}=A_{kk}B_{kk}$.
In another hand, you can do the same calculation for $BA$. You will have the same results:
when $i\neq j$, $(BA)_{ij}=B_{ii}*0+0*A_{jj}=0$, and when $i=j=k$, $(BA)_{ij}=(BA)_{kk}=B_{kk}A_{kk}=A_{kk}B_{kk}=(AB)_{ij}$.
So $AB=BA$.
Your proof shows only that when $i=j$,$(AB)_{ij}=(BA)_{ij}$.
