Lesson 9 of 15

Euler-Lagrange Equation

Euler-Lagrange Equation

The calculus of variations asks: which function y(x)y(x) extremizes the functional

S[y]=x1x2L(x,y,y)dxS[y] = \int_{x_1}^{x_2} L(x, y, y')\, dx

where LL is the Lagrangian density? The answer is the Euler-Lagrange equation:

ddx ⁣(Ly)Ly=0\frac{d}{dx}\!\left(\frac{\partial L}{\partial y'}\right) - \frac{\partial L}{\partial y} = 0

Classic Examples

Shortest path: L=1+y2L = \sqrt{1 + y'^2}. The E-L equation gives y=0y'' = 0, i.e., a straight line.

Brachistochrone: The curve of fastest descent under gravity is a cycloid, found by minimizing the travel time functional.

Simple pendulum: The Lagrangian L=TV=12ml2θ˙2mgl(1cosθ)L = T - V = \tfrac{1}{2}ml^2\dot\theta^2 - mgl(1-\cos\theta) gives the equation of motion:

θ¨+glsinθ=0\ddot\theta + \frac{g}{l}\sin\theta = 0

In the small-angle approximation (sinθθ\sin\theta \approx \theta), this becomes simple harmonic motion with angular frequency ω=g/l\omega = \sqrt{g/l}.

Pendulum Period

The small-angle period is:

T=2πlgT = 2\pi\sqrt{\frac{l}{g}}

The small-angle solution is θ(t)=θ0cos(ωt+ϕ)\theta(t) = \theta_0 \cos(\omega t + \phi).

Numerical Action

Given discrete sample points (xi,yi)(x_i, y_i), approximate S[y]S[y] numerically:

  1. Estimate yi(yi+1yi)/(xi+1xi)y'_i \approx (y_{i+1} - y_i) / (x_{i+1} - x_i) (forward difference).
  2. Evaluate LL at the midpoint of each interval.
  3. Sum: SiL(xmid,ymid,yi)ΔxiS \approx \sum_i L(x_{\text{mid}}, y_{\text{mid}}, y'_i)\, \Delta x_i.

Your Task

Implement action(L_func, y_values, x_values) using the midpoint-rectangle rule above. Implement pendulum_period_s(l_m, g=9.81) for the small-angle period. Implement pendulum_angle_rad(t_s, theta0_rad, l_m, g=9.81) for the small-angle trajectory θ0cos(ωt)\theta_0 \cos(\omega t).

All constants must be computed inside the function bodies.

Python runtime loading...
Loading...
Click "Run" to execute your code.