Harmonic oscillator: Hamiltonian eigenvalue equation in coordinate basis Many years after my physics degree, I decided to refresh my knowledge in QM. Looking at the harmonic oscillator, I got confused about the relationship between the Hamiltonian operator and its representation in the coordinate basis.
If I want to find the eigenstates, I need to solve
$$
\hat H|n\rangle = E_n|n\rangle
$$
Using the coordinate basis representation, I can cast this equation into a differential equation:
$$
H(x)\phi_n(x) = E_n\phi_n(x)
$$
where now $H(x)$ is a differential operator.
I am trying to understand the relationship between the first and second equation.
From the first equation, I can write:
$$
\hat H |n\rangle = \int dx dy |x\rangle \langle x|\hat H|y\rangle \langle y|n\rangle \equiv
\int dx dy H(x, y)\phi_n(y)|x\rangle = 
\int dy E_n\phi_n(y)|y\rangle 
\equiv E_n|n\rangle
$$
where $H(x,y)=\langle x|\hat H|y\rangle$ is the representation of $\hat H$ in the coordinate basis.
From here I can say
$$
\int dx dy H(x, y)\phi_n(y)|x\rangle = 
\int dy E_n\phi_n(y)|y\rangle =
\int dx dy \delta(x-y)E_n\phi_n(y)|x\rangle 
$$
which implies
$$
H(x, y)\phi_n(y) = \delta(x-y)E_n\phi_n(y)
$$
This is equivalent to $H(x)\phi_n(x) = E_n\phi_n(x)$ only if I suppose that $H(x,y)$ is diagonal, i.e. $H(x,y)=H(x)\delta(x-y)$. But I know that $\hat H$ is not diagonal on the coordinate basis, because eigenstates of the positions are not eigenstates of the energy.
I know I am approaching the problem in the wrong way, but I do not understand exactly where I am wrong.
 A: Your observation is actually correct, in the following sense. Consider the matrix elements of the momentum operator:
\begin{align}
\langle x \vert \hat{P} \vert y \rangle
&= \int dp \langle x \vert \hat{P} \vert p \rangle \langle p \vert y \rangle \\
&= \int dp ~ p~ \langle x \vert p \rangle \langle p \vert y \rangle \\
&= \int \frac{dp}{2\pi} ~ p~ e^{ip(x-y)} \\
&= i \delta'(x-y),
\end{align}
where $\delta'(x-y)$ is the generalized derivative of the Dirac delta. You see then that this operator is almost diagonal, but there is this pesky derivative on the Diarc delta. However, when you multiply this by a wavefunction and integrate you'll find you can pass the derivative to the wavefunction and recover a simple Dirac delta.
The Hamiltonian matrix elements then go as
\begin{align}
\langle x \vert \hat{H} \vert y \rangle 
&\propto \langle x \vert \hat{P}^2 \vert y \rangle \\
&\propto \int \frac{dp}{2\pi} ~ p^2~ e^{ip(x-y)} \\
&\propto  i^2 \delta''(x-y).
\end{align}
Using this into your last expression:
\begin{align}
\delta(x-y)E_n\phi_n(y)
&= H(x, y)\phi_n(y)\\
&= \left(\frac{-\delta''(x-y)}{2m} + \frac{m\omega^2}{2} y^2 \delta(x-y)\right) \phi_n(y)
\end{align}
Integrating on the loose variable ($x$):
\begin{align}
E_n\phi_n(y) 
&= \int dx \delta(x-y)E_n\phi_n(y) \\
&= \int dx\left(\frac{-\delta''(x-y)}{2m} + \frac{m\omega^2}{2} y^2 \delta(x-y)\right) \phi_n(y) \\
&= \left(\int dx \frac{-\delta''(x-y)}{2m} \phi_n(y) \right) + \frac{m\omega^2}{2} y^2 \phi_n(y) \\
&= \left(\int dx \frac{\delta'(x-y)}{2m} \phi'_n(y) \right) + \frac{m\omega^2}{2} y^2 \phi_n(y) \\
&= \left(\int dx \frac{-\delta(x-y)}{2m} \phi''_n(y) \right) + \frac{m\omega^2}{2} y^2 \phi_n(y) \\
&= \left(\frac{-\partial^2_y}{2m} + \frac{m\omega^2 y^2}{2}\right) \phi_n(y) 
\end{align}
