$\int_{0}^{\pi} D_{n}(y)dy=\frac{1}{2}$ Dirichlet I need to calculate that $\int_{0}^{\pi} D_{n}(y)dy=\frac{1}{2}$ with $D_{n}(y)= \frac{1}{2\pi}\frac{\sin((n+\frac{1}{2})y)}{\sin(\frac{y}{2})}$ from Dirichlet.
Now I tried to do this with the known that $D_{n}(y)=\frac{1}{2\pi}\sum_{k=-1}^{n}e^{iky}$.
I tried to things but I never become 1/2.

*

*First I tried to solve the somation and then integrate: $\int_{0}^{\pi} D_{n}(y)dy=\int_{0}^{\pi} \frac{1}{2\pi}\sum_{k=-1}^{n}e^{iky}dy=\int_{0}^{\pi} \frac{1}{2\pi}(\frac{e^{-niy}-e^{iy(n+1)}}{1-e^{iy}})dy$. This integral doesn't converges so I did something wrong but I don't know what?



*Second I tried to switch the integral and the sommetion and then solve it: $\int_{0}^{\pi} D_{n}(y)dy=\int_{0}^{\pi} \frac{1}{2\pi}\sum_{k=-1}^{n}e^{iky}dy=\int_{0}^{\pi} D_{n}(y)dy=\frac{1}{2\pi}\sum_{k=-1}^{n}\int_{0}^{\pi}e^{iky}dy=\frac{1}{2\pi}\sum_{k=-1}^{n}\frac{1}{ik}(1-e^{-\pi i k})$. But this sometion will give $i\infty -i \infty$ so this doesn't work eather.

Can someone eplain me what I do wrong and how I can fix it?
 A: You're using a wrong definition of the Dirichlet kernel. The proper one is
$$D_n(x) = \frac{1}{2\pi}\sum_{k=-n}^n e^{ikx} = \frac{1}{2\pi}\frac{\sin \left(\frac{(n+1)x}{2}\right)}{\sin \left(\frac{x}{2}\right)}.$$
Based on that you have by switching $\int$ and $\sum$
$$\int_0^{2\pi}D_n(x) = \int_0^{2\pi}\frac{1}{2\pi}\sum_{k=-n}^n e^{ikx} = 1.$$
as $\int_{0}^{2\pi}e^{ikx}=0 $ for $k\neq 0$ integer.
And as $D_n$ is even
$$\int_0^{\pi}D_n(x) = \frac{1}{2}.$$
A: Note
$$2\sin\frac y2(\cos y + \cos2y+\cos3y+...+\cos ny)
= \sin\frac{(2n+1)y}2-\sin\frac y2 $$
Then
\begin{align}
 \int_{0}^{\pi} D_{n}(y)dy=&\frac{1}{2\pi}
\int_0^\pi \frac{\sin\frac{(2n+1)y}{2}}{\sin \frac y2}{\rm d}y\\
=&\frac{1}{2\pi} \int_0^\pi(1+2\cos x + 2\cos2x+...+2\cos nx){\rm d}x\\
=&\frac1{2\pi}[\pi + (0+0+...+0)]=\frac12 \end{align}
A: You have to do summation from -n to +n when identifying Dirichlet kernel, though your closed expression for the kernel is correct: $D_{n}(y)=\frac{1}{2\pi}\sum_{k=-n}^{n}e^{iky}=\frac{1}{2\pi}\frac{\sin((n+\frac{1}{2})y)}{\sin(\frac{y}{2})}=\frac{1}{2\pi}\frac{\sin(\frac{(2n+1)y}{2})}{\sin(\frac{y}{2})}$
$D_{n}(y)=\frac{1}{2\pi}\sum_{k=-n}^{n}e^{iky}=\frac{1}{2\pi}+\frac{1}{2\pi}\sum_{k=1}^{n}e^{iky}+\frac{1}{2\pi}\sum_{k=-1}^{-n}e^{iky}=\frac{1}{2\pi}+\frac{1}{2\pi}e^{iy}(1-e^{iyn})\frac{1}{1-e^{iy}}+\frac{1}{2\pi}e^{-iy}(1-e^{-iyn})\frac{1}{1-e^{-iy}}=\frac{1}{2\pi}\frac{e^\frac{iy}{2}-e^\frac{-iy}{2}-e^\frac{iy}{2}-e^{-iy(n+\frac{1}{2})}-e^\frac{iy}{2}+e^{iy(n+\frac{1}{2})}}{e^\frac{iy}{2}-e^\frac{-iy}{2}}=\frac{1}{2\pi}\frac{\sin((n+\frac{1}{2})y)}{\sin(\frac{y}{2})}$
