# Hamiltonian mechanics really useful for numerical integration? Lagrange equations can become 1st-order by introducing extra variables

(I'm talking about the classical mechanics.)

Many texts say that Lagrange equations are difficult to treat numerically because they are second-order ODEs, $${f_i(\boldsymbol{q, \dot{q}, \ddot{q}}}) = 0$$, and Hamilton equations are (at least computationally) great because they are first-order, or their forms are essentially $${\dot{p_i}=g_i(\boldsymbol{p, q})}$$ and $$\dot{q_i}=h_i(\boldsymbol{p, q})$$.

I wonder if this statement is really valid? We can easily convert the Lagrange equations to first-order by, as a common technique, defining the new independent variables $$v_i:=\dot{q_i}$$.

Right, then we have to first solve the Lagrange equations for $$\ddot{q_i}$$ algebraically so that the equation can become $$\dot{q_i}=v_i$$ and $$\dot{v_i}=(solved\ as\ \ddot{q_i})$$. People say this is difficult and thus Hamilton's formalism is awesome.

However, in the process of Legendre transformation from Lagrangian $$L$$ to Hamiltonian $$H$$, we have to determine $$\dot{q}$$ as $$\dot{q}(\boldsymbol{p, q})$$ by algebraically solving the definitions $$p_i=\frac{\partial L}{\partial \dot{q_i}}$$ which is a system of equations.

So, in the both cases, we have to solve a set of algebraic equations anyway.

Is the latter solving process actually easier than the former in general? If there is, please give me an example where we can't use the former (Lagrange) but can use the latter (Hamilton) to make it first-order.

Comments to the question (v8) concerning numerical integration:

1. On one hand, to solve a Hamiltonian system numerically, there exist the numerical integration schemes of symplectic integrators (SI), where each (finite) numerical iteration step is a canonical transformation/symplectomorphism, which preserves certain properties, such as, e.g., energy, and which makes SIs suitable to solve long-term evolution problems numerically.

2. On the other hand, transforming a 2nd-order coupled ODE system $$\ddot{q}^i~=~f^i(q,\dot{q},t)\tag{1}$$ into a 1st-order coupled ODE system $$\dot{v}^i~=~f^i(q,v,t), \qquad \dot{q}^i~=~v^i,\tag{2}$$ does not necessarily bring it on Hamiltonian form$$^1$$.

--

$$^1$$ If the Lagrangian is of the form $$L(q,v,t)=\frac{1}{2}mv^2-V(q,t)$$ so that momentum $$p=mv$$ is proportional to velocity, then the 1st-order system (2) is on Hamiltonian form. See also e.g. this Wikipedia page.

• +1 for symplectic integrators, they're the cat's pajamas. – korrok Mar 4 '15 at 6:49
• Thanks! I didn't know that such an integrator exists. – akai Mar 4 '15 at 9:54
• Probably worth mentioning that symplectic integrators can be derived in a Lagrangian setting as well, which I think undermines #1. – jnez71 Jan 19 at 23:38
• Thanks for the feedback. I updated the answer. – Qmechanic Jan 20 at 11:30

So, the nice thing about Lagrangian mechanics is generalized coordinates. The crummy thing about it is that you at least in principle need to know about variational calculus to understand why it works and how to get the equations of motion. Finally, Emmy Noether's theorem gives you a really generic sense for conservation laws.

The nice thing about Hamiltonian mechanics is that Hamilton's equations just are the equations of motion, and the whole thing has a very Newtonian look and feel to it. In addition, you get a tighter coupling to plain quantum mechanics and very simple proofs of some basic conservation laws, if you know what you're looking for.

It is true that if you are starting from generalized coordinates and you only know the Lagrangian then you have to do a lot of work to turn that into a Hamiltonian, derive momentums, etc. But that's not the "core" of Hamiltonian mechanics. Just like Lagrangian mechanics assumes that you have the Lagrangian, Hamiltonian mechanics just assumes that you have the Hamiltonian in terms of the positions and momenta of the particles.