This is a read-only demonstration of PhysicsHive on an example project. You can open every page and type in every form, but nothing is saved. How this works
PhysicsHivependulum

Session record · file

computations/C-S1-2.md
Header
id: C-S1-2
kind: computation
supports: [CL-S1-1]

Summary

Wrote computations/C-S1-2.{py,out,md} and computations/C-S1-2.periods.csv. Symbolic and numerical paths agreed.

Result

\(T(\theta_0) = T_0\,(1 + \theta_0^2/16 + 11\,\theta_0^4/3072 + 173\,\theta_0^6/737280 + 22931\,\theta_0^8/1321205760 + O(\theta_0^{10}))\), with \(T_0 = 2\pi\sqrt{L/g}\). So \(c_2 = 1/16\) and \(c_4 = 11/3072\), both exact rationals.

  • Symbolic. Two independent routes give the same coefficients. The first is the exact period \(T = (4/\omega_0)K(\sin(\theta_0/2))\), expanded in \(\theta_0\); it gives \(c_2\) through \(c_8\). The second is a Lindstedt–Poincaré expansion of the equation of motion, with no elliptic integral; it gives \(c_2\), \(c_4\) and \(c_6\), identical to the first.
  • Numerical. At 13 amplitudes from 0.01 to 3 rad, three evaluations of the exact \(T/T_0\) agree to within \(1.3\times10^{-15}\): mpmath at 40 digits, scipy.special.ellipk, and a pure-NumPy arithmetic-geometric-mean (AGM) evaluation of \(K\). A direct integration of the equation of motion with no elliptic function (DOP853, rtol \(10^{-13}\)) agrees with the mpmath value to within \(1.3\times10^{-14}\).
  • Residual scaling. The residual \(T/T_0 - 1 - \theta_0^2/16\) scales as \(\theta_0^{4.0014}\) on \([0.01, 0.3]\). At \(\theta_0 = 0.01\), residual\(/\theta_0^4 = 0.0035807526\), against \(c_4 = 0.0035807292\).
  • \(c_2\) from the ODE data alone. A fit gives \(c_2 = 0.062500003\) (error \(3\times10^{-9}\)), and Richardson extrapolation gives \(0.062499994\) (error \(6\times10^{-9}\)).
  • Accuracy of the second-order formula. Its relative error \([T_0(1+\theta_0^2/16) - T]/T\) is \(-3.6\times10^{-7}\) at 0.1 rad, \(-3.6\times10^{-3}\) at 1 rad, \(-5.9\times10^{-2}\) at 2 rad and \(-0.39\) at 3 rad. The formula always underestimates the period.

Flags

  • conventions.md uses the letter \(m\) for two things: the mass (line 13) and the elliptic parameter \(m = k^2\) (line 22). This computation uses \(m\) only for the parameter. The clash is harmless here, since the mass drops out of the period, but it could confuse later artefacts.

Task

Check, independently, that the period of the simple pendulum at amplitude \(\theta_0\) is \(T = T_0\,(1 + \theta_0^2/16 + O(\theta_0^4))\) with \(T_0 = 2\pi\sqrt{L/g}\), so \(c_2 = 1/16\). The brief asks for two paths:

  • Symbolic. Starting from the equation of motion, obtain the exact \(T(\theta_0)\) and expand \(T/T_0\) with SymPy, reporting \(c_2\) and \(c_4\) as exact rationals.
  • Numerical. Evaluate the exact period at amplitudes from about 0.01 to 3 rad by two routes: the closed form with \(K\), and a direct ODE integration. Compare both with \(T_0(1 + c_2\theta_0^2)\). Check the \(\theta_0^4\) scaling of the residual, and extract \(c_2\) from the numerical data alone.

The brief agrees with project.md (goal) and conventions.md: the equation of motion is \(\ddot\theta + \omega_0^2\sin\theta = 0\), \(\theta_0\) is the maximum angle, and \(K\) is written with the modulus \(k\).

Computation

All periods are given as the dimensionless ratio \(T/T_0\); equivalently \(\omega_0 = 1\) and \(T_0 = 2\pi\). To get a time in seconds, multiply by \(2\pi\sqrt{L/g}\).

