Euler-Lagrange equations

### 13.8.2 Euler-Lagrange equations

The Euler-Lagrange equations for a Lagrangian function f(x,y,y′) are differential equations which must be satisfied by extrema of the functional F(y).

The euler_lagrange command finds the Euler-Lagrange equations for a Lagrangian f.

- euler_lagrange takes one mandatory argument and two optional arguments:
  - expr, an expression involving an independent variable, a dependent variable, and the dependent variable derivative.
  - Optionally, indvar, the independent variable (by default x).
  - Optionally, depvar, the dependent variable (by default y).

    If a function y∈ℝn is required (by default n=1), you can enter y=(y1,y2,…,yn) as a vector [y1,y2,…,yn]. In that case, y′=(y1′,y2′,…,yn′).

  An alternate way to specify the independent and dependent variables is by replacing both optional arguments by either, for example, y(x) or [y1(x),y2(x),…,yn(x)].
- euler_lagrange(expr ⟨,indvar,depvar ⟩) returns the system of differential Euler-Lagrange equations.

  For n=1, a single equation is returned: ∂ f/∂ y=d/dx ∂ f/∂ y′ .

  In general, n equations are returned: ∂ f/∂ yk=d/dx ∂ f/∂ yk′, k=1,2,…,n.

The degrees of these differential equations are kept as low as possible. If, for example, ∂ f/∂ y=0, the equation ∂ f/∂ y′=K is returned, where K∈ℝ is an arbitrary constant. Similarly, using the Hamiltonian

H(x,y,y′)=y′ |
∂
∂ y′
| f(x,y,y′)−f(x,y,y′)

the Euler-Lagrange equation is simplified in the case n=1 and ∂ f/∂ t=0 to:

H(x,y,y′)=K, (3)

since it can be shown that d/dx H(y,y′,x)=0. Therefore the Euler-Lagrange equations, which are generally of order two in y, are returned in a simpler form of order one in the aforementioned cases. If n=1 and ∂ f/∂ x=0, then both equations are returned, each of them being sufficient to determine y (one of the returned equations is usually simpler than the other).

#### Examples

Minimize the functional F for 0<a<b and f(x,y,y′)=x2 y′(x)2+y(x)2.

eq:=euler_lagrange(x^2*diff(y(x),x)^2+y^2)

d2
dx2
| y | ⎛ ⎝ | x | ⎞ ⎠ | = |
−2 |
d
dx
| y | ⎛ ⎝ | x | ⎞ ⎠ | x+y | ⎛ ⎝ | x | ⎞ ⎠
x2

This can be solved by assuming y(x)=xr for some r∈ℝ.

solve(subs(eq,y(x)=x^r),r)

| ⎡ ⎢ ⎢ ⎣ | − |
√ |
5
| +1
2
| ,− |
− | √ |
5
| +1
2
| ⎤ ⎥ ⎥ ⎦

The same pair of solutions is also returned by the kovacicsols command (see Section 13.4.3):

