I am trying to find the following sum of a series about exponent of complex number $$\sum_{m=-M}^M\exp(imx)$$ where $M$ is integer and $x$ is continuous real variable. I have no idea how to compute the sum to get a close form. But I try mathematica and it gives me something like $$\cos(Mx) + \cot(x/2)\sin(Mx)$$
I don't know how does it give that results but I try to compare this results with numerical computation with matlab by choosing different M, they are matching well. So now I am trying to figure it out how to compute and get that result.
Here is what I did. The first idea comes to my mind is to use geometric series. I break the original sum into two parts: all positive exponents $$\sum_{m=0}^M\exp(imx)$$ and with negative one $$\sum_{m=-M}^{-1}\exp(imx)$$.
For the positive one, I know that (from sum of geometric series) $$ \sum_{m=0}^M\exp(imx) = \dfrac{1-\exp[i(M+1)x]}{1-\exp(ix)} $$
For the negative part, I have $$\sum_{m=-M}^{-1}\exp(imx)=\exp(-iMx)\dfrac{1-\exp(iMx)}{1-\exp(ix)}$$
If I combine and simplify both result, I got the same close form as before. However, my question is since $x$ is not a number, it is continuous variable, how does we assure that the series converges so the geometric sum's formular applicable? I remember in the text of high school, it is said that the sum of the geometric series converges only when the ratio of any two neighbouring terms less than 1. But our ratio term is not a number and also it is complex. So why the sum formular for geometric series still applied? Thanks.
That's because you have a finite sum. A finite sum/series of real numbers is always convergent. We don't have to worry about how its terms behave as the variable index goes to infinity, since the index does not go to infinity.