Symbolic (SymPy 1.14).

  • S1. Energy integral. SymPy checks that the energy \(\tfrac12\dot\theta^2 - \omega_0^2\cos\theta\) is conserved on the equation of motion. This gives \(\dot\theta^2 = 2\omega_0^2(\cos\theta - \cos\theta_0)\), and by symmetry \(T = 4\int_0^{\theta_0} d\theta/|\dot\theta|\).
  • S2. Substitution. With \(\sin(\theta/2) = k\sin\phi\) and \(k = \sin(\theta_0/2)\), SymPy reduces the integrand to \(1/(\omega_0\sqrt{1-k^2\sin^2\phi})\). Literally, it returns the ratio of the two integrands as \(\cos\phi/|\cos\phi|\), which equals 1 on \([0,\pi/2]\); it is also equal to 1 to 18 digits at 6 random points. Hence \(T = (4/\omega_0)K(k)\) and \(T/T_0 = (2/\pi)K(\sin(\theta_0/2))\).
  • S3. Series of \(K\). \(K\) is expanded in the parameter \(m=k^2\) by integrating the binomial series of the integrand term by term. The result is identical to sympy.elliptic_k(m).series(m) (parameter \(m\)) and to \(\tfrac{\pi}{2}\sum_n\big[\binom{2n}{n}/4^n\big]^2 m^n\).
  • S4. Expansion in \(\theta_0\). The series of S3 is evaluated at \(m = \sin^2(\theta_0/2)\) and expanded in \(\theta_0\) through order 8. The odd coefficients vanish.
  • S5. Lindstedt–Poincaré, with no elliptic integral. With \(\tau = \omega t\), \(\Omega = \omega^2 = 1 + a_2\epsilon^2 + a_4\epsilon^4 + a_6\epsilon^6\) and \(\theta = \epsilon\cos\tau + \epsilon^3y_3 + \epsilon^5y_5 + \epsilon^7y_7\), the initial data are \(\theta(0)=\epsilon\) and \(\dot\theta(0)=0\), so that \(\theta_0=\epsilon\) exactly. Requiring no secular term at each order fixes the \(a_{2j}\). Then \(T/T_0 = \Omega^{-1/2}\).

