# Converting constrained Lagrangian to Hamiltonian form

Please correct me if I am wrong in the following. Let us say I have an unconstrained system with a Lagrangian $\bar L$ and a corresponding Hamiltonian $\bar H$.

$${{\dot x}_i} = {u_i}\qquad \quad i = 1,...,n$$

Let the cost functional be $J\left( x \right) = \int\limits_{{t_0}}^{{t_f}} {\bar L\left( {t,x,\dot x} \right)dt}$. It can be shown that the the above system satisfies Euler-Lagrange equation under optimality. From the canonical equations we have $$\dot p^* = - {{\bar H}_x^*} = {{\bar L}_x^*}$$ Then we use the fact that ${\bar H}$ has a stationary point with respect to $u^*$ and from there we get $p^* = {\bar L_{\dot x}^*}$ and so Euler-Lagrange is satisfied.

Now we introduce a set of constraints: \begin{align*} &{{\dot x}_i} = {f_i}\left( {t,{x_1},...,{x_n},{u_1},...,{u_{n - k}}} \right), & i = 1,...,k & \\ &{{\dot x}_{k + i}} = {u_i},& i=1,...,n-k& \end{align*}

I am trying to show that Euler-Lagrange still holds with the augmented Lagrangian.

$$\bar L\left( {t,x,\dot x} \right) + \sum\limits_{t = 1}^k {\lambda _i^*\left( t \right)\left( {{{\dot x}_i} - {f_i}\left( {t,{x_1},...,{x_b},{{\dot x}_{k + 1}},...,{{\dot x}_n}} \right)} \right)}$$

and new Hamiltonian. I have got the Hamiltonian in the form, $$H = \left[ {\begin{array}{*{20}{c}} {{{\left( {p + \lambda } \right)}^T}}&p^T \end{array}} \right]\left[ {\begin{array}{*{20}{c}} f \\ u \end{array}} \right] - \bar L + {\lambda ^T}\dot x$$

I can see that canonical equation ${{\dot x}^*} = {H_p}^*$ still holds and have derived the second one as, $${{\dot p}^*} = {{\bar L}_x}^* - {\left( {{p^*} + {\lambda ^*}} \right)^T}{\left. {\frac{{\partial f}}{{\partial x}}} \right|^*}$$

but I am not quite sure how to proceed from here. The lone $\dot x$ term in the Hamiltonian feels very weird to me.

