Boundary conditions for calculus of variations in phase space and under canonical transformations This might be a stupid question, but I just don't get it. In Hamiltonian mechanics when examining conditions for a $(\boldsymbol{q},\boldsymbol{p})\rightarrow(\boldsymbol{Q},\boldsymbol{P})$ transformation to be canonical one starts with
$$ \dot{q}_ip^i-H(\boldsymbol{q},\boldsymbol{p},t)= \dot{Q}_iP^i-\bar{H}(\boldsymbol{Q},\boldsymbol{P},t)+\frac{d}{dt}W(\boldsymbol{q},\boldsymbol{Q},t)$$
where $\bar{H}$ is the transformed Hamiltonian, and $W$ is the generating function (now a function of $\boldsymbol{q}$ and $\boldsymbol{Q}$). This term shouldn't break Hamilton's principle, since
$$ \delta\int_{t_1}^{t_2} dt\frac{d}{dt}W(\boldsymbol{q},\boldsymbol{Q},t)=\delta W(\boldsymbol{q},\boldsymbol{Q},t)|_{t_2}-\delta W(\boldsymbol{q},\boldsymbol{Q},t)|_{t_1}=0-0=0 .$$
But I don't see why the variation of $W$ should disappear at the endpoints (say at $t_1$). Expanding leads to:
$$ \delta W(\boldsymbol{q},\boldsymbol{Q},t)|_{t_1}=\left(\frac{\partial W}{\partial q_i}\right)_{t_1}\underbrace{\delta q_i(t_1)}_{=0}+ \left(\frac{\partial W}{\partial Q_i}\right)_{t_1}\delta Q_i(t_1)=\left(\frac{\partial W}{\partial Q_i}\right)_{t_1}\delta Q_i(t_1).$$
$\boldsymbol{Q}$ is itself a function of $\boldsymbol{q}$ and $\boldsymbol{p}$, so
$$ \delta Q_i(t_1)=\left(\frac{\partial Q_i}{\partial q_k}\right)_{t_1}\underbrace{\delta q_k(t_1)}_{=0}+\left(\frac{\partial Q_i}{\partial p_k}\right)_{t_1}\delta p_k(t_1)=\left(\frac{\partial Q_i}{\partial p_k}\right)_{t_1}\delta p_k(t_1). $$
It seems as if we also needed the variation of $\boldsymbol{p}$ to vanish at the endpoints, and I don't get this because (at least in cartesian coordinates) $\boldsymbol{p}=m\dot{\boldsymbol{q}}$ and the velocity can be different along the original and the varied orbitals even at the endpoints (they can point in totally different directions), so in general $\delta \dot{\boldsymbol{q}}(t_1)\neq 0$. What am I doing wrong? Can someone help me with this, please?
 A: These are very good questions.

*

*Let us start with the old phase space variables $(q^k,p_{\ell})$. The Hamiltonian action is
$$S_H~=~\int_{t_i}^{t_f} \! dt ~L_H, \qquad L_H~:=~\dot{q}^j p_j - H(q,p,t).\tag{A}$$
Its infinitesimal variation reads
$$ \delta S_H ~=~ \text{bulk-terms} ~+~ \text{boundary-terms},\tag{B}$$
where
$$\text{bulk-terms}~=~\int_{t_i}^{t_f} \! dt \left(\frac{\delta S_H}{\delta q^j}\delta q^j + \frac{\delta S_H}{\delta p_j}\delta p_j  \right)\tag{C}$$
yield Hamilton's equations, and where
$$\text{boundary-terms}~=~\left[p_j\underbrace{\delta q^j}_{=0} \right]_{t=t_i}^{t=t_f}~=~0\tag{D}$$
vanish as they should because of, say$^1$, essential/Dirichlet boundary conditions (BCs)
$$ q^j(t_i)~=~q^j_i\qquad\text{and}\qquad q^j(t_f)~=~q^j_f. \tag{E}$$
Notice that the momenta$^2$ $p_j$ are unconstrained at the boundary.


*Next let us consider new phase space variables $(Q^k,P_{\ell})$. The action of type 1 reads$^3$
$$S_1~:=~\int_{t_i}^{t_f} \! dt ~L_1~=~S_K+\left[ F_1(q,Q,t) \right]_{t=t_i}^{t=t_f}, \qquad S_K~:=~\int_{t_i}^{t_f} \! dt ~L_K, $$
$$ L_1~:=~L_K+\frac{dF_1(q,Q,t)}{dt}, \qquad L_K~:=~ \dot{Q}^j P_j - K(Q,P,t),\tag{F}$$
where the old positions $q^j=q^j(Q,P,t)$ are implicit functions of the new phase space variables $(Q^k,P_{\ell})$. Its infinitesimal variation reads
$$ \delta S_1 ~=~ \text{bulk-terms} ~+~ \text{boundary-terms},\tag{G}$$
where
$$\text{bulk-terms}~=~\int_{t_i}^{t_f} \! dt \left(\frac{\delta S_1}{\delta Q^j}\delta Q^j + \frac{\delta S_1}{\delta P_j}\delta P_j  \right)\tag{H}$$
yield Kamilton's equations, and where
$$\text{boundary-terms}~=~\left[\underbrace{\left(P_j+\frac{\partial F_1}{\partial Q^j}\right)}_{=0}\delta Q^j +\frac{\partial F_1}{\partial q^i}\underbrace{\delta q^j}_{=0} \right]_{t=t_i}^{t=t_f}~=~0\tag{I}$$
vanish as they should. One drawback is that it is non-trivial how to recast the Dirichlet BCs (E) in the new phase space variables $(Q^k,P_{\ell})$.
--
$^1$ Alternatively, one could impose natural BCs, or perhaps some mixture thereof.
$^2$ Note that in QM it would conflict with the HUP to simultaneously impose BCs on a canonical conjugate pair.
$^3$ Notation conventions: Kamiltonian $K\equiv\bar{H}$ and type 1 generating function $F_1\equiv G_1\equiv W$.
