We have to find
$$g(x)=\cos{x}+\cos{3x}+\cos{5x}+\cdots+\cos{(2n-1)x}$$
I could not get any good idea .
Intialy I thought of using
$$\cos a+\cos b=2\cos(a+b)/2\cos (a-b)/2$$
We have to find
$$g(x)=\cos{x}+\cos{3x}+\cos{5x}+\cdots+\cos{(2n-1)x}$$
I could not get any good idea .
Intialy I thought of using
$$\cos a+\cos b=2\cos(a+b)/2\cos (a-b)/2$$
Following @TheDeadLegend's answer I found this telescoping technique. Turns out that you need a similar identity to make it work:
$$ \sin(\alpha + \beta) - \sin(\alpha - \beta) =2\cos \alpha \sin \beta$$
\begin{align} g(x) &= \sum_{k=1}^n \cos(2k-1)x \\ &= \frac{1}{2\sin x}\sum_{k=1}^n 2\cos(2k-1)x \cdot \sin x \\ &= \frac{1}{2\sin x}\sum_{k=1}^n \left[\sin 2kx - \sin2(k-1)x \right] \\ &= \frac{1}{2\sin x}(\sin 2nx-0) = \frac{\sin 2nx}{2\sin x}. \end{align}
Let $z=\cos\theta+i\sin\theta$ i.e. $z=e^{i\theta}$
Your sum:$$e^{i\theta}+e^{3i\theta}+e^{5i\theta}+...e^{(2n-1)i\theta}$$
This is a GP with common ratio $e^{2i\theta}$
Therefore sum is $$\frac{a(r^n-1)}{r-1}$$ $$\frac{e^{i\theta}(e^{2ni\theta}-1)}{e^{2i\theta}-1}$$ $$\frac{(\cos \theta+i\sin\theta)(\cos(2n\theta)+i\sin\theta-1)}{\cos(2\theta)+i\sin(2\theta)-1}$$
Computing it's real part should give you the answer
Acknowledgement:Due credits to @LordShark Idea