When can an autonomous system be written using a Hamiltonian? If I have an autonomous series of differential equations
$$\tag{1} \frac{dx_i}{dt} ~=~ A_i(x_1,...,x_n)$$
with the condition that
$$\tag{2} \sum_{i=1}^n\frac{\partial A_i}{\partial x_i}~=~0$$
in all regions of phase space, can this be written as a Hamiltonian system in terms of some generalized position and momentum coordinates?
 A: *

*Let there be given an $n$-dimensional manifold $M$ with a smooth vector field $X\in \Gamma(TM)$.


*If $(x^1, \ldots, x^n)$ is some local coordinates on $M$, then the vector field takes the form
$$\tag{A} X~=~X^i(x)\frac{\partial}{\partial x^i},$$ and one may study the  autonomous first-order ODE
$$\tag{B} \frac{dx^i(t)}{dt}~=~ X^i(x(t)).$$
Note that the ODE (B) transforms covariantly under change of coordinates.


*If $X$ does not vanish in a point $p\in M$, then one may choose a local coordinate neighborhood $U\subseteq M$ of $p$, with local coordinates $(y^1, \ldots, y^n)$, so that
$$\tag{C} X~=~\frac{\partial}{\partial y^1}.$$
This procedure is sometimes called stratification or straightening out of a vector field. It is a special case of Frobenius theorem.


*The ODE (B) then becomes
$$\tag{D} \frac{dy^i}{dt}~=~ \delta^i_1$$
in the local coordinate neighborhood $U\subseteq M$.


*If one chooses the Poisson bracket in the obvious way, i.e.
$$\tag{E}\{y^i,y^2\}_{PB}~=~\delta^i_1,\qquad \text{etc},$$
then one may bring the ODE (D) on Hamiltonian form
$$ \tag{F} \frac{dy^i}{dt}~=~ \{ y^i, y^2\}_{PB}$$
in the local coordinate neighborhood $U\subseteq M$.


*If the dimension $n$ is even, then the Poisson bracket (E) can be chosen to be non-degenerate.


*The question of the existence of a global Hamiltonian formulation is much more subtle, even for $n=2$. See also e.g. this and this related Phys.SE posts.
