Is there a way to construct a Hamiltonian from a set of DE? Let's say I have a set of first-order differential equations for set of position $x_i$ and conjugate momenta $p_i$, which might be complicated and time-dependent
$$ \dot{x}_i = f_i(x_j,p_j,t)$$
$$ \dot{p}_i = g_i(x_j,p_j,t)$$
and I know that these equations originate from some Hamiltonian (that is, they respect conservation of phase-space volume, for example). Is there a constructive way to find said Hamiltonian? If not, what are the minimal conditions that the set of equation have to fulfill for this to happen? I mean I know that if the equations are linear and time-independent I can in general invert them and find $H$ in a straight-forward manner but what is the general case?
 A: Assuming from the notation 
$$ \dot{x}^i~=~f^i(x,p,t), \qquad \dot{p}_i~=~g_j(x,p,t), \tag{1}$$ 
that the symplectic structure is the standard canonical symplectic structure $$\omega = \sum_{i=1}^n\mathrm{d}p_i\wedge \mathrm{d}x^i,\tag{2}$$
we get that
$$\begin{align}\mathrm{d}H(x,p,t)- \frac{\partial H(x,p,t)}{\partial t}\mathrm{d}t
~=~&\sum_{i=1}^n\left(\frac{\partial H(x,p,t)}{\partial x^i}\mathrm{d}x^i+\frac{\partial H(x,p,t)}{\partial p_i}\mathrm{d}p_i\right)\cr
~=~&\sum_{i=1}^n\left(f^i(x,p,t)\mathrm{d}p_i-g_i(x,p,t)\mathrm{d}x^i\right). \end{align}\tag{3}$$
Now solve for $H(x,p,t)$, e.g.
$$ H(x,p,t)~=~H(0,0,t)+\int_0^1\!\mathrm{d}\alpha \sum_{i=1}^n\left(f^i(\alpha x,\alpha p,t)p_i-g_i(\alpha x,\alpha p,t)x^i\right).\tag{4} $$
A: Well, given
$$
\dot{p} = - \frac{\partial H}{\partial x}
\quad
\text{and}
\quad 
\dot{q} = \frac{\partial H}{\partial p}
$$
we have
$$
H = - \int dx_{i} \, g_{i}(x,p,t)
$$
and
$$ 
H = \int dp_i \, f_{i} (x, p, t).
$$
You deal with the constants of integration using the obvious constraint:
$$
- \int dx_{i} \, g_{i} (x, p, t)
= 
\int d p_{i} \, f_{i} (x, p, t)
$$
I guess the condition to find $H$ is whether we are able to solve these integrals or not. 
