What preconditions should be satisfied to make energy conservation law possible? Let us consider a system whose evolution is given by dependency of $N$-dimensional real-values vector on time: $\vec r = \vec r (t)$ (or in terms of components $x_i = x_i (t)$).
Let us also assume that second order derivative of the vector depends on $\vec r$:
$$
\ddot {\vec r} = \vec f(\vec r),
$$
or in terms of the components:
$$
\ddot x_i = f_i(x_1, x_2, \dots, x_N).
$$
Can we show that in this case, there is some function of $\vec r$ and $ \dot {\vec r}$ that will be constant in time no meter what initial conditions we started from?
$$
E(\vec r, \dot {\vec r}) = \text{const}
$$
I am obviously trying to make an analogy with the energy conservation law of classical mechanics. So, in the end we probably need to show that
$$
E(\vec r, \dot {\vec r}) = T(\dot {\vec r}) + V(\vec r).
$$
 A: I hope my answer it's not too basic, I also hope I am not overlooking something..
You have a generic system (which may not even have any obvious physical interpretation) of $N$ second-order ODEs,
$$
\ddot{x}_i = f_i(x_1...x_N) \, .
$$
This can be written as $2N$ equations,
$$
\dot{x}_i = p_i
\\
\dot{p}_i = f_i(x_1...x_N)
$$
Now, for the system to be Hamiltonian, you have to be able to write it as
$$
\dot{x}_i = \partial_{p_i} H
\\
\dot{p}_i = -\partial_{x_i} H
$$
This is possible only if $f$ is such that
$$
\partial_{x_i} H = -f_i \, .
$$
In order to find $H$, notice that it should also be true that
$$
\partial_{p_i} H = p_i \, ,
$$
so that, if you assume that $H$ is separable (I am not sure if this is necessary, but it's the easy way) as $H= T(p) + V(x)$, you have
$$
H = \sum_i (p_i^2)/2 + V(x_1...x_N)
$$
It seems that only condition you have to ask is $f_i = -\partial_{x_i} V$, i.e. the force field is that gradient of something. If you are able to find the potential $V$ that generates $f_i$, then you can construct $H$ as $H=T+V$. Once you find $H$ you are guaranteed that the value $E$ of $H$ (defined by the initial conditions) is conserved (because you have no explicit time into $f_i$).
