Why does the virial theorem of quantum mechanics hold for the quantum oscillator but not the infinite square well? Why does the virial theorem of quantum mechanics hold for the quantum oscillator but not the infinite square well? The proof uses Ehrenfest's theorem, so I was wondering if it had something to do with the boundary conditions and how the particle does not behave classically. The theorem is as follows:

Consider a quantum system where $\psi$ represents a stationary state which satisfies $d<\hat{x}\hat{p}>/dt=0$. Then,
  \begin{equation}
2<\hat{T}>=<\hat{x}\frac{d\hat{V}}{dx}>.
\end{equation}

 A: *

*We calculate
$$0~=~\frac{d}{dt}\langle \psi | \hat{x}\hat{p} | \psi\rangle
~=~\frac{1}{i\hbar}\langle \psi | [\hat{x}\hat{p},\hat{H}] | \psi\rangle $$
$$~=~\frac{1}{i\hbar}\langle \psi \left| \hat{x}[\hat{p},\hat{V}]-[\hat{T},\hat{x}]\hat{p} \right| \psi\rangle
~=~2\langle \psi | \hat{T}| \psi\rangle-\langle\psi |\hat{x}\hat{V}^{\prime}(\hat{x}) | \psi\rangle.$$

*OP wants to consider the infinite square well potential. 

*At first it might be tempting to consider the box interval $[-a,a]$ as full position space, and put the potential $V=0$ to zero everywhere. The problem with that approach is that the dynamics will not respect the boundary conditions $\psi(x=\pm a,t)=0$. 

*We want the boundary conditions to be consequences of the potential. Therefore the potential should be non-trivial.

*The problem is therefore that the derivative $V^{\prime}(x)$ is not well-defined at the end-points of the box interval $[-a,a]$. 

*One possible regularization is to consider the finite square well potential 
$$V(x)= V_0~\theta(|x|-a),\qquad V_0~<~\infty,$$ 
on the real axis $\mathbb{R}$, where the theorem applies. Then the derivative $V^{\prime}(x)$ is a Dirac delta distribution. Next consider the limit $V_0\to\infty$. 
