Necessary and sufficient conditions for two matrices to be diagonally similar. Let $A$ and $B$ be two matrices of order $n$. Then we call $A$ and $B$ as diagonally similar if they are similar via a diagonal matrix, i.e. there exists a diagonal matrix $D$ such that $A=D^{-1}BD$. 
My question is 

What are the conditions on $A$ and $B$ so that they are diagonally
  similar?

 A: This is  an answer which concentrates on necessary conditions.
Let $D=\begin{bmatrix} d_1 & 0 & \dots & 0 \\ 0 & d_2 &  \dots & 0 \\\dots  & \dots  &  \dots & \dots  \\ \\0 & 0 &  \dots &  d_n \end{bmatrix}$, then  $D^{-1}=\begin{bmatrix} 1/d_1 & 0 & \dots & 0 \\ 0 & 1/d_2 &  \dots & 0 \\\dots  & \dots  &  \dots & \dots  \\ \\0 & 0 &  \dots &  1/d_n \end{bmatrix}$.
Calculating $D^{-1}BD$ we obtain $A=\begin{bmatrix} (d_1/d_1)b_{11} & (d_2/d_1)b_{12} & \dots & (d_n/d_1)b_{1n} \\ (d_1/d_2)b_{21} & (d_2/d_2)b_{22} &  \dots & (d_n/d_2)b_{2n} \\\dots  & \dots  &  \dots & \dots  \\ \\(d_1/d_n)b_{n1} & (d_2/d_n)b_{n2} &  \dots &  (d_n/d_n)b_{nn}\end{bmatrix}$
Hence two of the necessary conditions:


*

*the $a_{ii}= b_{ii}$, the same entries on the main diagonals

*for $i \ne j$ $a_{ij}a_{ji}= b_{ij}b_{ji}$.


The presented form of $A=f(B)$ can help in reconstruction of matrix $D$.  
Take for example $B=\begin{bmatrix} 2 & 2 &  \\ 2 & 3 \end{bmatrix}$,
$A=\begin{bmatrix} 2 & 1 &  \\ 4 & 3 \end{bmatrix}$. 
Then for this case $d_1/d_2=2$ and $d_1=2d_2$.
Diagonal matrix for this case  $D=k\begin{bmatrix} 2 & 0 &  \\ 0 & 1 \end{bmatrix}$. 
You can check that $\begin{bmatrix} 2 & 1 &  \\ 4 & 3 \end{bmatrix}= \begin{bmatrix}0.5 & 0 &  \\ 0 & 1 \end{bmatrix}\begin{bmatrix} 2 & 2 &  \\ 2 & 3 \end{bmatrix}\begin{bmatrix} 2 & 0 &  \\ 0 & 1 \end{bmatrix}$.
Because this procedure is efficient for $n =2$, at least for matrices $2 \times 2 $ the conditions above are also sufficient.
For higher dimension denote matrix of coefficients     
$C=\begin{bmatrix} 
c_{11}  & c_{12}  & \dots & c_{1n}  \\ c_{21}  & c_{22}  & \dots & c_{2n}   \\\dots  & \dots  &  \dots & \dots  \\  c_{n1}  & c_{n2}  & \dots & c_{nn}  \end{bmatrix} = \begin{bmatrix} 1 & (d_2/d_1)  & \dots & (d_n/d_1)  \\ (d_1/d_2)  & 1  &  \dots & (d_n/d_2)  \\\dots  & \dots  &  \dots & \dots  \\  (d_1/d_n)  & (d_2/d_n)  &  \dots &  1 \end{bmatrix}$
The relationship $A= D^{-1}BD$ can be expressed in a compact  with the use of Hadamard product
$A=C \circ B$
Note that having one column of $C$, entries of other columns can be also calculated,
 for example $(d_2/d_n)= (d_1/d_n)/(d_1/d_2)$. 
On the other hand $C$ is equal to  matrix     $\begin{bmatrix} 
a_{11}/ b_{11} & a_{12}/ b_{12} & \dots & a_{1n}/b_{1n}  \\ a_{21}/b_{21}  & a_{22} /b_{22} & \dots & a_{2n} /b_{2n}  \\\dots  & \dots  &  \dots & \dots  \\  a_{n1} /  b_{n1} & a_{n2}/b_{n2}   & \dots & a_{nn}/b_{nn}  \end{bmatrix}$.
Calculated ${d_i}$ (entries of $D$) must be consistent for whole this matrix.
Using methods as above you can generate from them other necessary constraints,   
for example
$(d_2/d_n)= (d_1/d_n)/(d_1/d_2)$ i.e. $(a_{n2}/b_{n2})= (a_{n1}/b_{n1})/(a_{21}/b_{21})$.
If you calculate all such constraints you should have all necessary conditions.
