I'm asked to compute the matrix elements $\left( x^i \right)_{nm}$ where $i=2,3,4$ and $x$ represents the position operator for the quantum harmonic oscillator. I know that for $i=1$: \begin{equation} (x)_{nm}=\sqrt{\frac{\hbar}{2m\omega}}(\sqrt{m}\delta_{n,m-1}+\sqrt{m+1}\delta_{n,m+1}) \end{equation}
I have already solved the problem using the expression of $\hat{x}$ in terms of ladder operators $a_+,a_-$, but I'm asked to do it with matrix multiplication aswell. Is this the correct calculation with this method? \begin{equation} (x^2)_{nm}=\sum_{k=0}^{\infty}x_{nk}x_{km} \end{equation}
I tried to compute the upper expression but the answer I got is different from that obtained through the ladder operators method, which is: \begin{equation} (x^2)_{nm}=\frac{\hbar}{2m\omega}\left[ (m+1)\delta_{n,m+2}+m\delta_{n,m-2}+(2m+1)\delta_{nm} \right] \end{equation} Thank you in advance for any answer.