\subsection{Simple Harmonic Oscillator}

This subsection solves the simple harmonic oscillator through the Hamilton--Jacobi equation, obtains the complete integral and trajectory by quadrature, and computes the action-angle variables that confirm isochronous oscillation.

\dfn{Hamilton--Jacobi formulation of the simple harmonic oscillator}{
The Hamiltonian for a one-dimensional simple harmonic oscillator of mass~$m$ and spring constant~$k$ is
\[
\mcH = \frac{p^2}{2m} + \frac{1}{2}k x^2
\]
with natural angular frequency $\omega_0 = \sqrt{k/m}$. In terms of~$\omega_0$,
\[
\mcH = \frac{p^2}{2m} + \frac{1}{2}m\omega_0^2 x^2.
\]
The Hamilton--Jacobi partial differential equation for the principal function~$\mcS(x,t)$ follows by the substitution $p = \pdv{\mcS}{x}$:
\[
\frac{1}{2m}\left(\pdv{\mcS}{x}\right)^2 + \frac{1}{2}m\omega_0^2 x^2 + \pdv{\mcS}{t} = 0.
\]
A complete integral $\mcS(x,t;E)$, containing one independent non-additive constant $E$ equal to the total energy, determines the full dynamics by Jacobi's theorem.}

\nt{The simple harmonic oscillator is one of the few nonlinear Hamilton--Jacobi equations that can be integrated in closed form. The quadratic potential turns the square-root integral into an elementary trigonometric substitution, and the resulting complete integral yields the standard sinusoidal trajectory. This integrability makes the harmonic oscillator the prototypical example for testing both the Hamilton--Jacobi method and the action-angle formalism.}

\thm{Complete integral of the SHO Hamilton--Jacobi equation}{
The complete integral of the Hamilton--Jacobi equation for a simple harmonic oscillator is
\[
\mcS(x,t;E) = \frac{E}{\omega_0}\arcsin\!\left(x\sqrt{\frac{m\omega_0^2}{2E}}\right) 
+ \frac{1}{2}x\sqrt{2mE - m^2\omega_0^2 x^2} - Et,
\]
where $E>0$ is the total energy. It is defined for $|x| < A$ with $A = \sqrt{2E/(m\omega_0^2)}$.}

\pf{Derivation of the complete integral by separation and trigonometric substitution}{
Because $\pdv{\mcH}{t} = 0$, separate the time variable by setting $\mcS(x,t) = W(x) - Et$. The temporal derivative contributes $-E$ and the Hamilton--Jacobi equation reduces to
\[
\frac{1}{2m}\left(\der{W}{x}\right)^2 + \frac{1}{2}m\omega_0^2 x^2 = E.
\]
Solve for the spatial derivative:
\[
\der{W}{x} = \pm\sqrt{2mE - m^2\omega_0^2 x^2}.
\]
The square root is real for $|x| \le A$, where $A = \sqrt{2E/(m\omega_0^2)}$ is the amplitude. The turning points $x = \pm A$ bound the oscillation and correspond to the points where the kinetic energy vanishes.

Integrate by the trigonometric substitution $x = A\sin\theta$, giving $\dd x = A\cos\theta\,\mathrm{d}\theta$. The radicand becomes
\[
2mE - m^2\omega_0^2 A^2\sin^2\theta
= 2mE - 2mE\sin^2\theta
= 2mE\cos^2\theta,
\]
since $m^2\omega_0^2 A^2 = m^2\omega_0^2\cdot\bigl(2E/(m\omega_0^2)\bigr) = 2mE$. Hence,
\[
\sqrt{2mE - m^2\omega_0^2 x^2} = \sqrt{2mE}\cos\theta,
\]
where we take $\cos\theta \ge 0$ for $\theta\in[-\pi/2,\pi/2]$. The integral for~$W$ is
\[
W = \int\sqrt{2mE}\cos\theta\cdot A\cos\theta\,\mathrm{d}\theta
= \sqrt{2mE}\,A\int\cos^2\theta\,\mathrm{d}\theta.
\]
The antiderivative of $\cos^2\theta$ is $\tfrac12(\theta + \sin\theta\cos\theta)$, so
\[
W = \tfrac12\sqrt{2mE}\,A\bigl(\theta + \sin\theta\cos\theta\bigr).
\]
Evaluate the constant prefactor:
\[
\tfrac12\sqrt{2mE}\,A
= \tfrac12\sqrt{2mE}\cdot\sqrt{\frac{2E}{m\omega_0^2}}
= \tfrac12\cdot\frac{2E}{\omega_0}
= \frac{E}{\omega_0}.
\]
Now express the trigonometric quantities in terms of $x$:
\[
\theta = \arcsin\!\left(\frac{x}{A}\right) 
= \arcsin\!\left(x\sqrt{\frac{m\omega_0^2}{2E}}\right),
\]
\[
\sin\theta = \frac{x}{A} = x\sqrt{\frac{m\omega_0^2}{2E}},
\qquad
\cos\theta = \frac{\sqrt{2mE - m^2\omega_0^2 x^2}}{\sqrt{2mE}}.
\]
Substitute these expressions back into $W$:
\[
W = \frac{E}{\omega_0}\arcsin\!\left(x\sqrt{\frac{m\omega_0^2}{2E}}\right)
+ \frac{E}{\omega_0}\cdot x\sqrt{\frac{m\omega_0^2}{2E}}\cdot\frac{\sqrt{2mE - m^2\omega_0^2 x^2}}{\sqrt{2mE}}.
\]
The product of the factors in the second term simplifies as
\[
\frac{E}{\omega_0}\cdot\frac{\omega_0\sqrt{m}}{\sqrt{2E}}\cdot\frac{1}{\sqrt{2mE}}
= \frac{E}{\omega_0}\cdot\frac{\omega_0\sqrt{m}}{2E\sqrt{m}}
= \frac{1}{2},
\]
since $\sqrt{2E}\cdot\sqrt{2mE} = \sqrt{4mE^2} = 2E\sqrt{m}$. Thus
\[
W(x;E) = \frac{E}{\omega_0}\arcsin\!\left(x\sqrt{\frac{m\omega_0^2}{2E}}\right) 
+ \frac{1}{2}x\sqrt{2mE - m^2\omega_0^2 x^2},
\]
and the complete integral is $\mcS(x,t;E) = W(x;E) - Et$.}

\cor{Trajectory from Jacobi's theorem}{
Jacobi's theorem states $\pdv{\mcS}{E} = \beta$, where $\beta$ is a constant fixed by the initial conditions. Differentiate $\mcS = W - Et$ with respect to $E$ at fixed~$x$:
\[
\pdv{\mcS}{E} = \pdv{W}{E} - t.
\]
Write $W$ using the shorthand $\chi = x\sqrt{m\omega_0^2/(2E)}$ and $R = \sqrt{2mE - m^2\omega_0^2 x^2}$:
\[
W = \frac{E}{\omega_0}\arcsin\chi + \frac{1}{2}xR.
\]
The partial derivative with respect to~$E$ is
\[
\pdv{W}{E} = \frac{1}{\omega_0}\arcsin\chi 
+ \frac{E}{\omega_0}\frac{1}{\sqrt{1-\chi^2}}\pdv{\chi}{E}
+ \frac{x}{2}\cdot\frac{m}{R}.
\]
Because $\chi \propto E^{-1/2}$, one has $\pdv{\chi}{E} = -\chi/(2E)$. The second term simplifies to
\[
-\frac{E}{\omega_0}\frac{\chi}{2E\sqrt{1-\chi^2}}
= -\frac{\chi}{2\omega_0\sqrt{1-\chi^2}}
= -\frac{x\sqrt{m}}{2\sqrt{2E}\sqrt{1-\chi^2}}.
\]
To see the last equality, substitute $\chi = x\omega_0\sqrt{m/(2E)}$:
\[
\frac{\chi}{\omega_0} = x\sqrt{\frac{m}{2E}}.
\]
The third term equals
\[
\frac{xm}{2R} = \frac{xm}{2\sqrt{2mE}\sqrt{1-\chi^2}}
= \frac{x\sqrt{m}}{2\sqrt{2E}\sqrt{1-\chi^2}},
\]
which exactly cancels the second term. This cancellation reflects the fact that the energy dependence of the amplitude and the energy dependence of the integrand conspire to leave only the angular part. Therefore,
\[
\pdv{W}{E} = \frac{1}{\omega_0}\arcsin\!\left(x\sqrt{\frac{m\omega_0^2}{2E}}\right).
\]
The condition $\pdv{\mcS}{E} = \beta$ yields
\[
\frac{1}{\omega_0}\arcsin\!\left(x\sqrt{\frac{m\omega_0^2}{2E}}\right) - t = \beta,
\]
or equivalently,
\[
x\sqrt{\frac{m\omega_0^2}{2E}} = \sin\!\bigl(\omega_0(t+\beta)\bigr).
\]
Define the amplitude $A = \sqrt{2E/(m\omega_0^2)}$ and the phase $\phi = \omega_0\beta$. The trajectory is
\[
x(t) = A\sin(\omega_0 t + \phi).
\]
The total energy is $E = \tfrac12 m\omega_0^2 A^2 = \tfrac12 k A^2$, and the initial phase $\phi$ is determined by the initial position and velocity through $\sin\phi = x_0/A$ and $\cos\phi = v_0/(\omega_0 A)$. When the oscillator is released from rest at maximum displacement, $\cos\phi = 0$ and $\phi = \pi/2$, giving $x(t) = A\cos(\omega_0 t)$.}

\mprop{Action-angle variables for the harmonic oscillator}{
Applying the action-angle formalism to the simple harmonic oscillator gives the following results:

\begin{enumerate}[label=\bfseries\tiny\protect\circled{\small\arabic*}]
\item The action variable is the phase-space area enclosed by one complete cycle:
\[
J = \oint p\,\dd x = 2\int_{-A}^{A}\sqrt{2mE - m^2\omega_0^2 x^2}\,\dd x.
\]
With the substitution $x = A\sin\phi$, the integral reduces to $J = \pi\sqrt{2mE}\cdot A$. Using $A = \sqrt{2E/(m\omega_0^2)}$ this becomes $J = 2\pi E/\omega_0$. Geometrically, $J$ is the area of the elliptical orbit in the $(x,p)$ phase plane.

\item Inverting the action relation, the Hamiltonian as a function of the action alone is
\[
E(J) = \frac{\omega_0 J}{2\pi}.
\]
The Hamiltonian is now linear in $J$, which is the defining feature of an action-angle representation.

\item The HJ frequency is $\hat{\omega} = \pdv{E}{J} = \omega_0/(2\pi)$. The physical angular frequency is $\omega = 2\pi\hat{\omega} = \omega_0$, which is independent of the action $J$. Every oscillation shares the period $T = 2\pi/\omega_0$, regardless of energy or amplitude. This amplitude independence is the isochrony property of the harmonic oscillator.

\item The angle variable advances linearly in time: $w = \hat{\omega}t + w_0 = \omega_0 t/(2\pi) + w_0$. The phase of the sinusoidal trajectory, $\omega_0 t + \phi$, equals $2\pi w$ up to a constant, matching the canonical construction.
\end{enumerate}
}

\nt{Comparison with Newton's law and energy conservation}{
Newton's second law for the harmonic oscillator gives $m\ddot{x} + m\omega_0^2 x = 0$, a linear second-order ODE whose solution is $x(t) = A\sin(\omega_0 t + \phi)$. The energy method gives $E = \tfrac12 m\dot{x}^2 + \tfrac12 m\omega_0^2 x^2$ and $\dot{x} = \pm\sqrt{2E/m - \omega_0^2 x^2}$, which integrates to the same sinusoidal motion. The Hamilton--Jacobi approach reaches the identical result through a completely different route: solving a first-order nonlinear PDE by separation, evaluating a quadrature, and applying Jacobi's theorem. The agreement confirms the equivalence of the three formulations -- Newton's, Lagrange's, and Jacobi's -- as different faces of the same underlying mechanics.}

\qs{Simple harmonic oscillator from the HJ complete integral}{
A mass $m = 1.0\,\mathrm{kg}$ is attached to a horizontal spring with spring constant $k = 4.0\,\mathrm{N/m}$. The mass is displaced from equilibrium to $x_0 = 2.0\,\mathrm{m}$ and released from rest, so $v_0 = 0\,\mathrm{m/s}$.

\begin{enumerate}[label=(\alph*)]
\item Compute the natural angular frequency $\omega_0 = \sqrt{k/m}$. Write the Hamilton--Jacobi equation for this system, separate the variables to find $\der{W}{x}$, and state the complete integral $\mcS(x,t;E)$ with numerical parameter values.
\item Use the initial conditions $x(0) = 2.0\,\mathrm{m}$ and $\dot{x}(0) = 0\,\mathrm{m/s}$ to find the total energy $E$ and the amplitude $A = \sqrt{2E/(m\omega_0^2)}$. Write the trajectory $x(t)$ and verify that the maximum speed equals $A\omega_0$.
\item Compute the action variable $J = 2\pi E/\omega_0$ in SI units and verify numerically that $E(J) = \omega_0 J/(2\pi)$ reproduces the original energy.
\end{enumerate}}

\sol \textbf{Part (a).} The natural angular frequency is
\[
\omega_0 = \sqrt{\frac{k}{m}}
= \sqrt{\frac{4.0\,\mathrm{N/m}}{1.0\,\mathrm{kg}}}
= 2.0\,\mathrm{rad/s}.
\]
The Hamilton--Jacobi equation is
\[
\frac{1}{2m}\left(\pdv{\mcS}{x}\right)^2 + \frac{1}{2}m\omega_0^2 x^2 + \pdv{\mcS}{t} = 0.
\]
Substituting the numerical parameters $m = 1.0\,\mathrm{kg}$ and $\omega_0 = 2.0\,\mathrm{rad/s}$ gives
\[
\frac{1}{2}\left(\pdv{\mcS}{x}\right)^2 + 2.0\,x^2 + \pdv{\mcS}{t} = 0.
\]
Because the Hamiltonian is time-independent, separate as $\mcS = W(x) - Et$. The spatial derivative satisfies
\[
\der{W}{x} = \pm\sqrt{2mE - m^2\omega_0^2 x^2}
= \pm\sqrt{2E - 4x^2}.
\]
The complete integral for this specific system is
\[
\mcS(x,t;E) = \frac{E}{2.0}\arcsin\!\left(\frac{2x}{\sqrt{2E}}\right)
+ \frac{1}{2}x\sqrt{2E - 4x^2} - Et,
\]
valid for $|x| < \sqrt{E/2}$.

\textbf{Part (b).} The total mechanical energy is the sum of kinetic and potential energy:
\[
E = \frac{1}{2}m\dot{x}^2 + \frac{1}{2}k x^2.
\]
At release, $\dot{x} = 0$ and $x = 2.0\,\mathrm{m}$, so
\[
E = 0 + \frac{1}{2}(4.0\,\mathrm{N/m})(2.0\,\mathrm{m})^2
= 8.0\,\mathrm{J}.
\]
The amplitude follows from the energy--amplitude relation:
\[
A = \sqrt{\frac{2E}{m\omega_0^2}}
= \sqrt{\frac{2(8.0\,\mathrm{J})}{(1.0\,\mathrm{kg})(2.0\,\mathrm{rad/s})^2}}
= \sqrt{4.0}\,\mathrm{m}
= 2.0\,\mathrm{m}.
\]
The amplitude equals the initial displacement, as expected for release from rest.

The trajectory has the form $x(t) = A\sin(\omega_0 t + \phi)$. Determine the phase $\phi$ from the initial conditions:
\[
x(0) = A\sin\phi = 2.0\,\mathrm{m},
\qquad
\dot{x}(0) = A\omega_0\cos\phi = 0.
\]
Since $A = 2.0\,\mathrm{m}$, we have $\sin\phi = 1$ and $\cos\phi = 0$, giving $\phi = \pi/2$. The trajectory simplifies using the identity $\sin(\theta + \pi/2) = \cos\theta$:
\[
x(t) = A\cos(\omega_0 t).
\]
With numerical values,
\[
x(t) = (2.0\,\mathrm{m})\cos\bigl((2.0\,\mathrm{rad/s})\,t\bigr).
\]
The velocity is
\[
v(t) = \dot{x}(t) = -A\omega_0\sin(\omega_0 t).
\]
The maximum speed occurs at equilibrium ($x = 0$), where $|\sin(\omega_0 t)| = 1$:
\[
v_{\max} = A\omega_0 = (2.0\,\mathrm{m})(2.0\,\mathrm{rad/s}) = 4.0\,\mathrm{m/s}.
\]
From energy, $v_{\max} = \sqrt{2E/m} = \sqrt{16.0/1.0}\,\mathrm{m/s} = 4.0\,\mathrm{m/s}$, confirming the result.

\textbf{Part (c).} The action variable for the harmonic oscillator is
\[
J = \frac{2\pi E}{\omega_0}.
\]
Substitute the numerical values:
\[
J = \frac{2\pi(8.0\,\mathrm{J})}{2.0\,\mathrm{rad/s}}
= 8\pi\,\mathrm{J\!\cdot\!s}.
\]
Evaluating numerically:
\[
J = 8\pi\,\mathrm{J\!\cdot\!s} \approx 25\,\mathrm{J\!\cdot\!s}.
\]
Now verify the energy--action relation $E(J) = \omega_0 J/(2\pi)$:
\[
E(J) = \frac{\omega_0 J}{2\pi}
= \frac{(2.0\,\mathrm{rad/s})(8\pi\,\mathrm{J\!\cdot\!s})}{2\pi}
= 8.0\,\mathrm{J}.
\]
This returns the original energy exactly, confirming $E(J) = \omega_0 J/(2\pi)$ both algebraically and for the numerical values of this problem.

Therefore,
\[
\omega_0 = 2.0\,\mathrm{rad/s},
\qquad
x(t) = (2.0\,\mathrm{m})\cos\bigl((2.0\,\mathrm{rad/s})\,t\bigr),
\qquad
J = 8\pi\,\mathrm{J\!\cdot\!s}.
\]
