# Derivation of the virial theorem from the action and boundary term

In this answer, it is said that the invariance of the action under the transformation $$x \rightarrow (1+\epsilon)x\tag{0}$$ gives, up to some boundary terms the virial theorem.

I tried to interpret this but I'm very unsure:

Given the previous transformation, the action varies as follow: $$\delta S(x) = \epsilon\int_{0}^{T} \left(m\dot{x}^2 -x\frac{\partial V}{\partial x}\right)\mathrm{d}t\tag 1$$

but since $$\delta(0)\neq0$$ and $$\delta(T)\neq0$$, the boundary terms in the usual action variation doesn't vanish:

$$\delta S(x)=\epsilon\left[ x\frac{\partial L}{\partial \dot x}\right]_0^T+\int_0^T\left(\frac{\partial L}{\partial x}-\frac{\mathrm d}{\mathrm d t}\frac{\partial L}{\partial \dot x}\right)\mathrm{d} t\tag 2$$

If $$x$$ satisfies the equations of motion, then (2) is equal to: $$\delta S(T,0) = \epsilon\left[ x\frac{\partial L}{\partial \dot x}\right]_0^T\tag 3$$

Now, saying that (1) = (3) (inserting the $$x$$ which satisfy the equation of motion in (1)) we have:

$$\frac{1}{T}\left[ x\frac{\partial L}{\partial \dot x}\right]_0^T=\frac{1}{T}\int_{0}^{T} \left(m\dot{x}^2 -x\frac{\partial V}{\partial x}\right)\mathrm{d}t\tag 4$$

The LHS vanishes for bounded trajectories at $$T\rightarrow\infty$$ and we obtain the virial theorem.

I have three questions:

1. Is this right?
2. If so, why can't we just say that $$\delta S = 0$$ in (1) and thus get the wrong equation: $$m\dot{x}^2 -x\frac{\partial V}{\partial x}=0$$? Is this because, we have to ask $$\delta S = 0$$ for every $$\delta x(t)$$ with $$\delta x(0) = \delta x(T) =0$$?
3. Then, if this is right, we are not really asking that (1) $$= 0$$ to find the virial theorem, we are asking: $$\delta S = \textrm{boundary term}$$, where the boundary terms are given by a variation (here the scaling) of the on-shell action (if i'm not misusing the term, by-on shell I'm trying to say that to go from (2) to (3) we used the E-L equation)? If this view is correct, I find it somewhat reminiscent of the Noether's theorem...