The brachistochrone problem asks for the curve y(x) between two fixed points, A above and B below, that minimizes the time a frictionless bead needs to slide down it under gravity. By energy conservation the speed at height drop h below A is v = √(2gh), so the total time is the functional
T[y] = ∫ ds / v = ∫ √(1 + y'²) / √(2 g y) dx
Calculus of variations finds the minimizer by requiring the first variation of T to vanish (the Euler-Lagrange equation). Because the integrand F(y, y') does not depend on x explicitly, the Beltrami identity applies: F − y' ∂F/∂y' = const, which reduces to the ODE solved exactly by a cycloid, x = r(θ − sinθ), y = r(1 − cosθ).
This simulation does not assume that answer. It represents the path as N free points y₁…y_{N-1} at fixed horizontal spacing (the endpoints are pinned to A and B), computes the discretized functional T as a sum over segments, and takes the numerical gradient ∂T/∂y_i of every interior point. Each step moves every point a small distance opposite its gradient — steepest-descent minimization, the same idea used to derive Euler-Lagrange, applied directly and numerically instead of analytically.
- Initial guess — start the relaxation from a straight line, an upward bulge, or a jagged zigzag; all three converge to the same curve.
- Start descent — run continuous gradient-descent steps; Step once advances a single iteration to inspect the process; Reset path returns to the chosen initial guess.
- End B height / distance — move the target point; the analytic cycloid overlay (dashed) is refit automatically.
- Gravity g — scales the speed term in the functional; it does not change the optimal shape.
- Descent rate — how large each gradient step is (iterations applied per animation frame).
The amber curve is the numerically relaxing path; the thin dashed curve is the closed-form cycloid solution, fit to the same endpoints for comparison. Watch the RMS gap between them shrink toward zero as the "convergence" readout climbs to 100%.