Learning Scientific Programming with Python (2nd edition)

P2.7.6: An integral of sine and cosine products

Question P2.7.6

Write a function, sinm_cosn which returns the value of the following definite integral for integers $m, n > 1$.

\begin{align*} \int_0^{\pi/2} \sin^n\theta\cos^m\theta\;\mathrm{d}\theta = \left[ \begin{array}{ll} \frac{(m-1)!!(n-1)!!}{(m+n)!!}\frac{\pi}{2} & \quad m,n \;\mathrm{both\;even,}\\ \frac{(m-1)!!(n-1)!!}{(m+n)!!} & \quad \mathrm{otherwise.} \end{array} \right. \end{align*}

Hint: For calculating the double factorial, see Question Q2.4.6.