### 5.19.2 Euler-Lagrange equation(s) : euler_lagrange

euler_lagrange takes from one to three arguments :

- expression f(x,y,y′),
- independent variable (optional, by default x),
- dependent variable (optional, by default y).

If y∈ℝn is required (by default n=1), one can enter y=(y1,y2,…,yn) as a vector [y1,y2,…,yn]. In that case, y′:=(y1′,y2′,…,yn′). Alternatively, one can specify two arguments, f and either y(x) or [y1(x),y2(x),…,yn(x)].

The return value is a system of differential Euler-Lagrange equations, which represent necessary conditions for extremum of the functional

F(y)= | ∫ |
b
a
| f(x,y,y′) d x, y∈ C2[a,b]

with boundary conditions y(a)=A and y(b)=B where A,B∈ℝ. If n=1, a single equation is returned :

∂ f
∂ y
| = |
d
d x
∂ f
∂ y′
| . (1)

If n>1, there are n Euler-Lagrange equations :

∂ f
∂ yk
| = |
d
d x
∂ 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 case n=1 and ∂ f/∂ t=0 to :

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

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

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

For example, input :

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

We obtain a system of two differential equations of order one :

⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ |
x′(t)
√ |
x′(t)2+y′(t)2
| =K0,
y′(t)
√ |
x′(t)2+y′(t)2
| =K1

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

In the following example we find the Euler-Lagrange equation for the brachistochrone problem, in which the functional

F(y)= |
1
√ |
2 g
| ∫ |
x1
0
√
1+y′(x)2
y(x)
| d x

for some function y≥ 0 such that y(0)=0 and y(x1)=h>0. It represents a curve alongside which an object travels, forced by the force of gravity (its vector pointing upwards), from the point (0,0) to the point (x1,h) in shortest possible time. To obtain the corresponding Euler-Lagrange equation, input :

assume(y>=0):; euler_lagrange(sqrt((1+y`'^`2)/y),t,y)

Output :

[-1/sqrt(y(t)*(1+diff(y(t),t)`^`2))=K_2, diff(y(t),t,2)=(diff(y(t),t)`^`2+1)/(2*y(t))]

It is easier to solve the first equation for y, since it is first-order and separable.

In the next example we minimize the functional F for 0<a<b and

f(x,y,y′)=x2 y′(x)2+y(x)2.

Input :

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

We obtain the following Euler-Lagrange equation :

y″= |
1
x2
| (y−2 x y′).

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

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

Output :

[-(sqrt(5)+1)/2,(sqrt(5)-1)/2]

Note that a pair of independent solutions is also returned by kovacicsols command :

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

Output :

[sqrt(x`^`(sqrt(5)-1)),sqrt(x`^`(-(sqrt(5))-1))]

Anyway, we 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 we prove that f is convex :

convex(f,y(x))

Output :

true

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

In the example below we find the function

y∈ | ⎧ ⎪ ⎨ ⎪ ⎩ | 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
| d x.

To obtain the corresponding Euler-Lagrange equation, input :

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

Output :

diff(y(x),x)/(sqrt(diff(y(x),x)`^`2+1)*x)=K_3

Input :

sol:=dsolve(eq)

Output :

[c_0-(sqrt(-K_3`^`2*x`^`2+1))/K_3]

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

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

Output :

[[1,0]]

Input :

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

Output :

-sqrt(1-x`^`2)

To prove that y0(x)=−√1−x2 is indeed a minimizer for F, we show that the integrand in F(y) is convex. Input :

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

Output :

x>=0

Hence the integrand is convex for x∈[1/2,1].

Similarly, we find the minimizer for

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

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

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

Output :

diff(y(x),x,2)=sin(x)

Input :

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

Output :

-sin(x)

The above function is the sought minimizer as the integrand f is convex :

convex(f,y(x))

Output :

true

In the next example we minimize the functional F(y)=∫01(y′(x)4−4 y(x)) d x on C1[0,1] with boundary conditions y(0)=1 and y(1)=2. First we solve the associated Euler-Lagrange equation :

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

Output :

[(3*diff(y(x),x)`^`4+4*y(x))=K_4, diff(y(x),x,2)=-1/(3*diff(y(x),x)`^`2)]

Input :

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

Output :

[-3*(-x+1.52832425067)`^`(4/3)/4+2.32032831141]

We find that the integrand in F(y) is convex :

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

Output :

true

Hence the minimizer is

y0(x)= |
3
4
| (1.52832425067−x)4/3+2.32032831141, 0≤ x≤ 1.