import mpmath as mp
mp.mp.dps = 50
# These formulas cover the rectangle, disk, sector, annulus, and triangle rows.
def annulus_root():
def determinant(x):
return (mp.besselj(0, x) * mp.bessely(0, 2*x)
- mp.besselj(0, 2*x) * mp.bessely(0, x))
left = mp.mpf("3.0")
right = mp.mpf("3.2")
f_left = determinant(left)
f_right = determinant(right)
if f_left * f_right >= 0:
raise ValueError("the annulus bracket does not change sign")
for _ in range(250):
middle = (left + right) / 2
f_middle = determinant(middle)
if f_left * f_middle <= 0:
right = middle
f_right = f_middle
else:
left = middle
f_left = f_middle
return (left + right) / 2
values = [
("unit square", 2 * mp.pi**2),
("1 x 2 rectangle", 5 * mp.pi**2 / 4),
("unit disk", mp.besseljzero(0, 1)**2),
("half disk", mp.besseljzero(1, 1)**2),
("quarter disk", mp.besseljzero(2, 1)**2),
("annulus of radii 1 and 2", annulus_root()**2),
("sector of angle pi/3", mp.besseljzero(3, 1)**2),
("equilateral triangle", 16 * mp.pi**2 / 3),
("right-isosceles triangle", 5 * mp.pi**2),
("hemiequilateral triangle", 112 * mp.pi**2 / 9),
]
for name, value in values:
print(name, mp.nstr(value, 32))
The rectangle, disk, circular-sector, annulus and triangle rows are computed from the displayed formulas at two working precisions and compared. The L-shape value is transcribed from [1]'s hundred-digit computation and checked against the first value reported by [3].