Changing the order of double integrals in polar coordinates. How do i change the order of the integrals of a multiple integral of the following: $\int_0^{2\pi}\int_0^{1+\cos(\theta)}r\text{ }dr\text{ }d\theta$ ?
 A: For each $r_0$ between $0$ and $2$, the circle $r = r_0$ and the cardioid $r = 1+ \cos\theta$ intersect at most two points between $-\pi$ and $\pi$:  $\cos^{-1}(r_0 - 1)$, and $- \cos^{-1}(r_0 - 1)$.  When $r_0=0$, both points are the origin; when $r_0 = 2$, both points are $(2,0)$.

(Screenshot from Desmos; you can adjust the circle radius to see the points.)
So 
$$
    \int_0^{2\pi} \int_0^{1+\cos\theta}r\,dr\,d\theta 
=   \int_0^2 \int_{-\cos^{-1}(r-1)}^{\cos^{-1}(r-1)}r\,d\theta\,dr
=  2\int_0^2 r\cos^{-1}(r-1) \,dr
$$
To evaluate this, first do integration by parts with $u = \cos^{-1}(r-1)$ and $dv = 2r$:
\begin{align*}
2\int_0^2 r\cos^{-1}(r-1) \,dr
    &= \left.r^2 \cos^{-1}(r-1)\right|^2_0 + \int_0^2 \frac{r^2}{\sqrt{1-(r-1)^2}}\,dr \\
    &= 2^2 (0) - 0^2 (-\pi) + \int_0^2 \frac{r^2}{\sqrt{1-(r-1)^2}}\,dr \\
\end{align*}
Now substitute $s=r-1$, $ds=dr$, so this is equal to:
$$
\int_0^2 \frac{r^2}{\sqrt{1-(r-1)^2}}\,dr
    = \int_{-1}^{1} \frac{(s+1)^2}{\sqrt{1-s^2}}\,ds
$$
Now substitute $s = \sin\theta$:
\begin{align*}
    \int_{-1}^{1} \frac{(s+1)^2}{\sqrt{1-s^2}}\,ds
    &= \int_{-\pi/2}^{\pi/2}\frac{(\sin\theta+1)^2}{\cos\theta}\,\cos\theta\,d\theta
    \\&= \int_{-\pi/2}^{\pi/2}(1 + 2\sin\theta + \cos^2\theta)\,d\theta
    \\&= \pi + 0 + \int_{-\pi/2}^{\pi/2} \left(\frac{1 + \cos(2\theta)}{2}\right)\,d\theta
    \\&= \pi + \frac{\pi}{2} + 0 = \frac{3\pi}{2}
\end{align*}
On the other hand, without switching the order,
\begin{align*}
    \int_0^{2\pi} \int_0^{1+\cos\theta}r\,dr\,d\theta 
    &= \frac{1}{2}\int_0^{2\pi}(1 + \cos\theta)^2\,d\theta 
     = \frac{1}{2}\int_0^{2\pi}\left(1 + 2\cos\theta+ \cos^2\theta\right)\,d\theta 
  \\&= \pi + 0 + \frac12\int_0^{2\pi} \left(\frac{1 + \cos(2\theta)}{2}\right)\,d\theta
  \\&= \pi + \frac{\pi}{2} + 0 = \frac{3\pi}{2}
\end{align*}
Given the choice, I prefer the second integral.
