[step:Write the Legendre transform and Hamiltonian in local coordinates]
Let $t_0 \in I$ be fixed. Choose a coordinate chart $(U,\varphi)$ on $Q$ with $q(t_0) \in U$, and restrict $I$ to a smaller open interval $J \subset I$ containing $t_0$ such that $q(J) \subset U$. Write the induced tangent bundle coordinates on $TQ|_U$ as $(q_1,\dots,q_n,\dot q_1,\dots,\dot q_n)$ and the induced cotangent bundle coordinates on $T^*Q|_U$ as $(q_1,\dots,q_n,p_1,\dots,p_n)$.
In these coordinates, the Legendre transform $\mathbb{F}L:TQ|_U \to T^*Q|_U$ is
\begin{align*}
p_i=\frac{\partial L}{\partial \dot q_i}(q,\dot q)
\end{align*}
for each $i \in \{1,\dots,n\}$. Since $\mathbb{F}L:TQ \to P$ is a diffeomorphism, its coordinate inverse on $P \cap T^*Q|_U$ gives smooth velocity functions
\begin{align*}
v_i:P \cap T^*Q|_U \to \mathbb{R}
\end{align*}
defined by
\begin{align*}
(\mathbb{F}L)^{-1}(q,p)=(q,v(q,p)).
\end{align*}
Thus, on $P \cap T^*Q|_U$, the Hamiltonian is
\begin{align*}
H(q,p)=\sum_{j=1}^n p_j v_j(q,p)-L(q,v(q,p)).
\end{align*}
[/step]