A goat is tethered to a point on the perimeter of a circular paddock of grass by a rope of length \(r\). What should \(r\) be for the goat to be able to graze exactly half the area of the paddock?
This is a famous problem in recreational mathematics, the goat grazing problem, and is usually solved by approximate or numerical methods, despite being relatively easy to express in the form of a mathematical equation (derived below). The mathematician Ingo Ullisch [Math. Intelligencer 42, 12–16 (2020), doi:10.1007/s00283-020-09966-0] derived an exact solution in terms of the ratio of two contour integrals, which has been (generously) described as being in closed form:
Here we take the numerical approach (and return to Ullisch's formula at the end). Let the paddock be a unit circle, with area \(\pi\), centred at O, and let the goat be tethered at the point T on its perimeter. The extent of the goat's grazing area is illustrated below. Our job is to find the value of \(r\) that makes this area equal to \(\pi/2\).
First note four relations that will prove useful:
The first holds because the triangle OTP is isosceles (its sides OT and OP are both radii of the paddock), so that its angles at T and P are both \(\theta\); the second is the sine rule for triangles; and the third and fourth follow from the cosine rule.
The area of the circular sector TPQ, centred on T, is
the area of the circular sector OTP, centred on O, is
and the area of the triangle OTP is
using (2). The shaded region above the diameter TQ is made up of the sector TPQ and the segment of the paddock cut off by the chord TP, whose area is \(A_2 - A_3\). The area that the goat can graze is therefore \(A = 2(A_1 + A_2 - A_3)\), and the problem is to solve
for \(\alpha\) and hence \(r\). Using (1) and (3) to write \(\theta = \frac{1}{2}(\pi - \alpha)\) and \(r^2 = 2(1 - \cos\alpha)\) and rearranging yields
This equation is readily solved using, for example, the Newton–Raphson root-finding algorithm, as implemented by scipy.optimize.newton. The derivative of the left-hand side of (5), \(-(\pi - \alpha)\sin\alpha\), is passed as the argument fprime; without it, newton uses the secant method instead.
import numpy as np
from scipy.optimize import newton
def func(alpha):
return np.sin(alpha) + (np.pi - alpha) * np.cos(alpha) - np.pi / 2
def fprime(alpha):
return -(np.pi - alpha) * np.sin(alpha)
alpha_guess = np.pi / 2
alpha = newton(func, alpha_guess, fprime=fprime)
print(alpha)
1.2358969242799094
This value of \(\alpha\) is in radians. The corresponding rope length, \(r\), is given by (3):
r = np.sqrt(2 * (1 - np.cos(alpha)))
print(r)
1.1587284730181215
The grazable fraction of the paddock, \(A/\pi\), can be plotted as a function of the rope length, \(r\), as follows:
import matplotlib.pyplot as plt
rgrid = np.linspace(0, 2, 100)
cos_alpha = 1 - rgrid**2 / 2
alpha = np.arccos(cos_alpha)
theta = (np.pi - alpha) / 2
A = rgrid**2 * theta + alpha - np.sin(alpha)
plt.plot(rgrid, A / np.pi)
plt.hlines(0.5, 0, r, colors='k', linestyles='--')
plt.vlines(r, 0, 0.5, colors='k', linestyles='--')
plt.xlim(0, 2)
plt.ylim(0, 1)
plt.yticks([0, 0.5, 1])
plt.xlabel('$r$')
plt.ylabel(r'Fraction grazed, $A/\pi$')
plt.show()
Contour integrals
Ullisch's formula may be evaluated as follows. Writing \(z = \pi - \alpha\), which is \(2\theta\) by (1), turns (5) into \(\sin z - z\cos z = \pi/2\), so the denominator of both integrands,
is zero at the solution, \(z_0 = \pi - \alpha \approx 1.9057\). This is the only zero of \(g\) inside the circle \(|z - 3\pi/8| = \pi/4\), and it is a simple zero, since \(g'(z_0) = z_0\sin z_0 \ne 0\), so by the residue theorem
The ratio of the integrals is therefore \(z_0 = 2\theta\), and Ullisch's formula is relation (4), \(r = 2\cos\theta\), with \(2\theta\) written as a ratio of contour integrals. This ratio cannot be found symbolically (SymPy's solve function has no method for the equation \(g(z) = 0\), and so the integrals cannot be evaluated by residues either), but it is readily evaluated numerically. On the circle, \(z = 3\pi/8 + (\pi/4)e^{i\phi}\) and \(dz = i(\pi/4)e^{i\phi}\,d\phi\), which makes each integral one of a smooth, periodic function of \(\phi\) over \(0 \le \phi < 2\pi\). The trapezoidal rule converges geometrically (its error falls by a constant factor with each point added) for such integrals [L. N. Trefethen and J. A. C. Weideman, SIAM Rev. 56, 385–458 (2014), doi:10.1137/130932132], and here 16 points give \(r\) to seven significant figures and 32 points to 15:
c, R = 3 * np.pi / 8, np.pi / 4 # the centre and radius of the contour
N = 32
phi = np.linspace(0, 2 * np.pi, N, endpoint=False)
z = c + R * np.exp(1j * phi)
dz = 1j * R * np.exp(1j * phi) * (2 * np.pi / N)
g = np.sin(z) - z * np.cos(z) - np.pi / 2
ratio = np.sum(z / g * dz) / np.sum(dz / g)
print(ratio)
print(2 * np.cos(ratio.real / 2))
(1.9056957293098822+4.605279462319879e-17j)
1.1587284730181229
The real part of the ratio is \(\pi - \alpha\) and its imaginary part is rounding error; the rope length differs from the Newton–Raphson solution above only in the last two digits printed, which are also rounding error.