The Hamiltonian is defined as the sum of the product of momenta and velocities minus the Lagrangian, expressed as ##\mathcal{H} \equiv \sum_{i}^{all} p_{i} \dot{q}_{i} - \mathcal{L}##. It is considered a function of the generalized coordinates ##q## and momenta ##p## rather than velocities ##\dot{q}##. To achieve this representation, a change of variables is necessary to express ##\dot{q}## in terms of ##p## and ##q##. This transformation is crucial for the transition from Lagrangian to Hamiltonian mechanics. Understanding this relationship is essential for grasping the fundamentals of Hamiltonian dynamics.