euler_lagrange takes from one to three arguments :
If y∈ℝ^{n} is required (by default n=1), one can enter y=(y_{1},y_{2},…,y_{n}) as a vector [y_{1},y_{2},…,y_{n}]. In that case, y′:=(y_{1}′,y_{2}′,…,y_{n}′). Alternatively, one can specify two arguments, f and either y(x) or [y_{1}(x),y_{2}(x),…,y_{n}(x)].
The return value is a system of differential EulerLagrange equations, which represent necessary conditions for extremum of the functional
F(y)=  ∫ 
 f(x,y,y′) dx, y∈ C^{2}[a,b] 
with boundary conditions y(a)=A and y(b)=B where A,B∈ℝ. If n=1, a single equation is returned :
 = 

 . (1) 
If n>1, there are n EulerLagrange equations :
 = 

 , 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′ 
 f(x,y,y′)−f(x,y,y′) 
the EulerLagrange 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/dx H(y,y′,x)=0. Therefore the EulerLagrange 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 EulerLagrange equations minimizes the functional F.
For example, input :
^
2+y’(t)^
2),[x(t),y(t)])
We obtain a system of two differential equations of order one :

where K_{0},K_{1}∈ℝ are arbitrary (these constants are generated automatically).
In the following example we find the EulerLagrange equation for the brachistochrone problem, in which the functional
F(y)= 
 ∫ 


 dx 
for some function y≥ 0 such that y(0)=0 and y(x_{1})=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 (x_{1},h) in shortest possible time. To obtain the corresponding EulerLagrange equation, input :
'^
2)/y),t,y)
Output :
^
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 firstorder and separable.
In the next example we minimize the functional F for 0<a<b and
f(x,y,y′)=x^{2} y′(x)^{2}+y(x)^{2}. 
Input :
^
2*diff(y(x),x)^
2+y^
2:; eq:=euler_lagrange(f)
We obtain the following EulerLagrange equation :
y″= 
 (y−2 x y′). 
It can be solved by assuming y(x)=x^{r} for some r∈ℝ. Input :
^
r),r)
Output :
Note that a pair of independent solutions is also returned by kovacicsols command :
''
=(y2x*y’)/x^
2,x,y)
Output :
^
(sqrt(5)1)),sqrt(x^
((sqrt(5))1))]
Anyway, we conclude that y=C_{1} x^{−√5+1/2}+C_{2} x^{√5+1/2}. The values of C_{1} and C_{2} are determined from the boundary conditions. Finally we prove that f is convex :
Output :
Therefore, y minimizes F on [a,b].
In the example below we find the function
y∈  ⎧ ⎪ ⎨ ⎪ ⎩  y∈ C^{1}  ⎡ ⎢ ⎢ ⎣ 
 ,1  ⎤ ⎥ ⎥ ⎦  :y  ⎛ ⎜ ⎜ ⎝ 
 ⎞ ⎟ ⎟ ⎠  =− 
 ,y(1)=0  ⎫ ⎪ ⎬ ⎪ ⎭ 
which minimizes the functional
F(y)=  ∫ 

 dx. 
To obtain the corresponding EulerLagrange equation, input :
^
2)/x:; eq:=euler_lagrange(f)
Output :
^
2+1)*x)=K_3
Input :
Output :
^
2*x^
2+1))/K_3]
The sought solution is the function of the above form which satisfies the boundary conditions. Input :
Output :
Input :
Output :
^
2)
To prove that y_{0}(x)=−√1−x^{2} is indeed a minimizer for F, we show that the integrand in F(y) is convex. Input :
^
2)/x,y(x))
Output :
Hence the integrand is convex for x∈[1/2,1].
Similarly, we find the minimizer for
F(y)=  ∫ 
 ⎛ ⎝  2 sin(x) y(x)+y′(x)^{2}  ⎞ ⎠  dx 
where y∈ C^{1}[0,π] and y(0)=y(π)=0. Input :
^
2:; eq:=euler_lagrange(f)
Output :
Input :
Output :
The above function is the sought minimizer as the integrand f is convex :
Output :
In the next example we minimize the functional F(y)=∫_{0}^{1}(y′(x)^{4}−4 y(x)) dx on C^{1}[0,1] with boundary conditions y(0)=1 and y(1)=2. First we solve the associated EulerLagrange equation :
^
44y,x,y)
Output :
^
4+4*y(x))=K_4, diff(y(x),x,2)=1/(3*diff(y(x),x)^
2)]
Input :
Output :
^
(4/3)/4+2.32032831141]
We find that the integrand in F(y) is convex :
'^
44y,[x,y])
Output :
Hence the minimizer is
y_{0}(x)= 
 (1.52832425067−x)^{4/3}+2.32032831141, 0≤ x≤ 1. 