Let \(\mathrm{f}(x)=\dfrac{\sin(n+\frac{1}{2})x}{\sin\frac{1}{2}x}\) for \(0 < x\leqslant\pi.\)
Using the formula
\[
2\sin\tfrac{1}{2}x\cos kx=\sin(k+\tfrac{1}{2})x-\sin(k-\tfrac{1}{2})x
\]
(which you may assume), or otherwise, show that
\[
\mathrm{f}(x)=1+2\sum_{k=1}^{n}\cos kx\,.
\]
Find \({\displaystyle \int_{0}^{\pi}\mathrm{f}(x)\,\mathrm{d}x}\) and \({\displaystyle \int_{0}^{\pi}\mathrm{f}(x)\cos x\,\mathrm{d}x}.\)