Euler-Lagrange Equation — Derivation & Live Simulation

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.

$$S[q] = \int_{t_1}^{t_2} L(q, \dot{q}, t) \, dt$$

$$\delta S = 0$$

The Derivation Pathway

Step 1: Path Variation +
$$q(t) \to q(t) + \epsilon \eta(t)$$
Assume a true path \(q(t)\) that minimizes action. We introduce a small variation \(\eta(t)\) scaled by parameter \(\epsilon\). The endpoints are fixed.
Step 2: Action Functional +
$$S(\epsilon) = \int L(q + \epsilon\eta, \dot{q} + \epsilon\dot{\eta}) \, dt$$
Substitute the varied path into the action integral. The action \(S\) is now a function of the scalar parameter \(\epsilon\).
Step 3: First Order Expansion +
$$\frac{dS}{d\epsilon} \bigg|_{\epsilon=0} = \int \left( \frac{\partial L}{\partial q}\eta + \frac{\partial L}{\partial \dot{q}}\dot{\eta} \right) dt = 0$$
For stationary action, the derivative with respect to \(\epsilon\) evaluated at \(\epsilon=0\) must vanish. We use the chain rule to expand the Lagrangian.
Step 4: Integration by Parts +
$$\int \frac{\partial L}{\partial \dot{q}} \dot{\eta} \, dt = \left[ \frac{\partial L}{\partial \dot{q}} \eta \right] - \int \frac{d}{dt}\left(\frac{\partial L}{\partial \dot{q}}\right) \eta \, dt$$
Apply integration by parts to the second term to factor out \(\eta(t)\). This shifts the time derivative onto the momentum term.
Step 5: Euler-Lagrange Equation +
$$\frac{\partial L}{\partial q} - \frac{d}{dt}\left(\frac{\partial L}{\partial \dot{q}}\right) = 0$$
Since \(\eta(t)\) is zero at the boundaries, the surface term vanishes. Because the remaining integral must be zero for any arbitrary variation \(\eta(t)\), the term in brackets must be identically zero.

Action Minimization (Gravity Field)

ACTION PHASE SPACE (S vs ε)
VARIATION ε →
← VARIATION -ε
TRUE PATH (CYAN) / VARIED PATH (VIOLET)
ACTION S = 0.000

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

Runge-Kutta 4 (JS)
Euler Method (Python)
// 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.

INITIATIVE FOR PHYSICS VISUALIZATION NOTEBOOKS // V2.0 // KAZ
NOTEBOOK 01: CLASSICAL MECHANICS - EULER - LAGRANGE EQNS FROM VARIATIONAL PRINCIPLE

Visulalization of Fourier Synthesis of Common Wave Forms

Interactive Fourier Explorer

Decompose complex periodic waveforms into a sum of simple oscillating sine and cosine waves. Adjust the harmonics and observe how rotating epicycles generate the target function.

f(x) = a0 + ∑ (an cos(nx) + bn sin(nx))
Domain: Time (t) Points Rendered: 0

Frequency Spectrum

Learn

A Fourier Series expands a periodic function into an infinite sum of sines and cosines. This implies that any complex repeating pattern can be broken down into fundamental, simple oscillations.
Visualized here as connecting rotating circles. Each circle represents one term in the Fourier series. The radius is the amplitude, the rotation speed is the frequency, and adding them vectorially traces the complex shape!
Notice the "wiggles" or "ringing" near sharp corners (like the edges of the Square Wave)? This is the Gibbs phenomenon. Because we use continuous sine waves, they struggle to perfectly replicate instantaneous jumps, resulting in overshoot.

How Mirrors Reflect Light? The Truth Will Blow Your Mind!

Quantum Electrodynamics: The Path Integral

In classical optics, light appears to follow Fermat's Principle of Least Time, taking a single, straight path to bounce off the center of a mirror. However, Richard Feynman's Sum Over Histories formulation of quantum mechanics reveals a deeper reality: a photon doesn't just take one path; it explores every possible path simultaneously.

The probability \( P \) of a photon traveling from the Source (\(S\)) to the Detector (\(D\)) is the squared magnitude of the total probability amplitude \( \Psi \). This total amplitude is the sum of contributions from every conceivable path \( x \):

\[ P = |\Psi|^2 = \left| \sum_{\text{paths}} C \, e^{i S[x] / \hbar} \right|^2 \]

Each path contributes a vector (a phasor) of identical length. Its phase angle is determined by the classical action \( S[x] \) (proportional to the travel time). At the edges of the mirror, the travel time changes drastically between adjacent paths. Their phasors spin wildly and cancel each other out (destructive interference). At the center, the travel time is stationary (\( \delta S = 0 \)). The phasors point in the exact same direction and stack up perfectly (constructive interference), generating the classical macroscopic path.

Interactive Sandbox: Drag the Source, Detector, or Grating below. Watch the paths, amplitudes, and time curves recalculate in real-time. Click Bake & Apply Diffraction Grating to scrape away the destructively interfering edge paths—physically proving the light was interacting with the entire mirror all along!

Physical Space (Trajectories) Drag Source, Detector, or Grating
Time of Flight (Action) Fermat's Principle
Amplitude Addition Scroll: Zoom · Drag: Pan

Cool Science Podcast : How Pulse NMR Decoded Quantum Whispers

Desktop: Use ← and → keys to navigate slides.   •   Mobile: Swipe left or right.   •   Press Ctrl + Shift + F for fullscreen.

Projectile Motion in Style - A Nature's Odyssey

Physics • Nature • Motion

Projectile Motion
In The Natural World

Projectile motion is one of the most beautiful ideas in classical mechanics. From a squirrel leaping between branches to a kingfisher diving into water, nature constantly demonstrates the physics of curved motion under gravity.

9.8

m/s² Gravity

45°

Optimal Launch Angle

Parabolic

Trajectory Shape

Projectile Motion Squirrel Illustration

What is Projectile Motion?

Projectile motion describes the motion of an object launched into the air under the influence of gravity alone.


  • Horizontal Motion → constant velocity
  • Vertical Motion → accelerated downward by gravity

When combined, these motions create a curved path called a trajectory.

The Squirrel Leap

A squirrel jumping between branches follows a natural projectile path. Once it pushes off the branch, gravity continuously pulls it downward while it keeps moving forward through the air.


The result is a smooth parabolic arc that allows the squirrel to cross gaps efficiently and safely.

Key Equations

$$x(t)=v_0\cos\theta \cdot t$$ $$y(t)=v_0\sin\theta \cdot t-\frac{1}{2}gt^2$$ $$y=x\tan\theta-\frac{gx^2}{2v_0^2\cos^2\theta}$$

These equations predict the position and trajectory of a projectile at any instant.

Projectile Motion Nature Banner

Factors Affecting Motion

  • Initial velocity
  • Launch angle
  • Acceleration due to gravity
  • Air resistance
  • Launch height

Why The Path is Parabolic

The horizontal velocity remains nearly constant while the vertical velocity changes uniformly due to gravity.


Combining uniform motion with accelerated motion naturally creates a parabolic trajectory.

Applications

  • Sports physics
  • Rocket launches
  • Animal locomotion
  • Ballistics
  • Game simulations
  • Space exploration