Numerical (NumPy 2.4, SciPy 1.17, mpmath).

  • Closed form, \(T/T_0 = (2/\pi)K\), evaluated three ways:
    • mpmath.ellipk(m) at 40 digits, which takes the parameter \(m=\sin^2(\theta_0/2)\); this is the reference value;
    • scipy.special.ellipk(m), which also takes the parameter \(m\);
    • a pure-NumPy AGM, \(K(k) = \pi/(2\,\mathrm{AGM}(1, k'))\), which takes the complementary modulus \(k' = \cos(\theta_0/2)\).
  • Direct ODE integration. The equation integrated is \(u'' = -\sin(\theta_0 u)/\theta_0\), with \(u = \theta/\theta_0\), \(u(0)=1\) and \(u'(0)=0\). The integrator is scipy.integrate.solve_ivp with DOP853, rtol \(10^{-13}\) and atol \(10^{-15}\). The period is computed twice, from event location: as 4 times the first zero of \(u\), and as 2 times the time of the turning point at \(u=-1\).
  • Amplitudes: 0.01, 0.02, 0.05, 0.1, 0.2, 0.3, 0.5, 0.75, 1, 1.5, 2, 2.5, 3 rad.

Results

Symbolic. $\(K(m) = \frac{\pi}{2} + \frac{\pi m}{8} + \frac{9 \pi m^{2}}{128} + \frac{25 \pi m^{3}}{512} + \frac{1225 \pi m^{4}}{32768} + O(m^5)\)\( \)\(\frac{T}{T_0} = 1 + \frac{\theta_{0}^{2}}{16} + \frac{11 \theta_{0}^{4}}{3072} + \frac{173 \theta_{0}^{6}}{737280} + \frac{22931 \theta_{0}^{8}}{1321205760} + O(\theta_0^{10})\)\( \)\(c_2 = \frac{1}{16},\qquad c_4 = \frac{11}{3072},\qquad c_6 = \frac{173}{737280},\qquad c_8 = \frac{22931}{1321205760}\)\( In the Lindstedt–Poincaré route, the conditions on the secular terms give \)a_2 = -1/8\(, \)a_4 = 7/1536\( and \)a_6 = -19/184320\(. Then \)\Omega^{-1/2} = 1 + \theta_0^2/16 + 11\theta_0^4/3072 + 173\theta_0^6/737280 + O(\theta_0^8)$, which differs from the elliptic series by exactly 0.

Numerical (all values are \(T/T_0\), dimensionless; full table in the CSV):

\(\theta_0\) (rad) \(T/T_0\) (mpmath) ODE − mpmath \([T_0(1+\theta_0^2/16) - T]/T\) residual\(/\theta_0^4\)
0.01 1.00000625003580753 5.3e-15 −3.58e-11 0.00358075
0.1 1.00062535830773663 3.1e-15 −3.58e-07 0.00358308
0.5 1.01585253110143671 1.1e-15 −2.24e-04 0.00364050
1.0 1.06633424557996305 3.3e-15 −3.60e-03 0.00383425
2.0 1.32890445191509954 1.3e-14 −5.94e-02 0.00493153
3.0 2.57123394943214205 5.8e-15 −3.92e-01 0.01245351

\(c_2\) from the numerical data alone.

  • The ratio \((T/T_0 - 1)/\theta_0^2\), computed from the ODE data, is 0.062500358 at \(\theta_0 = 0.01\) and tends to \(1/16\) as \(\theta_0 \to 0\); at 0.01 it still contains \(c_4\theta_0^2 = 3.6\times10^{-7}\).
  • A least-squares fit of \(c_2 + c_4\theta_0^2 + c_6\theta_0^4\) on \(\theta_0\in[0.05, 0.5]\) (5 points) gives \(c_2 = 0.062500003309\) and \(c_4 = 0.00358032\) from the ODE data, and \(c_2 = 0.062500003308\) from the mpmath data.
  • Richardson extrapolation from the ODE data at 0.05 and 0.1 rad gives \(c_2 = 0.062499994\).
  • The remaining errors, of a few times \(10^{-9}\), come from truncating the fit, not from the integration.

Agreement

  • Symbolic, two routes. The elliptic-integral series (S3–S4) and the Lindstedt–Poincaré expansion of the equation of motion (S5) agree exactly through \(\theta_0^6\); the difference is identically 0. The series from SymPy's elliptic_k also agrees exactly.
  • Symbolic against numerical. The truncated series matches the mpmath exact value with a relative error that shrinks by the expected order:
    • at \(\theta_0=0.1\): \(-3.6\times10^{-7}\) at order 2, \(-2.3\times10^{-10}\) at order 4, \(-1.4\times10^{-16}\) at order 8;
    • at \(\theta_0=0.5\): \(-2.2\times10^{-4}\), \(-3.7\times10^{-6}\) and \(-1.4\times10^{-9}\) at the same orders.
  • Numerical routes. scipy, the AGM and mpmath agree to within \(1.3\times10^{-15}\). The ODE integration (quarter period) agrees with mpmath to within \(1.3\times10^{-14}\) at every amplitude. The half-period estimate agrees to within \(1.6\times10^{-14}\), except \(9.4\times10^{-13}\) at 3 rad, close to the separatrix. These differences are at least 6000 times smaller than the relative error of the second-order formula at every amplitude (the smallest of those errors is \(3.6\times10^{-11}\), at 0.01 rad), so the comparison with the second-order formula gives the same result against either route.
  • \(c_2\). The value fitted from numerical data alone, 0.0625000033, matches the exact \(1/16\) to within \(3.3\times10^{-9}\).

Sanity checks

  • Small amplitude. At \(\theta_0 = 10^{-8}\), mpmath gives \(T/T_0 - 1 = 6.25\times10^{-18}\), which equals \(\theta_0^2/16\).
  • Scaling of the residual. The log–log slope of \(T/T_0 - 1 - \theta_0^2/16\) against \(\theta_0\) on \([0.01, 0.3]\) is 4.0014 from the mpmath data and 4.0014 from the ODE data. Residual\(/\theta_0^4\) tends to \(c_4 = 11/3072 \approx 0.0035807\).
  • Near the separatrix, \(\theta_0\to\pi\). \(T/T_0\) approaches \((2/\pi)\ln(4/\cos(\theta_0/2))\): 3.348496 against 3.348203 at 3.1 rad, and 7.2358741 against 7.2358741 at 3.1415 rad. The period diverges logarithmically, as expected.
  • Sign. \(c_2 > 0\): larger swings are slower. The second-order formula underestimates \(T\) at every amplitude tested.
  • Dimensions. \(T/T_0\) is dimensionless, and the mass drops out at the first step (S1).

Data files

  • computations/C-S1-2.periods.csv: 13 rows (amplitudes \(\theta_0\) from 0.01 to 3 rad) × 11 columns. The columns are:
    • theta0_rad, the amplitude in rad;
    • \(T/T_0\) (dimensionless) from mpmath, given as a 20-digit string, and from scipy, the AGM, the ODE quarter period and the ODE half period;
    • the second-order value \(1 + \theta_0^2/16\);
    • the relative error of the second-order formula against mpmath;
    • the residual \(T/T_0 - 1 - \theta_0^2/16\), and the residual divided by \(\theta_0^4\);
    • ODE minus mpmath.