# Equations of motion for the n-body problem

The Lagrange function is defined as $\mathcal{L}(q,\dot{q}) = T(q,\dot{q}) - V(q,\dot{q})$ where $T$ defines the kinetic energy and $V$ the potential energy.

The equations of motion are given by $\frac{\partial \mathcal{L}}{\partial q_i} - \frac{d}{dt} \frac{\partial \mathcal{L}}{\partial \dot{q_i}} = 0$.

In the $n$-body problem we have $n$ planets with masses $m_1, \dots, m_n \in \mathbb{R}_+$. The kinetic and potential energy is given by

$T = \sum_i \frac{1}{2} m_i \Vert \dot{q_i} \Vert_2^2$ and $V = G \cdot \sum_{i<j} \frac{m_i m_j}{\Vert q_i - q_j \Vert_2}$ where $G$ denotes a gravitational constant. Furthermore, $q_i(t) \in \mathbb{R}^3$ decribes the position of the $i$-th planet at time $t$.

Now I need to calculate the equations of motions.

But now I do not understand how to deal with $\frac{\partial \mathcal{L}}{\partial q_i}$. The first thing which confuses me is that $q_i$ is a three-dimensional vector. The second thing would be the derivative of the norm because in calculus we have learned that the norm is not differentiable.

Could anyone explain this problem to me? Any help is really appreciated.

First off, your equation for $T$ is not quite correct. Recall that $T$ is the kinetic energy, which involves the velocity $\dot{q}$ of the particle! The correct equation is $$T = \frac{1}{2}\sum_{i} m_{i} \| \dot{q}_{i} \|^{2}.$$

Now let's look at the Euler Lagrange equations. You have to be very careful with indices here. The $i$-the particle in your system is represented by the vector $\vec{q}_{i}$. Let's agree to denote the $a$-th component of this vector by $q_{i,a}$. Thus $i$ runs from $1$ to $n$, and $a$ runs from $1$ to $3$. The Euler Lagrange equations now read $$\frac{\partial \mathcal{L}}{\partial q_{i,a}} - \frac{d}{dt} \frac{\partial \mathcal{L}}{\partial \dot{q}_{i,a}} = 0.$$ These are actually $3\times n$ equations, one for each combination of $i$ and $a$. Now to rewrite $T$ in a more usefull form. The square norm of $\dot{q}_{i}$ is given by $$\|\dot{\vec{q}}_{i}\|^{2} = \sum_{a=1}^{3} \dot{q}_{i,a}^{2}.$$ Substituting this in the expression for $T$ we obtain $$T = \frac{1}{2} \sum_{i=1}^{n} \sum_{a = 1}^{3} m_{i}\dot{q}_{i,a}^{2}.$$ A similar rewriting must be done for $V$. It is maybe a bit more complicated, but the idea is the same, so maybe it's good to try it before I explain more.

Now for your second issue, you are right that the norm is non-differentiable at zero. Note that in the expression for $T$ we are not talking about any norms, instead we are talking about the square of the norm, which is perfectly differentiable. In the expression for $V$, the situation is quite dire, we are not just talking about a norm, but even about the function $1/\|\vec{q}_{i} - \vec{q}_{j}\|$, which behaves even more poorly. I tink one simply assumes that $\vec{q}_{i} \neq \vec{q}_{j}$ for $i \neq j$...

• An alternative notation (but the same basic idea) is used in ocw.mit.edu/courses/aeronautics-and-astronautics/… which says to let $i$ range from $1$ to $3N$ to account for all the coordinates of $N$ bodies in three dimensions. – David K Apr 21 '17 at 12:48
• This is something you can do, but I think it's not so obvious how to rewrite the gravitational energy, $\sum_{i<j} 1/\|\vec{q}_{i} - \vec{q}_{j} \|$. – Peter Apr 21 '17 at 12:52
• True, we would be trading off more complexity in how we write $V$ (having to keep track of which three $q_i$ belong to each body) for a slight simplification of $T.$ Possibly the notes I linked to put this forward more as a conceptual aid (to resolve the "but $q_i$ is a vector!" misconception) than as a practical way to organize the equations. – David K Apr 21 '17 at 13:00
• Hey, thanks for your remark! Now I have corrected the formula for $T$. Next I tried to rewrite $V$ and received $V = G \sum_{i<j} \frac{m_i m_j}{\sqrt{\sum_{a=1}^3 (q_{i,a} - q_{j,a})^2}}$. The derivative $\frac{\partial T}{\partial q_{k,b}}$ is easily calculated as $m_k \dot{q_{k,b}}$. But how the heck can I candle $\frac{\partial V}{\partial q_{k,b}}$? This looks absolutely horrible... – Diglett Apr 21 '17 at 16:36
• I don't have much time to go into it right now, but I can say that it's not as bad as it looks, and that the chain rule is your friend. – Peter Apr 21 '17 at 16:48


