Skip to main content
Minor improvements
Source Link

The following SymPy script

from sympy import *

x = Symbol('x')
f = Function('f')(x)

# define Lagrangian
L = (sin(x))**2 * (3 + 2*((sin(f))**2/(sin(x))**2) + (Derivative(f,x))**2)**2

# Euler-Lagrange equation
print euler_equations(L,f,x)

produces the output

[Eq(-4*(2*(Derivative(f(x), x)*Derivative(f(x), x, x) + 2*sin(f(x))*cos(f(x))*Derivative(f(x), x)/sin(x)**2 - 2*sin(f(x))**2*cos(x)/sin(x)**3)*sin(x)*Derivative(f(x), x) + (Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(x)*Derivative(f(x), x, x) + 2*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*cos(x)*Derivative(f(x), x))*sin(x) + 8*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(f(x))*cos(f(x)), 0)]

Using function latex to print the output in a more friendly form, we obtain the scary-looking ODE

$$\left(- 4 \left(2 \frac{d}{d x} f{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} + \frac{4 \frac{d}{d x} f{\left (x \right )}}{\sin^{2}{\left (x \right )}} \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} - \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{3}{\left (x \right )}} \cos{\left (x \right )}\right) \sin{\left (x \right )} \frac{d}{d x} f{\left (x \right )} - 4 \left(\frac{d}{d x} f{\left (x \right )}^{2} + 3 + \frac{2 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} - 4 \left(2 \frac{d}{d x} f{\left (x \right )}^{2} + 6 + \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \cos{\left (x \right )} \frac{d}{d x} f{\left (x \right )}\right) \sin{\left (x \right )} + \left(8 \frac{d}{d x} f{\left (x \right )}^{2} + 24 + \frac{16 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} = 0$$

If we make $f (x) := x$, we obtain the following equation

$$ - \left(16 x + 40\right) \cos{\left (x \right )} \sin{\left (x \right )} + \left(16 x + 40\right) \sin{\left ( x\right )} \cos{\left (x \right )} = 0$$

which holds for all $x$. Hence, $f (x) = x$ is a solution to the Euler-LagrangeEuler-Lagrange ODE and, thus, it does extremizemakes the integralfunctional stationary. Proving that it minimizes the integralfunctional is left as an exercise for the reader.

The following SymPy script

from sympy import *

x = Symbol('x')
f = Function('f')(x)

# define Lagrangian
L = (sin(x))**2 * (3 + 2*((sin(f))**2/(sin(x))**2) + (Derivative(f,x))**2)**2

# Euler-Lagrange equation
print euler_equations(L,f,x)

produces the output

[Eq(-4*(2*(Derivative(f(x), x)*Derivative(f(x), x, x) + 2*sin(f(x))*cos(f(x))*Derivative(f(x), x)/sin(x)**2 - 2*sin(f(x))**2*cos(x)/sin(x)**3)*sin(x)*Derivative(f(x), x) + (Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(x)*Derivative(f(x), x, x) + 2*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*cos(x)*Derivative(f(x), x))*sin(x) + 8*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(f(x))*cos(f(x)), 0)]

Using function latex to print the output in a more friendly form, we obtain the scary-looking ODE

$$\left(- 4 \left(2 \frac{d}{d x} f{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} + \frac{4 \frac{d}{d x} f{\left (x \right )}}{\sin^{2}{\left (x \right )}} \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} - \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{3}{\left (x \right )}} \cos{\left (x \right )}\right) \sin{\left (x \right )} \frac{d}{d x} f{\left (x \right )} - 4 \left(\frac{d}{d x} f{\left (x \right )}^{2} + 3 + \frac{2 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} - 4 \left(2 \frac{d}{d x} f{\left (x \right )}^{2} + 6 + \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \cos{\left (x \right )} \frac{d}{d x} f{\left (x \right )}\right) \sin{\left (x \right )} + \left(8 \frac{d}{d x} f{\left (x \right )}^{2} + 24 + \frac{16 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} = 0$$

If we make $f (x) := x$, we obtain the following equation

$$ - \left(16 x + 40\right) \cos{\left (x \right )} \sin{\left (x \right )} + \left(16 x + 40\right) \sin{\left ( x\right )} \cos{\left (x \right )} = 0$$

which holds for all $x$. Hence, $f (x) = x$ is a solution to the Euler-Lagrange ODE and, thus, it does extremize the integral. Proving that it minimizes the integral is left as an exercise for the reader.

The following SymPy script

from sympy import *

x = Symbol('x')
f = Function('f')(x)

# define Lagrangian
L = (sin(x))**2 * (3 + 2*((sin(f))**2/(sin(x))**2) + (Derivative(f,x))**2)**2

# Euler-Lagrange equation
print euler_equations(L,f,x)

produces the output

[Eq(-4*(2*(Derivative(f(x), x)*Derivative(f(x), x, x) + 2*sin(f(x))*cos(f(x))*Derivative(f(x), x)/sin(x)**2 - 2*sin(f(x))**2*cos(x)/sin(x)**3)*sin(x)*Derivative(f(x), x) + (Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(x)*Derivative(f(x), x, x) + 2*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*cos(x)*Derivative(f(x), x))*sin(x) + 8*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(f(x))*cos(f(x)), 0)]

Using function latex to print the output in a more friendly form, we obtain the scary-looking ODE

$$\left(- 4 \left(2 \frac{d}{d x} f{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} + \frac{4 \frac{d}{d x} f{\left (x \right )}}{\sin^{2}{\left (x \right )}} \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} - \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{3}{\left (x \right )}} \cos{\left (x \right )}\right) \sin{\left (x \right )} \frac{d}{d x} f{\left (x \right )} - 4 \left(\frac{d}{d x} f{\left (x \right )}^{2} + 3 + \frac{2 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} - 4 \left(2 \frac{d}{d x} f{\left (x \right )}^{2} + 6 + \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \cos{\left (x \right )} \frac{d}{d x} f{\left (x \right )}\right) \sin{\left (x \right )} + \left(8 \frac{d}{d x} f{\left (x \right )}^{2} + 24 + \frac{16 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} = 0$$

If we make $f (x) := x$, we obtain the following equation

$$ - \left(16 x + 40\right) \cos{\left (x \right )} \sin{\left (x \right )} + \left(16 x + 40\right) \sin{\left ( x\right )} \cos{\left (x \right )} = 0$$

which holds for all $x$. Hence, $f (x) = x$ is a solution to the Euler-Lagrange ODE and, thus, it makes the functional stationary. Proving that it minimizes the functional is left as an exercise for the reader.

Source Link

The following SymPy script

from sympy import *

x = Symbol('x')
f = Function('f')(x)

# define Lagrangian
L = (sin(x))**2 * (3 + 2*((sin(f))**2/(sin(x))**2) + (Derivative(f,x))**2)**2

# Euler-Lagrange equation
print euler_equations(L,f,x)

produces the output

[Eq(-4*(2*(Derivative(f(x), x)*Derivative(f(x), x, x) + 2*sin(f(x))*cos(f(x))*Derivative(f(x), x)/sin(x)**2 - 2*sin(f(x))**2*cos(x)/sin(x)**3)*sin(x)*Derivative(f(x), x) + (Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(x)*Derivative(f(x), x, x) + 2*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*cos(x)*Derivative(f(x), x))*sin(x) + 8*(Derivative(f(x), x)**2 + 3 + 2*sin(f(x))**2/sin(x)**2)*sin(f(x))*cos(f(x)), 0)]

Using function latex to print the output in a more friendly form, we obtain the scary-looking ODE

$$\left(- 4 \left(2 \frac{d}{d x} f{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} + \frac{4 \frac{d}{d x} f{\left (x \right )}}{\sin^{2}{\left (x \right )}} \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} - \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{3}{\left (x \right )}} \cos{\left (x \right )}\right) \sin{\left (x \right )} \frac{d}{d x} f{\left (x \right )} - 4 \left(\frac{d}{d x} f{\left (x \right )}^{2} + 3 + \frac{2 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (x \right )} \frac{d^{2}}{d x^{2}} f{\left (x \right )} - 4 \left(2 \frac{d}{d x} f{\left (x \right )}^{2} + 6 + \frac{4 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \cos{\left (x \right )} \frac{d}{d x} f{\left (x \right )}\right) \sin{\left (x \right )} + \left(8 \frac{d}{d x} f{\left (x \right )}^{2} + 24 + \frac{16 \sin^{2}{\left (f{\left (x \right )} \right )}}{\sin^{2}{\left (x \right )}}\right) \sin{\left (f{\left (x \right )} \right )} \cos{\left (f{\left (x \right )} \right )} = 0$$

If we make $f (x) := x$, we obtain the following equation

$$ - \left(16 x + 40\right) \cos{\left (x \right )} \sin{\left (x \right )} + \left(16 x + 40\right) \sin{\left ( x\right )} \cos{\left (x \right )} = 0$$

which holds for all $x$. Hence, $f (x) = x$ is a solution to the Euler-Lagrange ODE and, thus, it does extremize the integral. Proving that it minimizes the integral is left as an exercise for the reader.