Euler–Lagrange Lab
An interactive environment exploring analytical mechanics and the Principle of Stationary Action. Discover the fundamental equations that govern the paths of nature.
$$\delta S = 0$$
The Derivation Pathway
Action Minimization (Gravity Field)
Observe a particle in a uniform gravitational field. Modify the variation amplitude \(\epsilon\) to see how arbitrary wavy paths increase the total Action compared to the natural parabolic path.
Classical Systems
Lagrangian: $$L = \frac{1}{2} m \dot{x}^2$$
E-L Eq: $$\frac{d}{dt}(m \dot{x}) - 0 = 0$$
EOM: $$\ddot{x} = 0 \implies v = \text{const}$$
Lagrangian: $$L = \frac{1}{2} m \dot{x}^2 - \frac{1}{2} k x^2$$
E-L Eq: $$\frac{d}{dt}(m \dot{x}) - (-kx) = 0$$
EOM: $$\ddot{x} = -\frac{k}{m}x$$
Lagrangian: $$L = \frac{1}{2} m l^2 \dot{\theta}^2 + m g l \cos(\theta)$$
E-L Eq: $$\frac{d}{dt}(m l^2 \dot{\theta}) - (-m g l \sin(\theta)) = 0$$
EOM: $$\ddot{\theta} = -\frac{g}{l}\sin(\theta)$$
Numerical Workspace
// RK4 Integrator for 2nd Order ODE: x'' = f(x, v, t)
function rk4_step(x, v, t, dt, force_func) {
const k1_v = force_func(x, v, t);
const k1_x = v;
const k2_v = force_func(x + 0.5*dt*k1_x, v + 0.5*dt*k1_v, t + 0.5*dt);
const k2_x = v + 0.5*dt*k1_v;
const k3_v = force_func(x + 0.5*dt*k2_x, v + 0.5*dt*k2_v, t + 0.5*dt);
const k3_x = v + 0.5*dt*k2_v;
const k4_v = force_func(x + dt*k3_x, v + dt*k3_v, t + dt);
const k4_x = v + dt*k3_v;
const new_x = x + (dt / 6.0) * (k1_x + 2*k2_x + 2*k3_x + k4_x);
const new_v = v + (dt / 6.0) * (k1_v + 2*k2_v + 2*k3_v + k4_v);
return { x: new_x, v: new_v };
}
# Basic Euler Integration for Harmonic Oscillator
def simulate_ho(k, m, x0, v0, dt, steps):
x = x0
v = v0
history = [(x, v)]
for _ in range(steps):
# EOM: a = - (k/m) * x
a = -(k / m) * x
# Update state
v_new = v + a * dt
x_new = x + v * dt
x = x_new
v = v_new
history.append((x, v))
return history
Phase Space Geometry
The state of a system is fully described by coordinates \(q\) and momenta \(p\). For a conservative system like the Harmonic Oscillator, energy conservation manifests as closed orbits in phase space.