many textbooks tell me that Hamiltonians are constructed from Lagrangians like $$L=L(q,\dot{q})$$ with a Legendre transformation to obtain the Hamiltonian as $$H=\dot{q}\frac{\partial L}{\partial \dot{q}}-L$$ but none of the textbooks explain how this is done.

My specific problem is that I have Lagrangians that do not depend on $\dot{q}$ and therefore should have $\frac{\partial L}{\partial \dot{q}}=0$, hence $H=-L$. But my impression from the clues I have is that it is not that simple.

Let's say the Lagrangian is $$L(q)=\ln(q)-(2q-10)\lambda$$ Now as far as I know the Legendre transformation should give a function $f^*(p)=\sup(pq-L(q))$ (this implies $p=\frac{\partial L}{\partial q}$) which is obtained by substituting the stationary point $q_s$ of $\sup(pq-L(q))$ into $pq-L(q)$ thus getting $f^*(p)=pq_s-L(q_s)$ (for instance wikipedia's Legendre Transformation page explains this). Doing this for the example above: $$\frac{\partial (pq-L(q))}{\partial q}=\frac{\partial (pq-\ln(q)+(2q-10)\lambda)}{\partial q}=p-\frac{1}{q}+2\lambda$$ must be 0 for a stationary point, thus $q_s=1/(p+2\lambda)$. And hence the transformation should be $$f^*(p)=p\frac{1}{p+2\lambda}-\ln(\frac{1}{p+2\lambda})+(2\frac{1}{p+2\lambda}-10)\lambda$$

and this should be the Hamiltonian.

But this equation does obviously have nothing to do with the textbook Hamiltonian. Rather, an answer to another question has in a similar case treated $L(q)$ as being dependent on $\dot{q}$ implicitly (Writing $\dot{q}$ in terms of $p$ in the Hamiltonian formulation ... answer by Qmechanic). It mentions using the Dirac-Bergmann method for obtaining the Legendre transform.

Trying something along the lines of this other question the above example seems to give $$p=\frac{\partial L}{\partial \dot{q}}=0$$ and $$p \approx 0$$ (an equality modulo constraint as the answer to the question linked above says). And then $H=\dot{q}p-L$.

The difference seems to be that the Legendre transform is done with respect to two different variables, $q$ and $\dot{q}$ - but it was my understanding that it had to be done with respect to all variables the Lagrangian depends on. So how does the $qp_q$ term vanish if we have only the $\dot{q}p_{\dot{q}}$ term left?


edit: changed ln to \ln as Plane Waves suggested, and sup to \sup. And yes, sup is the supremum over all q, as Vibert said, sorry for forgetting to mention that.

  • 1
    $\begingroup$ Where did you get that Lagrangian? It has no actual dynamics... $\endgroup$
    – webb
    Commented Jun 11, 2013 at 23:00
  • 1
    $\begingroup$ It is a nonlinear programming Lagrangian similar to those you can see for instance here en.wikipedia.org/wiki/Lagrange_multiplier#Examples - basically it can be used for maximizing a target function $\ln(q)$ under the constraint $2q-10 \leq 0$ (the solution is obviously $q=5$). No it has no actual dynamics but a corresponding Hamiltonian must exist nevertheless and there must be a general way to obtain it no matter if the Lagrangian is actually dynamic or not. $\endgroup$
    – 0range
    Commented Jun 12, 2013 at 2:04
  • $\begingroup$ You can use Lagrangian and Hamiltonian formalism not only for physics but also for microeconomics, of course. As it has been already said here, the question is to treat the case as a functional (not as a mere function) and this will require to begin from a variational principle from an action. Most of these cases are not conservative, but eou can prove that inflation dp/dx>0 leads to value H dissipation. $\endgroup$ Commented Dec 1, 2022 at 12:50

3 Answers 3


The fact that $p = \large \frac{\partial L}{\partial \dot{q}} = 0$ introduces a problem in the equivalence between Lagrangian and Hamiltonian representations.

The idea is that the Hamiltonian representation plus the constraint $p = 0$ is equivalent to the Lagrangian representation

The Lagrangian $L$ is a function of $q$ and $\dot q$, that is $L(q, \dot q)$

If we work with the Lagrangian, we will apply the Euler-Lagrange equations which are :

$$\frac{\partial L}{\partial q} = \frac{d}{dt} \left(\frac{\partial L}{\partial \dot{q}}\right)$$