Let me change your notation slightly. Let $q_\a$ be the set of coordinates we use to specify the positions $\bs{r}_i = \boldsymbol{r}_i(q)$ of the planets. Starting with Newton's law, if we introduce virtual work and change our philosophy we arrive at d'Alembert's principle, for which the equations of motion take the form $$\sum_i (\F_i - m \,\bs{a}_i) \cdot \delta \r_i \; = \; 0$$ where $\F_i$ is the force-on and $\bs{a}_i$ is the acceleration-of the $i$th planet. Setting the virtual displacements to $\delta \r_i = \sum_\a (\p\r_i \+ / \+ \p q_\a) \; \delta q_\a$ leads us to the set of $3n$ Lagrange's equations (see Goldstein sec. 1-4) $$\L_\a[T] = \; F_\a$$ where the generalized force $F_\a = \sum_i \F_i \! \cdot \! \pdx{\r_i}{q_\a}$, the kinetic energy $T = \sum_i \frac{1}{2} m_i \bs{v}_i \! \cdot \! \bs{v}_i$, and the Lagrange operator $\L_\a = \lagrange{}$. Let us use a non-script $L$ to denote the Lagrangian. In writing down the equations of motion, we can freely switch between using the forces $$\F_i = \sum_{j \; : \; j \neq i} \frac{ G \, m_i m_j \, (\r_j - \r_i)}{|\r_j - \r_i|^3}$$ and using the potential $$V = \sum_{i,j \; : \; i<j} \frac{-G \, m_i m_j}{|\r_j - \r_i|}$$ The equivalence stems from the fact that the forces can be written as the gradient $\F_i = -\nabla_i V$, which can be used to equate the generalized force to $\L[V]$ $$F_\a \;\; = \;\; \sum_i -\nabla_i V \! \cdot \! \pdx{\r_i}{q_\a} \;\; = \;\; -\pdx{V}{q_\a} \;\; = \;\; \L_\a[V]$$ Since $\L$ is a linear operator, we can combine $T$ and $V$ into the Lagrangian $L=T-V$ to arrive at the Euler-Lagrange equations of motion $$\L_\a[L] = 0$$ I often see people claim that Lagrange's or Hamilton's equations are inapplicable when there are forces present that cannot be written as a potential (eg. non-conservative forces). But there is nothing stopping us from leaving the corresponding generalized forces on the RHS. Now, if we want a more explicit expression for the equations of motion we need to choose coordinates. For simplicity, let's use Cartesian coordinates and assume that there are no constraints on the system $\{q_1, q_2, q_3, q_4, \ldots, q_{3n}\} \equiv \{x_1, y_1, z_1, x_2, \ldots, z_n \}$. Non-Cartesian coordinates are best handled with tensor notation -- which I'd rather not introduce in a Stack Exchange post. It is useful to see the vectors expanded out. $$\begin{array}{rcl} \r_i &=& q_{3i-2} \+ \bs{i} + q_{3i-1} \+ \bs{j} + q_{3i} \+ \bs{k} \\ \bs{v}_i &=& \qdot_{3i-2} \+ \bs{i} + \qdot_{3i-1} \+ \bs{j} + \qdot_{3i} \+ \bs{k} \\ \F_i &=& F_{i1} \+ \bs{i} + F_{i2} \+ \bs{j} + F_{i3} \+ \bs{k} \\ \end{array}$$ The positions only depend on three coordinates so the terms $\pdx{\r_i}{q_\a}$ are nonzero for only three values of $\alpha$ (for which they become $\bs{i}, \bs{j},$ or $\bs{k}$). It is not hard to see that $\L_\a[T]$ are the coordinate accelerations and that $F_\a$ are the force components. Thus, Lagrange's equations $\L_\a[T] = F_\a$ mirror Newton's law $$m_{i} \ddt{q}_{3i+j-3} = F_{ij}$$ where we identified $\a = 3i+j-3$ for convenience. We can condense these $3n$ equations down to $n$ vector equations $$m_{i} \bs{a}_i = \F_i$$ We've come full circle. Indeed, there is really no reason to introduce the Lagrangian at all because: one there are no constraints, two we are using Cartesian coordinates, and three we have explicit expressions for the forces.