Given $A, B\in R^{n\times n}$ diagonal matrices, there exist $p,q \in R[x]$ and $X\in R^{n\times n}$ such that $A = p(X),B=q(X)$ 
(1) We are given $A,B \in R^{n\times n}$ diagonal matrices of n rows and n columns with real values.
Show that there are $X \in R^{n\times n}$ and polynomials $q$ and $p$ such that:
$$q(X)=B \text{ and }p(X)=A$$

What I've tried doing:
I've tried a different combinations of X and p,q, for example:
If we say that $X=A$ and we define $q(X) = X-A+B$ and $p(X)=X$ we indeed solve the problem
BUT those p and q are not polynomials, because if i use a scalar as an input for those polynomials instead of a matrix, it doesn't work. There is no scalar version of the matrix A (Unlike for example the unit matrix, which the scalar version of which is 1) So that isn't the way to solve the question

(2) Is this correct for any 2 matrices or just for diagonal matrices? Hint: What basic difference is there between the polynomial ring and the matrix ring?

(Haven't started working on this yet cause didn't solve question 1, but it probably involves that the matrix multiplication isnt commutative)
 A: Hint:
$$X=\begin{pmatrix}x_1&&\\&\ddots&\\&&x_n\end{pmatrix}$$
$$P(X)=\begin{pmatrix}P(x_1)&&\\&\ddots&\\&&P(x_n)\end{pmatrix}$$
A: Hints:


*

*Lagrange interpolation would be useful if $X$ is a diagonal matrix with distinct diagonal entries.

*The polynomial ring over $\mathbb{R}$ is commutative, but the matrix ring is not. So, $p(X)$ always commutes with $q(X)$ but ...


Remarks:
(a) Note that in question 1, a solution $(p,q,X)$ exists not only because $A$ and $B$ are diagonal matrices, but also because the underlying field ($\mathbb{R}$) is infinite. There can be no feasible solution if the field is finite. For instance, consider $A=\operatorname{diag}(1,0,0)$ and $B=\operatorname{diag}(0,1,0)$ over $GF(2)$. There are only $512$ choices of $X$ and eight choices of each of $p(X)$ and $q(X)$. One can perform a brute-force search to verify that none of these choices solve the set of equations $p(X)=A,\,q(X)=B$.
(b) The wording of the question may lead one to (wrongly) believe that two commuting matrices $A$ and $B$ can always be written as polynomials of some matrix $X$. However, in the previous remark, we have already seen that this is not the case even if $A$ and $B$ are diagonal matrices. For more in-depth discussions, see MSE/326293 and MO/34314.
