The brachistochrone problem asks for the curve y(x) between two fixed points that minimizes the time a frictionless bead needs to slide down it under gravity. By energy conservation v = √(2gy), so the total time is the functional
T[y] = ∫ ds / v = ∫ √(1 + y'²) / √(2 g y) dx
This 2D version uses the spectral Ritz method: instead of free vertex points, the trial curve is written as a truncated Fourier sine series added to the straight chord,
y(u) = u·h + Σ_{k=1}^{M} c_k · sin(k π u), u = x / span
which satisfies the boundary conditions y(0)=0, y(1)=h automatically for any coefficients c_k — no pinning needed. The discretized functional T(c) is evaluated by numerical integration, and gradient descent moves every coefficient opposite its numerical partial derivative ∂T/∂c_k, shrinking the whole mode spectrum toward the values that make y(u) trace the cycloid. Because only M modes are kept, the curve converges to the best M-mode approximation of the cycloid, not the exact curve — the spectrum bars and the residual gap to the analytic time make that truncation error visible directly, something a vertex-mesh discretization does not show.
- Initial guess — Straight starts every c_k at 0; Bulge up sets a low-mode-dominated negative spectrum (path rises above the chord); Zigzag loads the high modes instead.
- Start descent / Step once / Reset path — run, single-step, or restart the coefficient descent.
- End B height / distance — move the target point; the cycloid overlay and its mode spectrum are refit automatically.
- Fourier modes M — how many sine terms the trial curve is allowed; more modes reach a lower final T but never overshoot below the analytic optimum.
Top strip: the reconstructed curve (amber) against the analytic cycloid (dashed). Middle strip: current |c_k| spectrum bars against the cycloid's own Fourier projection (thin ticks) — the target every mode is descending toward. Bottom strip: T(iteration), the functional value trace, converging down onto the analytic cycloid time (dashed floor).