Hamiltonian of coupled oscillators

Let's say I have a system of coupled oscillators which are described by the coordinates $\{x_1,...,x_N\}$ and $\{\dot{x}_1,...,\dot{x}_N\}$. The equation of motion for each oscillator is

$$\ddot{x}_n + \sum_m k_{nm} x_m = 0 .$$

What is the potential energy or alternatively the Hamiltonian of this system? I've only been able to find discussions of the case where all of the oscillators are connected in a straight line. I'm interested in the case of all to all coupling.

Edit: This isn't a hw exercise. Please don't mark it as such.

• Shouldn't the equation of motion have $k_{mn} (x_n-x_m)$? Or am I misunderstanding something? Oct 12 '15 at 15:56
• @Javier Isn't that just the case in which they are coupled end to end like this i.imgur.com/8m6wShX.jpg? I'm interested in the case of general connectivity. Oct 12 '15 at 15:58
• I mean with a sum over $m$. But your equation implies that the force on each oscillator is determined by the absolute positions of all the other oscillators, instead of the relative separations. The sum over $m$ is what makes all the oscillators be connected to each other. Oct 12 '15 at 16:03
• @Javier. That is correct. The force is determined by the absolute positions of the oscillators. Why would that be a problem? Oct 12 '15 at 16:29
• It's a weird situation. If the oscillators are joined together by springs, I would expect the forces to be proportional to the springs' extensions and thus to the relative separations, not to the absolute position of each oscillator. Oct 12 '15 at 16:37

Hamilton's equations are given by $$\dot x_n = \frac{\partial H}{\partial p_n}, \quad\text{and}\quad \dot p_n = -\frac{\partial H}{\partial x_n}.$$ Rewriting the second term using $p_n \equiv \dot x_n$ (using convention that the mass $m=1$) and the equation given in the question gives $$-\ddot x_n = \sum_m k_{nm}x_m = \frac{\partial V}{\partial x_n},$$ where we recognize that $\frac{\partial H}{\partial x_n} = \frac{\partial V}{\partial x_n},$ where $V$ is the potential. Solving this gives $$\int\frac{\partial V}{\partial x_n} {\text dx}_n = V_n = \sum_{m \ne n}k_{nm}x_mx_n + \frac{1}{2}k_{nn}x_n^2 = \sum_m k_{nm}x_mx_n - \frac{1}{2}k_{nn}x_n^2,$$ with a total potential energy of $$V = \sum_n V_n = \sum_{nm}k_{nm}x_m x_n - \frac{1}{2}\sum_n k_{nn}x_n^2.$$
For reference, in units where we include the mass $m$, the potential energy is (changing the labeling of the indexing so we don't use $m$) $$\boxed{V = m\sum_{jk}k_{jk}x_j x_k - \frac{m}{2}\sum_j k_{jj}x_j^2}.$$