Solve $ \frac{2}{\pi}\int_{-\pi}^\pi\frac{\sin\frac{9x}{2}}{\sin\frac{x}{2}}dx $ Solve the following integral:
$$
\frac{2}{\pi}\int_{-\pi}^\pi\frac{\sin\frac{9x}{2}}{\sin\frac{x}{2}}dx
$$
 A: Such integral equals:
$$\frac{4}{\pi}\int_{-\pi/2}^{\pi/2}\frac{\sin(9x)}{\sin(x)}\,dx=\frac{4}{\pi}\int_{-\pi/2}^{\pi/2}\frac{e^{9ix}-e^{-9ix}}{e^{ix}-e^{-ix}}\,dx \tag{1}$$
that is:
$$ \frac{4}{\pi}\int_{-\pi/2}^{+\pi/2}\left(e^{8ix}+e^{6ix}+\ldots+1+\ldots+e^{-6ix}+e^{-8ix}\right)\,dx=\frac{4}{\pi}\int_{-\pi/2}^{\pi/2}1\,dx=\color{red}{4}\tag{2} $$
since $\int_{-\pi/2}^{\pi/2}\cos(2nx)\,dx = 0$.
A: By using
$$ \sin A-\sin B=2\cos(\frac{A+B}{2})\sin(\frac{A-B}{2})$$
one has
\begin{eqnarray}
&&\frac{2}{\pi}\int_{-\pi}^\pi\frac{\sin\frac{9x}{2}}{\sin\frac{x}{2}}dx\\
&=&\frac{2}{\pi}\int_{-\pi}^\pi\frac{\sum_{n=1}^4\bigg[\sin\frac{(2n+1)x}{2}-\sin\frac{(2n-1)x}{2}\bigg]+\sin\frac{x}{2}}{\sin\frac{x}{2}}dx\\
&=&\frac{2}{\pi}\int_{-\pi}^\pi\frac{\sum_{n=1}^42\cos(nx)\sin \frac{x}{2}+\sin\frac{x}{2}}{\sin\frac{x}{2}}dx\\\\
&=&\frac{2}{\pi}\int_{-\pi}^\pi\bigg[2\sum_{n=1}^4\cos(nx)+1\bigg]dx\\
&=&\frac{2}{\pi}\cdot2\pi\\
&=&4.
\end{eqnarray}
Here $$ \int_{-\pi}^{2\pi}\cos(nx)dx=0$$
is used.
A: $\newcommand{\bbx}[1]{\,\bbox[8px,border:1px groove navy]{\displaystyle{#1}}\,}
 \newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack}
 \newcommand{\dd}{\mathrm{d}}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,}
 \newcommand{\ic}{\mathrm{i}}
 \newcommand{\mc}[1]{\mathcal{#1}}
 \newcommand{\mrm}[1]{\mathrm{#1}}
 \newcommand{\pars}[1]{\left(\,{#1}\,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,}
 \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}}
 \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$
\begin{align}
&\bbox[5px,#ffd]{{2 \over \pi}\int_{-\pi}^{\pi}{\sin\pars{9x/2} \over \sin\pars{x/2}}\,\dd x} \\[5mm] = &\
{2 \over \pi}\oint_{\verts{z} = 1}{\pars{z^{9/2} - z^{-9/2}}/2\ic \over \pars{z^{1/2} - z^{-1/2}}/2\ic}\,{\dd z \over \ic z}
\\[5mm] = &\
-\,{2\ic \over \pi}\oint_{\verts{z} = 1}{1 \over z^{4}}
{z^{9} - 1 \over z - 1}\,\dd z
\\[5mm] = &\
-\,{2\ic \over \pi}\braces{2\pi\ic\bracks{z^{3}}\pars{z^{9} - 1 \over z - 1}}
\\[5mm] = &\
4\,\bracks{z^{3}}\pars{1- z}^{-1} =
\bbx{\ds{4}} \\ &
\end{align}
