Q8.2.4dblquad gotcha
What is wrong with the following attempt to calculate the area of the unit circle (\(\pi\)) as a double integral in polar coordinates?
In [x]: dblquad(lambda r, theta: r, 0, 1, lambda r: 0, lambda r: 2*np.pi)
Out[x]: (19.739208802178712, 2.1914924100062363e-13)
Show solution
The integral to be calculated is
\[\int_0^1\int_0^{2\pi} r \;\mathrm{d}\theta\,\mathrm{d}r = \pi.\]
Note that the inner integral is over \(\theta\) and the outer is over \(r\). Therefore, the call to dblquad should call the function \(f(r,\theta)=r\) as lambda theta, r: r (note the order of the arguments).
In [x]: dblquad(lambda theta, r: r, 0, 1, lambda r: 0, lambda r: 2*np.pi)
Out[x]: (3.141592653589793, 3.487868498008632e-14)
Alternatively, swap the order of the integration:
dblquad(lambda r, theta: r, 0, 2*np.pi, lambda theta: 0, lambda theta: 1)
(3.141592653589793, 3.487868498008632e-14)