In a contest physics problem that asked to calculate the electric field at the center of a hexagon, our teacher derived the following equation and asked us to calculate the value. The equation is shown below.
$S=\sum_{n=1}^{\infty}n^2e^{in\theta}$
where $\theta=\frac{\pi}{3}$
I know how to calculate $S_2=\sum_{n=1}^{\infty}ne^{in\theta}$, which equals to $e^{i\theta}(\frac{1}{1-e^{i\theta}})^2$ but cannot come up with a method to get the value for the equation with a $n^2$ in it.
Supplement to my question
Some people pointed out in the comments that $\sum_1^\infty ne^{in\theta}$ doesn't converge. The point my teacher gave was that it doesn't matter if it diverges in this situation since we are focusing on the physics stuff but not rigorous mathematics.
I would describe the whole context of this problem to avoid confusion.
The initial question asks about the electric field generated in the center of a hexagon due to a series of point charges putting on vertexes with increasing electric quantity (increasing natural numbers in this problem) till the infinity. Then the approach we use is to put this hexagon on a complex plane where the center of the hexagon is the origin of the plane.
The vertexes, therefore, have fixed distance from the origin, and we set it to be $r$. The physics formula tells us that the electric field $E$ generated by the point charge is $E=\frac{Kq}{r^2}$ (It's not that important to know this formula, you will see later). Then, since our point charge with increasing electric quantity (increasing natural number), our total electric field on the center would be expressed as
$$E_{total}=\sum_1^\infty \frac{Knq}{r^2} e^{in\theta}$$ where $\theta =\frac{\pi}{3}$ since it's a hexagon. (The reason to include $e^{in\theta}$ is that the electric field is vector and we want it to have direction on the complex plane. The direction of the electric field due to a single point charge is the direction the charge points towards the location we want to calculate if the charge is positive.)
We can ignore $\frac{Kq}{r^2}$ since it's a constant, and we need to solve $\sum_1^\infty ne^{in\theta}$, and it can be written it separately as \begin{align*} 1e^{i\theta}+1e^{2i\theta}+1e^{3i\theta}...&=e^{i\theta}\frac{1}{1-e^{i\theta}}\\ +1e^{2i\theta}+1e^{3i\theta}...&=e^{2i\theta}\frac{1}{1-e^{i\theta}}\\ +1e^{3i\theta}...&=e^{3i\theta}\frac{1}{1-e^{i\theta}} \end{align*}
So our final answer for $E$ is $$E=\frac{kq}{r^2}e^{i\theta}\frac{1}{1-e^{i\theta}}\frac{1}{1-e^{i\theta}}$$
That's how we solve for $\sum_1^\infty ne^{in\theta}$, and so now my question is how can we solve for $\sum_1^\infty n^2e^{in\theta}$ since our teacher wants to challenge us and changes the question a bit.
Here is a naive start.
$\begin{array}\\ S(x) &=\sum_{n=1}^{\infty}n^2e^{inx}\\ \int S(x)dx &=\int \sum_{n=1}^{\infty}n^2e^{inx}dx\\ &=\sum_{n=1}^{\infty}n^2\int e^{inx}dx\\ &=\sum_{n=1}^{\infty}n^2\dfrac{ e^{inx}}{in}\\ &=\sum_{n=1}^{\infty}-ine^{inx}\\ &=-iE(x)\\ \text{so}\\ S(x) &=-iE'(x)\\ &=-i(e^{ix}(\frac{1}{1-e^{ix}})^2)'\\ \end{array} $