"""Tick swings a weight on a string of three lengths and times one full swing of each.""" import math import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from labkit import const, versions # noqa: E402 from tick import Pendulum # noqa: E402 DT = 1e-5 g = const.g_n.to("m/s^2").magnitude print(f"simulated: Tick {__import__('tick').__version__}, pendulum stepped by its angle, dt = {DT} s, g = {g} m/s^2, released 5 degrees from straight down") print(f"({versions()})") print() print(" string one full swing sqrt(L/g) swing / sqrt(L/g)") for length in (0.25, 1.0, 4.0): p = Pendulum(length=length, angle=math.radians(5), g=g) crossings, last = [], p.angle while len(crossings) < 3: p.step(DT) if last > 0 >= p.angle: # interpolate the moment the angle passed through zero frac = last / (last - p.angle) crossings.append(p.t - DT + frac * DT) last = p.angle period = crossings[2] - crossings[1] root = math.sqrt(length / g) print(f" {length:>5.2f} m {period:>12.3f} s {root:>7.3f} s {period / root:>17.3f}") print() print("The missing pure number is the same for every length, and has no units.")