How to solve this one? $$\sum_{k=1}^n q^k \sin(kx) = S(q,n)$$ where $n$ is natural number and $q$ is a real number
I already got the formula $$S(q,n) = \Im\left(\frac{q\exp(ix)(1-q^n\exp(nix))}{1-q\exp(ix)}\right)$$ but I don't know how to simplify the $1-q\exp(ix)$ using the formulas $$ \sin(φ)=\frac{\exp(iφ)-\exp(-iφ)}{2i}$$ $$ \cos(φ)=\frac{\exp(iφ)+\exp(-iφ)}{2}\,.$$
Let me recast your formula using $n-1$ instead of $n$, for convenience. First, we reduce the calculation to the sum of a geometric progression $$ \sum_{k=0}^{n-1} q^k \sin(kx) = \Im \sum_{k=0}^{n-1}(q\, e^{ix})^k = \Im \frac{1-(q\, e^{ix})^{n}}{1-q\, e^{ix}}\,,$$ where we have used $$ \sum_{k=0}^{n-1} s^k = \frac{1-s^n}{1-s} $$ (this is easily proved for $s\neq 1$ multiplying both sides by $1-s$ and noting the telescopic sum on the left-hand side; for $s\to1$, the right-hand side reduces to $n$). Now, $$ \frac{1-(q\, e^{ix})^{n}}{1-q\, e^{ix}} =\frac{1-q^n\cos(nx)-iq^n\sin(nx)}{1-q\cos x -iq \sin x}=(1-q\cos x+i q \sin x)\frac{1-q^n\cos(nx)-iq^n\sin(nx)}{(1-q\cos x)^2 + (q \sin x)^2}\,, $$ whose imaginary part is $$ \frac{q\sin x(1-q^n\cos(nx))-q^n \sin(nx) (1-q\cos x)}{(1-q\cos x)^2+(q \sin x)^2}\,. $$ Simplifying slightly, by means of trigonometric formulas, $$ \sum_{k=0}^{n-1} q^k \sin(kx) = \frac{q\sin x - q^n \sin(nx)+q^{n+1}\sin((n-1)x)}{1-2q\cos x+q^2}\,. $$