# Time 7, Exercise 2: simulating the swing and measuring the circular error import math g, L = 9.81, 1.0 SECONDS_PER_DAY = 86400 T0 = 2 * math.pi * math.sqrt(L / g) # small-swing period def measured_period(amplitude_deg, dt=1e-5): # Let the pendulum fall from rest at the given amplitude and time the first # crossing of the centre. That is a quarter of a full swing, so multiply by 4. theta = math.radians(amplitude_deg) omega = 0.0 accel = -g / L * math.sin(theta) t = 0.0 while theta > 0: theta += omega * dt + 0.5 * accel * dt * dt new_accel = -g / L * math.sin(theta) omega += 0.5 * (accel + new_accel) * dt accel = new_accel t += dt return 4 * t print("small-swing period:", round(T0, 4), "s") print("amplitude simulated T slower by seconds per day") for deg in (2, 5, 10, 30): T = measured_period(deg) slower = T / T0 - 1 print(f"{deg:>5} deg {T:.4f} s {slower * 100:.4f} % {slower * SECONDS_PER_DAY:.1f}") # Compare with the simple formula: fractional slowing is about theta^2 / 16 (theta in radians) for deg in (2, 5, 10, 30): theta = math.radians(deg) print(deg, "deg: theta^2/16 gives", round(theta ** 2 / 16 * 100, 4), "% ->", round(theta ** 2 / 16 * SECONDS_PER_DAY, 1), "s per day") # Output when run: # small-swing period: 2.0061 s # amplitude simulated T slower by seconds per day # 2 deg 2.0062 s 0.0086 % 7.5 # 5 deg 2.0070 s 0.0485 % 41.9 # 10 deg 2.0099 s 0.1921 % 166.0 # 30 deg 2.0410 s 1.7414 % 1504.6 # 2 deg: theta^2/16 gives 0.0076 % -> 6.6 s per day # 5 deg: theta^2/16 gives 0.0476 % -> 41.1 s per day # 10 deg: theta^2/16 gives 0.1904 % -> 164.5 s per day # 30 deg: theta^2/16 gives 1.7135 % -> 1480.4 s per day # Reading the output: the simulation and theta^2/16 agree closely for small swings. # At 30 degrees the clock would lose about 25 minutes a day, which is why clockmakers # wanted small arcs (the anchor escapement works at about 4 to 6 degrees).