# Calculating $\hat{x}^2$ and $\hat{p}^2$ - harmonic oscillator matrix form [closed]

In harmonic oscillator, we can write $$\hat{x}$$ and $$\hat{p}$$ as (I obtained the $$\hat{x}$$ and $$\hat{p}$$ by using matrix form of the ladder operators) ;

$$\hat{x} = \sqrt{\frac{\hbar}{2m\omega}}\begin{bmatrix} 0 & \sqrt{1} & 0 \\ \sqrt{1} & 0 & \sqrt{2} \\ 0 & \sqrt{2} & 0 \end{bmatrix}$$

and

$$\hat{p} = i\sqrt{\frac{\hbar m\omega}{2}}\begin{bmatrix} 0 & -\sqrt{1} & 0 \\ \sqrt{1} & 0 & -\sqrt{2} \\ 0 & \sqrt{2} & 0 \end{bmatrix}$$

Now, I need to find $$\hat{x}^2$$ and $$\hat{p}^2$$. My approach was to do simple matrix multiplication

$$\hat{x}^2 = \frac{\hbar}{2m\omega}\begin{bmatrix} 0 & \sqrt{1} & 0 \\ \sqrt{1} & 0 & \sqrt{2} \\ 0 & \sqrt{2} & 0 \end{bmatrix}\begin{bmatrix} 0 & \sqrt{1} & 0 \\ \sqrt{1} & 0 & \sqrt{2} \\ 0 & \sqrt{2} & 0 \end{bmatrix}$$

so

$$\hat{x}^2 = \frac{\hbar}{2m\omega}\begin{bmatrix} 1 & 0 & \sqrt{2} \\ 0 & 3 & 0 \\ \sqrt{2} & 0 & 2 \end{bmatrix}$$

and similarly

$$\hat{p}^2 = \frac{\hbar m\omega}{2}\begin{bmatrix} 1 & 0 & -\sqrt{2} \\ 0 & 3 & 0 \\ -\sqrt{2} & 0 & 2 \end{bmatrix}$$

But this feels somewhat wrong, and when I do the same procedures for ($$4\times4$$) $$\hat{x}$$ and $$\hat{p}$$ matrices, I obtain wrong results.

I have also tried to perform the same operations by using $$\hat{x}^2 = a_{+}a_{+} + a_{+}a_{-} + a_{-}a_{+} + a_{-}a_{-}$$ but I got the same result.

Are $$\hat{x}^2$$ and $$\hat{p}^2$$ correct ?

• In what basis are these $3 \times 3$ matrices expressed? The three lowest energy levels? Commented Jan 2, 2023 at 9:40
• Yeah, I think so. I obtained the $\hat{x}$ and $\hat{p}$ by using matrix form of the ladder operators. Commented Jan 2, 2023 at 9:44
• @seVenVo1d This does not make sense. Mathematical rigor aside, the ladder operators are infinite matrices; in no way you can obtain $x$ and $p$ as finite matrices. Commented Jan 2, 2023 at 10:25
• Well, check the existent answer... I don't have the book, so I cannot cross-check. $X$ and $P$ are operators on an infinite-dimensional Hilbert space (do you know why?) - thus, they cannot be represented by $n\times n$ matrices for any $n\in \mathbb N$. Commented Jan 2, 2023 at 11:49
• As for now, your question is off-topic as it is a check-my-work question and it'll be closed, I guess. You can consider to rephrase the question appropriately, e.g. with a quote from the book you cite and to explicitly state your confusion regarding principles instead of concrete computations. Commented Jan 2, 2023 at 14:04

A simple check is to compute the Hamiltonian $$H={p^2\over 2m}+{1\over 2}m\omega^2x^2$$ With your matrices, you get $$H={\hbar\omega\over 4}\pmatrix{ 1 & 0 & -\sqrt 2 \cr 0 & 3 & 0 \cr -\sqrt 2 & 0 & 2}+{\hbar\omega\over 4}\pmatrix{ 1 & 0 & \sqrt 2 \cr 0 & 3 & 0 \cr \sqrt 2 & 0 & 2}={\hbar\omega\over 2}\pmatrix{ 1 & 0 & 0 \cr 0 & 3 & 0 \cr 0 & 0 & 2}$$ The Hamiltonian is diagonal as expected with the matrix elements $${1\over 2}\hbar\omega$$, $${3\over 2}\hbar\omega$$ and $$\hbar\omega$$. The last one is wrong but it is due to the fact that you truncated the $$x$$ and $$p$$ matrices to a finite subspace of the Hilbert space. With $$4\times 4$$ matrices, this term would be correct but then the last (fourth) one would then be wrong.
• But when I truncate and perform the operations my answer and the books do not match for $(4\times4)$ matrices. Commented Jan 2, 2023 at 12:29
• I guess that your book gives the true $x^2$ matrix truncated to $4\times 4$. You first truncated $x$ and then took its square. That’s where comes the discrepancy. Commented Jan 2, 2023 at 12:41