assume(x>=0):; kovacicsols(y''=(y-2x*y')/x^2,x,y)

| ⎡ ⎢ ⎢ ⎢ ⎣ |
√
x |
√ |
5
| −1
| , |
√
x |
− | √ |
5
| −1
| ⎤ ⎥ ⎥ ⎥ ⎦

You can conclude that y=C1 x−√5+1/2+C2 x√5+1/2. The values of C1 and C2 are determined from the boundary conditions. Finally, to prove that f is convex:

convex(x^2*diff(y(x),x)^2+y^2,y(x))

true |  |  |  |  |  |  |  |  |  |

Therefore, y minimizes F on [a,b].

Find the function y in {y∈ C1[1/2,1]:y(1/2)=−√3/2, y(1)=0} which minimizes the functional

F(y)= | ∫ |
1
1/2
√ |
1+y′(x)2
x
| dx.

To obtain the corresponding Euler-Lagrange equation:

eq:=euler_lagrange(sqrt(1+diff(y(x),x)^2)/x)

d
dx
| y | ⎛ ⎝ | x | ⎞ ⎠
x |
√
⎛ ⎜ ⎜ ⎝ |
d
dx
| y | ⎛ ⎝ | x | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
2
| +1
| =K2

sol:=dsolve(eq)

| ⎡ ⎢ ⎢ ⎣ | − |
√ |
−K32 x2+1
K3
| +c0 | ⎤ ⎥ ⎥ ⎦

The sought solution is the function of the above form which satisfies the boundary conditions.

y0,c:=sol[0],[K_3,c_0]:; v:=solve([subs(y0,x=1/2)=-sqrt(3)/2,subs(y0,x=1)=0],c)

⎡ ⎣ |
1 | 0
| ⎤ ⎦

y0:=normal(subs(y0,c,v[0])

− | √ |
−x2+1

If the integrand in F(y) is convex, then y0(x)=−√1−x2 is a minimizer for F. Indeed:

convex(sqrt(1+y'^2)/x,y(x))

| ⎡ ⎣ | x≥ 0 | ⎤ ⎦

You can similarly find the minimizer for

F(y)= | ∫ |
π
0
| ⎛ ⎝ | 2 sin(x) y(x)+y′(x)2 | ⎞ ⎠ | dx

where y∈ C1[0,π] and y(0)=y(π)=0.

eq:=euler_lagrange(2*sin(x)*y(x)+diff(y(x),x)^2)

d2
dx2
| y | ⎛ ⎝ | x | ⎞ ⎠ | =sinx

dsolve(eq and y(0)=0 and y(pi)=0,x,y)

−sinx |  |  |  |  |  |  |  |  |  |

The above function is the sought minimizer as the integrand 2 sin(x) y(x)+y′(x)2 is convex:

convex(2*sin(x)*y(x)+diff(y(x),x)^2,y(x))

true |  |  |  |  |  |  |  |  |  |

Minimize the functional F(y)=∫01(y′(x)4−4 y(x)) dx on C1[0,1] with boundary conditions y(0)=1 and y(1)=2.

First, solve the associated Euler-Lagrange equation:

eq:=euler_lagrange(y'^4-4y,x,y)

| ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ | 3 | ⎛ ⎜ ⎜ ⎝ |
d
dx
| y | ⎛ ⎝ | x | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
4
| +4 y | ⎛ ⎝ | x | ⎞ ⎠ | =K6, |
d2
dx2
| y | ⎛ ⎝ | x | ⎞ ⎠ | =− |
1
3 | ⎛ ⎜ ⎜ ⎝ |
d
dx
| y | ⎛ ⎝ | x | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
2
| ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦

dsolve(eq[1] and y(0)=1 and y(1)=2,x,y)

| ⎡ ⎢ ⎢ ⎣ | − |
3
4
|  | ⎛ ⎝ | −x+1.52832425067 | ⎞ ⎠ |
4
3
| +2.32032831141 | ⎤ ⎥ ⎥ ⎦

Next, check if the integrand in F(y) is convex:

convex(y'^4-4y,[x,y])

true |  |  |  |  |  |  |  |  |  |

Hence the minimizer is y0(x)=−3/4 (1.52832425067−x)4/3+2.32032831141, 0≤ x≤ 1.

Find Euler-Lagrange equations for a bivariate functional F:

euler_lagrange(sqrt(x'(t)^2+y'(t)^2),[x(t),y(t)])

| ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ |  |
d
dt
| x | ⎛ ⎝ | t | ⎞ ⎠
√
⎛ ⎜ ⎜ ⎝ |
d
dt
| x | ⎛ ⎝ | t | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
2
| + | ⎛ ⎜ ⎜ ⎝ |
d
dt
| y | ⎛ ⎝ | t | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
2
| =K0, |
d
dt
| y | ⎛ ⎝ | t | ⎞ ⎠
√
⎛ ⎜ ⎜ ⎝ |
d
dt
| x | ⎛ ⎝ | t | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
2
| + | ⎛ ⎜ ⎜ ⎝ |
d
dt
| y | ⎛ ⎝ | t | ⎞ ⎠ | ⎞ ⎟ ⎟ ⎠ |
2
| =K1 | ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦

where K0,K1∈ℝ are arbitrary constants (note that these symbols are generated automatically).

It can be proven that if f is convex (as a function of three independent variables, see Section 13.7.8), then a solution y to the Euler-Lagrange equations minimizes the functional F.