# Time 2, Exercise 2: the equation of time over a whole year # Scan all 365 days with the approximate formula, find the biggest sundial-fast # and sundial-slow days, and the clock time at which the Sun is highest on two # dates (ignoring the longitude offset from your time-zone meridian). import math def equation_of_time(day): b = math.radians(360 / 365 * (day - 81)) return 9.87 * math.sin(2 * b) - 7.53 * math.cos(b) - 1.5 * math.sin(b) values = {day: equation_of_time(day) for day in range(1, 366)} fast = max(values, key=values.get) slow = min(values, key=values.get) print("sundial furthest ahead: day", fast, round(values[fast], 1), "min") print("sundial furthest behind: day", slow, round(values[slow], 1), "min") print("total swing:", round(values[fast] - values[slow], 1), "min") crossings = [d for d in range(1, 365) if values[d] * values[d + 1] < 0] print("days where the sign changes:", crossings) for label, day in (("3 Nov", 307), ("11 Feb", 42)): e = values[day] noon = 12 * 3600 - e * 60 # seconds after midnight when the Sun is highest h, rem = divmod(round(noon), 3600) m, s = divmod(rem, 60) print(label, "Sun highest at", f"{h:02d}:{m:02d}:{s:02d}", "mean clock time") # Output when run: # sundial furthest ahead: day 304 16.5 min # sundial furthest behind: day 44 -14.6 min # total swing: 31.1 min # days where the sign changes: [105, 165, 242, 357] # 3 Nov Sun highest at 11:43:37 mean clock time # 11 Feb Sun highest at 12:14:36 mean clock time # # Reading the output: the sundial is at most about 16 minutes ahead (around # the start of November) and about 15 minutes behind (mid February), a swing of # roughly 31 minutes. It agrees with the clock four times a year, near mid April, # mid June, the end of August and just before Christmas. On 3 November the Sun # is highest about 16 minutes before 12:00, and on 11 February about 15 minutes after.