Double Integral 75
Hard Changing the Order of Integration

Calculate the following integral over each of the two

Calculate the following integral over each of the two regions described below: $$ \iint_D |\cos(x+y)|\,dx\,dy. $$ $1^{\circ}$ $D$ is the square $0\leqslant x\leqslant\pi$, $0\leqslant y\leqslant\pi$.
$2^{\circ}$ $D$ is the triangle $0\leqslant y\leqslant x\leqslant\pi$.

Explanation of Method

Substituting $w=x+y$ for fixed $x$ turns the inner integral into $\int|\cos w|\,dw$ over an interval of length $\pi$ (Part $1^\circ$) or of length $x$ (Part $2^\circ$). In Part $1^\circ$ the interval always has length exactly $\pi$ — one full half-period of $|\cos w|$ — so the inner integral is the same constant for every $x$. In Part $2^\circ$ the interval $[x,2x]$ changes both its length and position as $x$ varies, so it must be split according to where it crosses the sign-change points $w=\frac\pi2$ and $w=\frac{3\pi}2$.

  1. Part $1^\circ$: use $\int_a^{a+\pi}|\cos w|\,dw=2$ for any $a$.
  2. Part $2^\circ$: split $x\in[0,\pi]$ into four sub-intervals according to how $[x,2x]$ straddles $\frac\pi2$ and $\frac{3\pi}2$.
  3. Integrate each piecewise antiderivative over its sub-interval and sum.

Part $1^\circ$ · Square $[0,\pi]\times[0,\pi]$

Step 1 · Integrate with respect to $y$

For fixed $x$, let $w=x+y$, so $dw=dy$; as $y$ runs $0\to\pi$, $w$ runs $x\to x+\pi$:

$$ \int_0^\pi |\cos(x+y)|\,dy = \int_x^{x+\pi} |\cos w|\,dw. $$

Since $|\cos w|$ has period $\pi$ and $\int_0^\pi|\cos w|\,dw=2$, the integral over any interval of length $\pi$ equals $2$:

$$ \int_x^{x+\pi}|\cos w|\,dw = 2. $$

Step 2 · Integrate with respect to $x$

$$ I_1 = \int_0^\pi 2\,dx = 2\pi. $$


Part $2^\circ$ · Triangle $0\leqslant y\leqslant x\leqslant\pi$

Step 1 · Reduce to a $w$-integral

As above, with $w=x+y$:

$$ I_2 = \int_0^\pi\int_0^x|\cos(x+y)|\,dy\,dx = \int_0^\pi\int_x^{2x}|\cos w|\,dw\,dx. $$

Step 2 · Split according to sign changes of $\cos w$

As $x$ runs from $0$ to $\pi$, the interval $[x,2x]$ (of length $x$) sweeps across the sign-change points $w=\frac\pi2$ and $w=\frac{3\pi}2$. This gives four sub-intervals:

$0\leqslant x\leqslant\frac\pi4$: $[x,2x]\subseteq\left[0,\frac\pi2\right]$, so $\cos w\geqslant0$ throughout: $$ \int_x^{2x}|\cos w|\,dw = \sin2x-\sin x. $$

$\frac\pi4\leqslant x\leqslant\frac\pi2$: $[x,2x]$ straddles $\frac\pi2$: $$ \int_x^{2x}|\cos w|\,dw = 2-\sin x-\sin2x. $$

$\frac\pi2\leqslant x\leqslant\frac{3\pi}4$: $[x,2x]\subseteq\left[\frac\pi2,\frac{3\pi}2\right]$, so $\cos w\leqslant0$ throughout: $$ \int_x^{2x}|\cos w|\,dw = \sin x-\sin2x. $$

$\frac{3\pi}4\leqslant x\leqslant\pi$: $[x,2x]$ straddles $\frac{3\pi}2$: $$ \int_x^{2x}|\cos w|\,dw = 2+\sin x+\sin2x. $$

Step 3 · Integrate each piece over $x$

$$ \int_0^{\pi/4}(\sin2x-\sin x)\,dx = \frac{\sqrt2}{2}-\frac12, $$

$$ \int_{\pi/4}^{\pi/2}(2-\sin x-\sin2x)\,dx = \frac\pi2-\frac12-\frac{\sqrt2}{2}, $$

$$ \int_{\pi/2}^{3\pi/4}(\sin x-\sin2x)\,dx = \frac{\sqrt2}{2}+\frac12, $$

$$ \int_{3\pi/4}^{\pi}(2+\sin x+\sin2x)\,dx = \frac\pi2+\frac12-\frac{\sqrt2}{2}. $$

Step 4 · Sum the four pieces

The $\pm\frac{\sqrt2}{2}$ and $\pm\frac12$ terms cancel in pairs across the four pieces, leaving only the two $\frac\pi2$ contributions:

$$ I_2 = \left(\frac{\sqrt2}{2}-\frac12\right) + \left(\frac\pi2-\frac12-\frac{\sqrt2}{2}\right) + \left(\frac{\sqrt2}{2}+\frac12\right) + \left(\frac\pi2+\frac12-\frac{\sqrt2}{2}\right) = \pi. $$


Additional Notes

Result

The solutions to the integral are:

$$ 1^{\circ}:\ \iint_D |\cos(x+y)|\,dx\,dy = 2\pi. $$ $$ 2^{\circ}:\ \iint_D |\cos(x+y)|\,dx\,dy = \pi. $$