Given the system, we define the Hamiltonian as, $$H = {p_1}{f_1}\left( {{x_1},{x_2},u} \right) + {p_2}u - L\left( {{x_1},{x_2},{f_1}\left( {{x_1},{x_2},u} \right),u} \right)$$ and so the canonical equations give us, $$\frac{{\partial H}}{{\partial u}} = {p_1}\frac{{\partial {f_1}}}{{\partial u}} + {p_2} - \frac{{\partial L}}{{\partial {f_1}}}\frac{{\partial {f_1}}}{{\partial u}} - \frac{{\partial L}}{{\partial u}} \equiv 0$$ along with $${{\dot p}_1} = - {p_1}\frac{{\partial {f_1}}}{{\partial {x_1}}} + \frac{{\partial L}}{{\partial {x_1}}} + \frac{{\partial L}}{{\partial {f_1}}}\frac{{\partial {f_1}}}{{\partial {x_1}}}\quad {\text{and }}\quad {{\dot p}_2} = - {p_1}\frac{{\partial {f_1}}}{{\partial {x_2}}} + \frac{{\partial L}}{{\partial {x_2}}} + \frac{{\partial L}}{{\partial {f_1}}}\frac{{\partial {f_1}}}{{\partial {x_2}}}$$ Note that from the augmented Langrangian we have, $${{\bar L}_{{x_1}}} = {L_{{x_1}}} - \lambda \frac{{\partial {f_1}}}{{\partial {x_1}}}\qquad {\text{and }}\qquad {{\bar L}_{{{\dot x}_1}}} = {L_{{{\dot x}_1}}} - \lambda$$ To satisfy E-L we need, $$\frac{d}{{dt}}\left( {{{\bar L}_{{{\dot x}_1}}}} \right) = {{\bar L}_{{x_1}}}$$ and so we set $\lambda = - {p_1} + {L_{{{\dot x}_1}}}$. Then ${{\bar L}_{{{\dot x}_1}}} = {L_{{{\dot x}_1}}} - \lambda = {L_{{{\dot x}_1}}} - \left( { - {p_1} + {L_{{{\dot x}_1}}}} \right) = {p_1}$. So, $$\frac{d}{{dt}}\left( {{{\bar L}_{{{\dot x}_1}}}} \right) = {{\dot p}_1} = - {p_1}\frac{{\partial {f_1}}}{{\partial {x_1}}} + \frac{{\partial L}}{{\partial {x_1}}} + \frac{{\partial L}}{{\partial {f_1}}}\frac{{\partial {f_1}}}{{\partial {x_1}}} = - {p_1}\frac{{\partial {f_1}}}{{\partial {x_1}}} + {L_{{x_1}}} + {L_{{{\dot x}_1}}}\frac{{\partial {f_1}}}{{\partial {x_1}}}$$ and we also have, $${{\bar L}_{{x_1}}} = {L_{{x_1}}} - \lambda \frac{{\partial {f_1}}}{{\partial {x_1}}} = {L_{{x_1}}} - \left( {{p_1} + {L_{{{\dot x}_1}}}} \right)\frac{{\partial {f_1}}}{{\partial {x_1}}} = {L_{{x_1}}} - {p_1}\frac{{\partial {f_1}}}{{\partial {x_1}}} + {L_{{{\dot x}_1}}}\frac{{\partial {f_1}}}{{\partial {x_1}}}$$
To see that the second E-L equation is also satisfied we note from the canonical equation that it can be written as, $$\frac{{\partial H}}{{\partial u}} = {p_1}\frac{{\partial {f_1}}}{{\partial u}} + {p_2} - \frac{{\partial L}}{{\partial {f_1}}}\frac{{\partial {f_1}}}{{\partial u}} - \frac{{\partial L}}{{\partial u}} = {p_1}\frac{{\partial {f_1}}}{{\partial {{\dot x}_2}}} + {p_2} - {L_{{{\dot x}_1}}}\frac{{\partial {f_1}}}{{\partial {{\dot x}_2}}} - {L_{{{\dot x}_2}}} \equiv 0$$
Then we note by comparison that $${{\bar L}_{{{\dot x}_2}}} = {L_{{{\dot x}_2}}} + \left( { - {p_1} + {L_{{{\dot x}_1}}}} \right)\frac{{\partial {f_1}}}{{\partial {{\dot x}_2}}} = {L_{{{\dot x}_2}}} - {p_1}\frac{{\partial {f_1}}}{{\partial {{\dot x}_2}}} + {L_{{{\dot x}_1}}}\frac{{\partial {f_1}}}{{\partial {{\dot x}_2}}} = {p_2}$$ and so we need $\frac{d}{{dt}}\left( {{{\bar L}_{{{\dot x}_2}}}} \right) = {{\dot p}_2} = {{\bar L}_{{x_2}}}$ And that this is indeed the case is established because, $${{\bar L}_{{x_2}}} = {L_{{x_2}}} - \lambda \left( { - \frac{{\partial {f_1}}}{{\partial {x_2}}}} \right) = {L_{{x_2}}} + \lambda \frac{{\partial {f_1}}}{{\partial {x_2}}} = {L_{{x_2}}} + \left( { - {p_1} + {L_{{{\dot x}_1}}}} \right)\frac{{\partial {f_1}}}{{\partial {x_2}}} = {L_{{x_2}}} - {p_1}\frac{{\partial {f_1}}}{{\partial {x_2}}} + {L_{{{\dot x}_1}}}\frac{{\partial {f_1}}}{{\partial {x_2}}}$$ which is $\dot p_2$ as we can see by comparing with previous canonical equation.