Previous Up Next

6.22.2 Euler-Lagrange equation(s): euler_lagrange

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. The function f can be given in one of two ways. For the first way:

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, (2)

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 ‍(1) and ‍(2) are returned, each of them being sufficient to determine y (one of the returned equations is usually simpler than the other).


Example.
Input:

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

Output

⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎣
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 (these constants are generated automatically).


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


Example.
Minimize the functional F for 0<a<b and

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

Input:

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

Output:

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∈ℝ.
Input:

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

Output:

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

Note that a pair of independent solutions is also returned by the kovacicsols command (see Section ‍6.57.3):
Input:

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

Output:

⎡
⎢
⎢
⎢
⎣
√
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:
Input:

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

Output:

true

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


Example.
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:
Input:

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

Output:

d
dx
y⎛
⎝
x⎞
⎠
x 
√
⎛
⎜
⎜
⎝
d
dx
y⎛
⎝
x⎞
⎠
⎞
⎟
⎟
⎠
2



 
+1
=K2

Input:

sol:=dsolve(eq)

Output:

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

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:

⎡
⎣
10
⎤
⎦

Input:

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

Output:

−√
−x2+1

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

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

Output:

⎡
⎣
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.
Input:

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

Output:

d2
dx2
y⎛
⎝
x⎞
⎠
=sinx

Input:

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

Output:

  −sinx

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

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

Output:

true


Example.
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:
Input:

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

Output:

⎡
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎢
⎣
3 ⎛
⎜
⎜
⎝
d
dx
y⎛
⎝
x⎞
⎠
⎞
⎟
⎟
⎠
4



 
+4 y⎛
⎝
x⎞
⎠
=K6,
d2
dx2
y⎛
⎝
x⎞
⎠
=−
1
3 ⎛
⎜
⎜
⎝
d
dx
y⎛
⎝
x⎞
⎠
⎞
⎟
⎟
⎠
2



 
⎤
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎥
⎦

Input:

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

Output:

⎡
⎢
⎢
⎣
−
3
4
 ⎛
⎝
−x+1.52832425067⎞
⎠
4
3
 
+2.32032831141⎤
⎥
⎥
⎦
[-3*(-x+1.52832425067)^(4/3)/4+2.32032831141]

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

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. 

Previous Up Next