Can you beat the extremal? Sometimes you can.
The Euler–Lagrange equation finds a curve where the first variation vanishes. That does not make it a minimum. Bend the curve yourself and find out when it is one.
01The game
We minimize the functional from the exam exercise, on an interval of length $T$:
$$J[x]=\int_0^T\big(\dot x^2-x^2+4x\cos t\big)\,dt,\qquad x(0)=x(T)=0 .$$The dashed curve solves the Euler–Lagrange equation. Your job is to find a curve with a smaller $J$. The steps inside the card walk you through it; the numbers under the chart keep score.
02Where the dashed curve comes from
With $L=\dot x^2-x^2+4x\cos t$, the Euler–Lagrange equation $\frac{d}{dt}L_{\dot x}=L_x$ becomes
$$\ddot x + x = 2\cos t .$$A particular solution is $t\sin t$, and the boundary conditions fix the rest:
$$x^*(t)=(t-T)\sin t .$$For $T=\pi/2$ this is the exam answer, $x^*=(t-\pi/2)\sin t$.
03The difference is exact
$J$ is quadratic, so a perturbation $x=x^*+h$ with $h(0)=h(T)=0$ changes it by exactly
$$J[x^*+h]-J[x^*]=\underbrace{\delta J[x^*;h]}_{=\,0}+\int_0^T\big(\dot h^2-h^2\big)\,dt .$$The first variation vanishes because $x^*$ solves the Euler–Lagrange equation. The scoreboard computes both sides independently, and they agree to rounding error.
04Why you cannot win when T < π
Wirtinger's inequality says that if $h(0)=h(T)=0$, then
$$\int_0^T\dot h^2\,dt\ \ge\ \Big(\frac{\pi}{T}\Big)^2\int_0^T h^2\,dt .$$For $T<\pi$ the factor is larger than one, so $\Delta J\ge 0$ for every admissible $h$: the extremal is a strict minimum.
05Past T = π: the conjugate point
Take a single bump $h=a\sin(\pi t/T)$. Then
$$\Delta J=a^2\,\frac{T}{2}\Big(\frac{\pi^2}{T^2}-1\Big)\ <\ 0\qquad\text{for } T>\pi .$$The extremal still satisfies the Euler–Lagrange equation but is no longer a minimum, and $J$ is unbounded below. At $T=\pi$ exactly, $\sin t$ solves the homogeneous problem with zero boundary values: the same resonance that appears in the Fredholm alternative.
Methods. Your curve is the extremal plus a natural cubic spline through the handles, vanishing at both ends. $J$ and $\int(\dot h^2-h^2)$ use composite Simpson's rule with 2000 intervals.