# Trying to maximize $\int_a^b L(t,q(t),\dot{q}(t)) dt$ subject to $|\dot{q}(t)| = 1$

I am trying to find the differential equation which implies a smooth path $$q:[a,b] \rightarrow \mathbb{R}^n$$ subject to $$|\dot{q}(t)| = 1$$ (i.e. $$q$$ has unit speed) is a stationary point of $$\int_a^b L(t,q(t), \dot{q}(t)) \ dt$$ for a certain $$L(t,q(t), \dot{q}(t))$$. This question and answer here appears to be exactly what I need, but when I tried to apply their formula to an easy example, it didn't work. Did I make a mistake or is their formula wrong? The example I tried to apply it to is below.

Following the notation of their question, suppose $$F(x,y) = x^2+y^2$$ and $$g(x',y') = {x'}^2 + {y'}^2 -1 = 0$$ and $$x(0) = y(0) = 0$$. So you are trying to maximize $$\int_0^1 x(t)^2 + y(t)^2 dt \tag 1$$ subject to $$(x(t),y(t))$$ having unit speed. Because $$x(t)^2 + y(t)^2 \leq t^2$$, $$(1)$$ is less than $$\int_0^1 t^2 dt = 1/3$$. On the other hand, this maximal value is obtainable by having $$(x(t),y(t))$$ move in a straight line at unit speed. However their equation $$\frac{\partial F}{\partial x}-\frac{d}{dt}\frac{\partial F}{\partial x'}=\lambda(t)\left(\frac{\partial g}{\partial x}-\frac{d}{dt}\frac{\partial g}{\partial x'}\right) \tag 2$$ yields $$2x = -\lambda(t) 2x''.$$ Their other equation for $$y$$ yields
$$2y = -\lambda(t) 2y''.$$ When $$(x(t),y(t))$$ moves in a straight line at unit speed, $$x'' = y'' = 0$$. Their equations imply $$(x,y) = 0$$. So $$(x,y)$$ maximizing $$(1)$$ by moving in a line is not detected by their equations.

$$\textbf{Updated Question}$$: Is it mathematically justifiable to consider the modified Lagrangian $$L(t,q(t),\dot{q}(t)) + \lambda(t) g(q(t),\dot{q}(t))$$? I have been searching through books to find out if this is mathematically valid, and I can't find any proofs for this type of constraint.

By considering this modified the Lagrangian I derived the formula $$L_q(t,q(t),\dot{q}(t)) - \frac{d}{dt} L_{\dot{q}}(t,q(t), \dot{q}(t)) = - \lambda(t) g_q(q(t),\dot{q}(t)) + \frac{d}{dt} \big(\lambda(t) g_{\dot{q}}(q(t),\dot{q}(t)) \big)$$ which is different from $$(2)$$ due to $$\lambda(t)$$ being differentiated.

The problem is simpler in polar coordinates. The augmented Lagrangian, then, is given by $$L=r^2+\lambda(\dot{r}^2+r^2\dot{\theta}^2-1). \tag{1}$$ The correct Euler-Lagrange equations are$$^{(*)}$$ \begin{align} \frac{\partial L}{\partial r}-\frac{d}{dt}\left(\frac{\partial L}{\partial\dot{r}}\right)=0 &\implies \left(1+\lambda\dot{\theta}^2\right)r-\dot{\lambda}\dot{r}-\lambda\ddot{r}=0, \tag{2} \\ \frac{\partial L}{\partial \theta}-\frac{d}{dt}\left(\frac{\partial L}{\partial\dot{\theta}}\right)=0 &\implies \frac{d}{dt}(\lambda r^2\dot{\theta})=0 \implies \lambda r^2\dot{\theta}=C, \tag{3} \\ \frac{\partial L}{\partial \lambda}=0 &\implies \dot{r}^2+r^2\dot{\theta}^2-1=0. \tag{4} \end{align} The initial condition $$x(0)=y(0)=0$$, or $$r(0)=0$$, implies $$C=0$$ in Eq. $$(3)$$. There are, then, three possibilities:

1. $$r(t)=0$$: this is not consistent with Eq. $$(4)$$, which becomes $$\dot{r}^2=1$$;

2. $$\lambda(t)=0$$: Eq. $$(2)$$ then implies $$r(t)=0$$, which we have seen is not consistent with Eq. $$(4)$$;

3. $$\dot{\theta}=0$$: Eq. $$(4)$$ again becomes $$\dot{r}^2-1=0$$. Plugging the solution $$r(t)=t$$ (and $$\dot{\theta}=0$$) into Eq. $$(2)$$, we obtain an equation for $$\lambda(t)$$: $$t-\dot{\lambda}=0 \implies \lambda(t)=\lambda_0+\frac{t^2}{2}. \tag{5}$$

In conclusion, the solution to the maximization problem is the one expected, $$r(t)=t$$ --- or, in Cartesian coordinates, $$(x(t),y(t))=(t\cos\theta,t\sin\theta)$$.