Because $\large \frac{\partial L}{\partial \dot{q}} = 0$, the equation is simply $\large \frac{\partial L}{\partial q} = 0$, that is $ \frac{1}{q} - 2\lambda = 0$, so $q = \frac{1}{2 \lambda}$

Now try to work with the Hamiltonian.

The Hamiltonian $H$ is a function of $q$ and $p$, that is $H(q, p)$

The link between the two is the Legendre transformation :

$$H=\dot{q}\frac{\partial L}{\partial \dot{q}}-L$$

Because your Lagrangian does not depends of $\dot q$, then $p = \frac{\partial L}{\partial \dot{q}} = 0$, and so :

$$H(q, p) = - L(q, \dot q) = - \ln(q) + (2q-10)\lambda$$

From this hamiltonian, you get the equations of movement :

$$\dot q = \frac{\partial H}{\partial p} ~,~\dot p = - \frac{\partial H}{\partial q}$$ So we have :

$$\dot q = 0~,~\dot p = \frac{1}{q} - 2\lambda \tag{1}$$

From this, we cannot recover the equation obtained from Euler-Lagrange equations, we have to add the constraint $p = 0$.

If $p = 0$, it means that $\dot p = 0$, and so :

$$q = \frac{1}{2 \lambda}\tag{2}$$

This is coherent with the fact that $\dot q = 0$

  • 1
    $\begingroup$ Trimok Why we have to add constraints with Hamiltonian representation to be equivalent the Lagrangian representation? What is/are physically or mathematically reason/s? Thank you very much for the answers. $\endgroup$
    – user30750
    Commented Oct 8, 2013 at 15:56
  • $\begingroup$ The OP Lagrangian here was very very special, because it depends only on $q$, so we have $p=0$. Now, passing to the hamiltonian $H(p,q)$, we have to keep this information $(p=0)$, if we want to recover the usual Euler-Lagrange equations $(2)$ (see also the beginning of the answer), from the hamiltonian relations $(1)$. I suppose a more rigorous answer would be based on the Legendre transformation $\endgroup$
    – Trimok
    Commented Oct 8, 2013 at 16:19
  • 2
    $\begingroup$ @user30750 If the derivative matrix of the Langrangian w.r.t. to velocities cannot be inverted (aka has eigenvector with eigenvalue 0) these have to be taken as primary constraints. $\endgroup$
    – lalala
    Commented Feb 22, 2017 at 10:16

Functions like yours are often referred to as "Lagrangians" in economic textbooks and such, but in the context of physics a Lagrangian is a functional, not just a function, and implies the concept of action, which in turn implies a dynamic situation. So you should probably avoid calling it a Lagrangian, at least when in earshot of physicists. Let's call your function $f(q)$ instead for now.

In the Legendre transformation that leads to the Hamiltonian, the argument of the Lagrangian is $\dot{q}$ and the argument of the Hamiltonian (i.e. the Legendre transformation) is $\frac{\partial L}{\partial \dot{q}}$ (or $p$)--which I think is called the canonical momentum conjugate to $q$. Both arguments are dynamic in nature.

In the case of a function (not functional) like yours, there is nothing dynamic happening, so better not to try to extrapolate from the derivation of the Hamiltonian. The Legendre transformation (call it $h$) is simply

$$h \left( m \right)=mq-f(q)$$

Where $m=\frac{df}{dq}$ and $q=q(m)$

This paper might help understand the Legendre transformation better.

  • 2
    $\begingroup$ The action is a functional, but it's perfectly fine to call the Lagrangian a function; actually, in case of first-order mechanics it should be a 1-form $L=\mathcal L\mathrm dt$ on the jet bundle $J^1Q$ of some configuration bundle $Q\to\mathbb R$, but if we don't care about generalizations, we can get away with considering the Lagrangian a function $\mathrm TM\times\mathbb R\to\mathbb R$ for $Q=M\times\mathbb R$ $\endgroup$
    – Christoph
    Commented Jun 12, 2013 at 9:21

What is "sup"? Please write "ln" with a backslash $\ln$. Anyway if $L$ is independent of a specific variable, then the canonically conjugate variable is conserved, which means that the energy function (the Hamiltonian) cannot explicitly depend on it. In your case $p_q$ should be conserved so your first intuition is correct: $$H=-L.$$

  • 2
    $\begingroup$ 'sup' means supremum (over all possible values of $q$). $\endgroup$
    – Vibert
    Commented Jun 11, 2013 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.