How to evaluate the following summation involving imaginary number if possible 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.
 A: It is possible to derive a formal series sum without regard to convergence quite simply.
Start with $\displaystyle S(\theta) = \sum_{n=1}^{\infty}e^{in\theta}$
and note that $\displaystyle -\frac{d^2}{d\theta^2}S(\theta)$ gives the expression for your required sum.
(Again, disregarding questions of convergence) you can say $\displaystyle S(\theta) = \frac{e^{i\theta}}{1-e^{i\theta}}$
and all that remains is to differentiate that twice and then flip the sign.
The "elephant in the room" is convergence and, as the others have pointed out, the series as written doesn't converge, so all this is fairly meaningless (to the best of my knowledge). I did plug this into Wolfram Alpha, and it claims that the series converges for $\Im(\theta) > 0$, and I don't know if that's true. But that seems to imply it's not convergent for real $\theta$.
A: 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}
$
A: You should ask your teacher in which sense the series "converges". Here is an idea. For the sake of simplicity let us consider the "basic" series
$$\sum_{n=0}^\infty e^{i n \theta} = \sum_{n=0}^\infty (e^{i \theta})^n .$$
It is a geometric series and it converges iff $\lvert e^{i \theta} \rvert < 1$. In that case we get $\sum_{n=0}^\infty e^{i n \theta} = \dfrac{1}{1-e^{i \theta}}$. For real $\theta$ it does definitely not converge. However, if $\theta = x + iy$, then $e^{i\theta } = e^{ix}e^{-y}$ and $\lvert  e^{i \theta} \rvert = e^{-y} < 1$ provided $y > 0$. In that case
$$\sum_{n=0}^\infty e^{i n \theta} = \dfrac{1}{1-e^{i \theta}} =  \dfrac{e^{y}}{e^{y}-e^{i x}} .$$
But now
$$\lim_{y \to 0} \dfrac{e^{y}}{e^{y}-e^{i x}} = \dfrac{1}{1-e^{i x}} .$$ 
If that should be the intention, then you can use the other answers (especially Deepak's answer) to find a "solution" for $\sum_{n=1}^\infty n^2 e^{i n \theta}$.
Edited:
The "physical" background does not clarify the motivation in considering series like $\sum_{n=1}^\infty n e^{i n \theta}$. It is physically clear that it cannot have a definite value. Let us again consider the basic case  $\sum_{n=1}^\infty e^{i n \theta}$. The physical interpretion is that we have a hexagon with vertices $v_k = e^{k i \pi/3}$, $k =1,\dots 6$, and succesively place point charges $c_1, c_2, c_3, \dots$ at the $v_k$, beginning at $v_1$ and going counterclockwise. Doing so, the electric field vector in the origin $E_m$ after having placed $c_1\dots,c_m$ takes six distinct values: $E_1,\dots E_5, E_6 = 0$ and then these values are repeated.
The situation is a little more complicated if we place multiple point charges $1c_1, 2c_2, 3c_3, \dots$ at the $v_k$, but again the electric field vector in the origin does not go to a definite value.
In my opinion your teacher is neither doing physics nor mathematics.
By the way, you can study a simplified model by considering only two vertices $w_1 = -1, w_2 = 1$ on the real line. Then place $1c_1$ at $w_1$, $2c_2$ at $w_2$, $3c_3$ at $w_1$ etc. You see that the electric field vector takes the values $-1,1,-2,2,-3,3, \dots$.
A: Set $z:=e^{i\theta}$. Then
$$S_0=\sum_{k=1}^n z^k=\frac{z^{n+1}-z}{z-1}.$$
$$z\,S_0'=z\sum_{k=1}^n k\,z^{k-1}=\sum_{k=1}^n k\,z^{k}=z\left(\frac{z^{n+1}-z}{z-1}\right)'.$$
$$z\,(z\,S_0')'=z\sum_{k=1}^n k^2\,z^{k-1}=\sum_{k=1}^n k^2\,z^{k}=z\left(z\left(\frac{z^{n+1}-z}{z-1}\right)'\right)'.$$
(The prime $'$ denotes differentiation on $z$.)
