\subsection{Simple Harmonic Oscillator}

This subsection solves the simple harmonic oscillator through the Hamilton--Jacobi equation. The quadratic potential turns the Hamilton--Jacobi square-root integral into an elementary trigonometric substitution, making the oscillator one of the few nonlinear Hamilton--Jacobi equations integrable in closed form. This same physical system appears in Unit~7 (oscillations) under Newton\normalsize{}'s law; here we solve it by an entirely different route to obtain the complete integral, trajectory by quadrature, and action--angle variables confirming isochronous oscillation. This integrability makes the harmonic oscillator the prototypical example for testing both the Hamilton--Jacobi method and the action--angle formalism.

\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\normalsize{}'s theorem.}

\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.

The sign carries physical meaning: the upper sign describes forward motion ($p>0$, the mass traveling toward $+A$) and the lower sign describes backward motion ($p<0$, the mass returning toward $-A$). In the closed contour integral $\oint p\,\dd x$ that defines the action variable, the $+$ branch contributes the outward half of the orbit $(-A\to A)$ and the $-$ branch contributes the return half $(A\to -A)$. For finding $W(x;E)$ as a local generating function we choose the positive branch and carry it through the integration; full periodicity is then imposed by the boundary conditions.

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\normalsize{}'s theorem}{
Jacobi\normalsize{}'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 carries deep physical significance: the energy dependence of the amplitude $A = \sqrt{2E/(m\omega_0^2)}$ and the energy dependence of the integrand $\sqrt{2mE - m^2\omega_0^2 x^2}$ nearly cancel when differentiated with respect to $E$, leaving only the geometric phase $\tfrac{1}{\omega_0}\arcsin(\cdots)$. Because $\pdv{W}{E}$ is independent of the amplitude, the period $T = 2\pi/\omega_0$ is the same for every orbit regardless of how much energy it carries. This is the isochrony of the simple harmonic oscillator---all amplitudes share one period. The algebraic cancellation in $\pdv{W}{E}$ is the Hamilton--Jacobi embodiment of that physical fact. 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)$.}

\ex{Phase-space ellipse}{
The action variable $J = \frac{1}{2\pi}\oint p\,\dd x$ is $\frac{1}{2\pi}$ times the area enclosed by the orbit in the $(x,p)$ phase plane. For the harmonic oscillator the orbit is an ellipse. The orbit equation follows from energy conservation,
\[
\frac{p^2}{2m} + \frac{1}{2}m\omega_0^2 x^2 = E,
\]
which can be rearranged to standard form:
\[
\frac{x^2}{A^2} + \frac{p^2}{p_{\max}^2} = 1,
\]
where $A = \sqrt{2E/(m\omega_0^2)}$ is the maximum displacement (semi-axis along the position direction) and $p_{\max} = \sqrt{2mE} = m\omega_0 A$ is the maximum momentum (semi-axis along the momentum direction). The phase-space orbit is an ellipse centered at the origin with these semi-axes. The enclosed area is $\pi A\,p_{\max}$. The action variable is $\frac{1}{2\pi}$ times this area:
\[
J = \frac{1}{2\pi}\cdot\pi A\,p_{\max}
= \frac{1}{2}\sqrt{\frac{2E}{m\omega_0^2}}\cdot\sqrt{2mE}
= \frac{1}{2}\sqrt{\frac{4E^2}{\omega_0^2}}
= \frac{E}{\omega_0}.
\]
The linear relation $J \propto E$ reflects the fact that doubling the energy rescales the ellipse uniformly, while the ratio $p_{\max}/A = m\omega_0$ sets the ellipse\normalsize{}'s aspect ratio.}

\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 $\frac{1}{2\pi}$ times the phase-space area enclosed by one complete cycle:
\[
J = \frac{1}{2\pi}\oint p\,\dd x = \frac{1}{\pi}\int_{-A}^{A}\sqrt{2mE - m^2\omega_0^2 x^2}\,\dd x.
\]
With the substitution $x = A\sin\phi$, the integral $\int_{-A}^{A}\sqrt{2mE - m^2\omega_0^2 x^2}\,\dd x$ evaluates to $\tfrac{\pi}{2}\sqrt{2mE}\cdot A$. With the prefactor $1/\pi$ this gives $J = \tfrac{1}{2}\sqrt{2mE}\cdot A$. Using $A = \sqrt{2E/(m\omega_0^2)}$ we obtain $J = E/\omega_0$. Geometrically, $J$ is $\frac{1}{2\pi}$ times the area of the elliptical orbit in the $(x,p)$ phase plane, confirming the computation in the example above.

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

\item The frequency conjugate to the action is $\pdv{E}{J} = \omega_0$, which is the physical angular frequency itself, independent of $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, whose algebraic origin we saw in the cancellation within $\pdv{W}{E}$.

\item The angle variable $w\in[0,2\pi)$ tracks the oscillator\normalsize{}'s progress through one complete cycle. At $w=0$ the particle sits at the outward turning point $x=+A$ (maximum displacement, zero velocity). It crosses equilibrium toward $-A$ at $w=\pi/2$, reaches the opposite turning point $x=-A$ at $w=\pi$, and returns through equilibrium at $w=3\pi/2$. At $w=2\pi\equiv 0$ the orbit closes, having completed one period. The angle advances linearly, $w = \omega_0 t + w_0$, advancing exactly $2\pi$ each period $T=2\pi/\omega_0$. The sinusoidal phase $\omega_0 t + \phi$ coincides with $w$ up to a constant offset, confirming that $w$ measures angular position within the cycle.
\end{enumerate}
}

\nt{Comparison with Newton\normalsize{}'s law and energy conservation}{
Newton\normalsize{}'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\normalsize{}'s theorem. The agreement confirms the equivalence of the three formulations -- Newton\normalsize{}'s, Lagrange\normalsize{}'s, and Jacobi\normalsize{}'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 = E/\omega_0$ in SI units and verify numerically that $E(J) = \omega_0 J$ 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{E}{\omega_0}.
\]
Substitute the numerical values:
\[
J = \frac{8.0\,\mathrm{J}}{2.0\,\mathrm{rad/s}}
= 4.0\,\mathrm{J\!\cdot\!s}.
\]
Now verify the energy--action relation $E(J) = \omega_0 J$:
\[
E(J) = \omega_0 J
= (2.0\,\mathrm{rad/s})(4.0\,\mathrm{J\!\cdot\!s})
= 8.0\,\mathrm{J}.
\]
This returns the original energy exactly, confirming $E(J) = \omega_0 J$ 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 = 4.0\,\mathrm{J\!\cdot\!s}.
\]