$$^{(*)}$$ Compare with Eq. $$(2)$$ in the question, which missed the time derivative of $$\lambda(t)$$.

I think the problem is that you’re not actually solving a variational problem. You don’t mention the boundary conditions (and neither does the post you link to), and usually you don’t need to worry about boundary conditions in such problems, but in this case the boundary conditions of the global optimum that you’re considering (namely, that $$(x(1),y(1))$$ is a given unit vector) are such that the constraint $$x'^2+y'^2=1$$ only allows a single solution (namely $$(x(t),y(t))=t(x(1),y(1))$$). Thus, there are no other functions to compare against, so we shouldn’t expect a variational approach to work.

For other boundary conditions, with $$|(x(1),y(1)|\lt1$$, the optimal solution isn’t differentiable (it consists of a line segment that goes beyond $$(x(1),y(1))$$ and then a line segment that returns to $$(x(1),y(1))$$), so you can’t find it with a variational approach, either.

• If calculus of variations requires both endpoints of the path are specified, that is not good, because the endpoint is not known in the problem I am trying to apply calculus of variations to, only the start. In physics, the principle of least action does not specify the endpoint right? But doesn't that use the same calculus of variations formula? Commented Mar 5 at 8:38
• @StephenHarrison: You might find this answer and this physics.SE post it links to helpful. Commented Mar 5 at 8:52
• @StephenHarrison: As regards “that is not good, because the endpoint is not known”: If the endpoint isn’t known, you can optimize the functional for a variable endpoint and then optimize the resulting function of the endpoint. But that’s not what one typically does in physics. For instance, any straight or refracted light path is the solution of a variational problem; it’s not a problem that you don’t know where the light is going; you just get all the possible light paths from the variational approach. Commented Mar 5 at 8:56
• @StephenHarrison: Well, they don’t have a constraint and a Lagrange mutliplier. If you look at the derivation of the method of Lagrange multipliers, the constraint plays a similar role as the functional; you need integration by parts to move the derivative from the variation to the function as long as either the functional or the constraint contains $\dot q$. Commented Mar 5 at 9:09
• @StephenHarrison: You solved a different problem there. This is the solution of the problem where the integral of $g$ is constrained, not $g$ itself. In that case, $\lambda$ doesn’t actually depend on $t$ – a single constraint requires a single Lagrange multiplier, a continuous constraint requires a continuous Lagrange multiplier. Commented Mar 5 at 11:05

When the constraint is holonomous it can be represented by a regular function in the configuration space. Considering $$(x,y)$$ as representing the configuration space, then the holonomous constraint will read $$g(x,y)=0$$ as for example, $$x^2+y^2-r^2=0$$. A differentiated holonomous constraint, is still holonomous. Consider for instance the problem:

$$L = f(\dot x,\dot y, x, y)+\lambda (g_x\dot x+g_y\dot y)$$

The movement equations, after Euler-Lagrange, gave

$$\left\{ \begin{array}{rcl} x''(t) &=& -\frac{g_y \left(g_x \left(x'(t) f_{x y'}+f_{y y'} y'(t)-f_y\right)-g_y \left(y'(t) f_{y x'}+f_{x x'} x'(t)-f_x\right)\right)-\left(g_x f_{\left(y'\right)^2}-g_y f_{x' y'}\right) \left(x'(t) \left(g_{\text{xx}} x'(t)+g_{\text{xy}} y'(t)\right)+y'(t) \left(g_{\text{xy}} x'(t)+g_{\text{yy}} y'(t)\right)\right)}{2 g_x g_y f_{x' y'}-g_y^2 f_{\left(x'\right)^2}+g_x^2 \left(-f_{\left(y'\right)^2}\right)} \\ y''(t)&=& -\frac{-g_x g_{\text{xx}} x'(t)^2 f_{x' y'}+g_{\text{xx}} g_y f_{\left(x'\right)^2} x'(t)^2-2 g_x g_{\text{xy}} x'(t) y'(t) f_{x' y'}+2 g_{\text{xy}} g_y f_{\left(x'\right)^2} x'(t) y'(t)-g_x g_{\text{yy}} y'(t)^2 f_{x' y'}+g_y g_{\text{yy}} f_{\left(x'\right)^2} y'(t)^2+g_x^2 x'(t) f_{x y'}-g_x g_y y'(t) f_{y x'}-g_x g_y f_{x x'} x'(t)+g_x^2 f_{y y'} y'(t)-f_y g_x^2+f_x g_x g_y}{-2 g_x g_y f_{x' y'}+g_y^2 f_{\left(x'\right)^2}+g_x^2 f_{\left(y'\right)^2}} \\ \lambda'(t)&=& -\frac{g_{\text{xx}} x'(t)^2 f_{x' y'}^2-g_{\text{xx}} f_{\left(x'\right)^2} f_{\left(y'\right)^2} x'(t)^2+2 g_{\text{xy}} x'(t) y'(t) f_{x' y'}^2-2 g_{\text{xy}} f_{\left(x'\right)^2} f_{\left(y'\right)^2} x'(t) y'(t)+g_{\text{yy}} y'(t)^2 f_{x' y'}^2-g_{\text{yy}} f_{\left(x'\right)^2} f_{\left(y'\right)^2} y'(t)^2-g_x x'(t) f_{x y'} f_{x' y'}-g_y f_{x x'} x'(t) f_{x' y'}-g_x f_{y y'} y'(t) f_{x' y'}-g_y y'(t) f_{y x'} f_{x' y'}+g_x f_{x x'} f_{\left(y'\right)^2} x'(t)+g_y f_{\left(x'\right)^2} x'(t) f_{x y'}+g_x f_{\left(y'\right)^2} y'(t) f_{y x'}+g_y f_{\left(x'\right)^2} f_{y y'} y'(t)+f_y g_x f_{x' y'}+f_x g_y f_{x' y'}-f_y g_y f_{\left(x'\right)^2}-f_x g_x f_{\left(y'\right)^2}}{-2 g_x g_y f_{x' y'}+g_y^2 f_{\left(x'\right)^2}+g_x^2 f_{\left(y'\right)^2}} \\ \end{array} \right.$$

as can be observed, the configuration space movement can be obtained without $$\lambda(t)$$ intervention. Now if the constraint is not integrable (nonholonomous) then, the movement will depend on $$\lambda(t)$$.

The focused problem in the OP is non-holonomous, therefore we should expect problems on the way to it's solution. Consider the lagrangian

$$L = x^2+y^2+\lambda(x'^2+y'^2-1)$$

with $$x,y,\lambda$$ functions of $$t$$, the Euler-Lagrange give us

$$\cases{ \lambda' x'+\lambda x''-x=0\\ \lambda' y'+\lambda y''-y=0 }$$

now deriving the restriction and including as a third equation we have

$$\cases{ \lambda' x'+\lambda x''-x=0\\ \lambda' y'+\lambda y''-y=0\\ x'x''-y'y'' = 0 }$$

so we can solve for $$x'',y'',\lambda '$$ and equivalently we arrive at

$$\cases{ x' = v_x\\ y' = v_y\\ v_x' = \frac{v_y(v_y x- v_x y)}{\lambda(v_x^2+v_y^2)}\\ v_y' = -\frac{v_x(v_y x- v_x y)}{\lambda(v_x^2+v_y^2)}\\ \lambda' = \frac{v_x x+v_y y}{v_x^2+v_y^2} }$$

but $$v_x^2+v_y^2=1$$ so the movement equations are

$$\cases{ x' = v_x\\ y' = v_y\\ v_x' = \frac{v_y(v_y x- v_x y)}{\lambda}\\ v_y' = \frac{v_y(v_x y-v_y x)}{\lambda}\\ \lambda' = v_x x+v_y y }$$

now we have $$5$$ boundary conditions. If we choose boundary conditions, the problem has solutions $$x_{\lambda}(t),y_{\lambda}(t)$$ because the movement equations depend on $$\lambda$$. Follows a MATHEMATICA script to verify that.

L = x[t]^2 + y[t]^2 + lambda[t] (x'[t]^2 + y'[t]^2 - 1);
equ2 = D[x'[t]^2 + y'[t]^2 - 1, t];
equs = Join[equ1, {equ2}];
sol = Solve[equs == 0, {x''[t], y''[t], lambda'[t]}][[1]] /. {x'[t] -> vx[t], y'[t] -> vy[t]};

tmax = 2;
GR = {};
pts = {{0, 1}, {2, -1}};
For[k = 0.6, k <= 6, k++,
odes = Thread[{vx'[t], vy'[t], lambda'[t]} == ({x''[t], y''[t], lambda'[t]} /. sol) (vx[t]^2 + vy[t]^2)] // Simplify;
condb = {x[0] == 0, y[0] == 1, x[tmax] == 2, y[tmax] == -1, lambda[0] == k};
cinits = condb;
odes0 = Join[Join[odes, {x'[t] == vx[t], y'[t] == vy[t]}], cinits];
solode = NDSolve[odes0, {x, y, vx, vy, lambda}, {t, 0, tmax} [[1]];
xtyt = Evaluate[{x[t], y[t]} /. solode];
gr0 = Graphics[{Red, PointSize[0.02], Point[pts]}];
gr = ParametricPlot[xtyt, {t, 0, tmax}];
AppendTo[GR, gr]]

Show[GR, gr0, PlotRange -> All]


In the plot is depicted the diverse solutions to the boundary problem $$(x_{t_i} = 0, y_{t_i} = 1), (x_{t_f}= 2, y_{t_f}= -1)$$ with $$t_i = 0, t_f = 2$$. By choosing values to lambda[0] to the boundary conditions problem. The script solves the Euler-Lagrange, for diverse (lambda[0] = k).