Evaluate $\sum_{n=1}^\infty \frac{n}{2^n}$. 
Evaluate $$\sum_{n=1}^\infty \frac{n}{2^n}$$

My Work:
$$\sum_{n=1}^\infty \frac{n}{2^n} = \sum_{n=1}^\infty n \left(\frac{1}{2}\right)^n$$
If we denote $f(x) = \sum_{n=1}^\infty nx^n$ then we wish to evaluate $f(1/2)$.
Now, $$\sum_{n=1}^\infty nx^n = x \sum_{n=1}^\infty nx^{n-1} = x\sum_{n=1}^\infty (x^n)' =  x\left(\sum_{n=1}^\infty x^n\right)' = x \left(\frac{-x}{1-x}\right)' = \frac{-x}{(1-x)^2}$$
Applying $x=1/2$ we get the wrong result of $-2$.
Where is my mistake?

Yet another solution (maybe less tricky).
You can express this as a double summation and exchange the order (this is directly related to the integration by parts):
\begin{align}
\sum_{n=1}^\infty \frac{n}{2^n} &= \sum_{n=1}^\infty \sum_{k=1}^n \frac{1}{2^n}\\
& = \sum_{n=1}^\infty \sum_{k=1}^\infty \frac{1}{2^n} 1_{k \leq n}\\
& = \sum_{k=1}^\infty \sum_{n=1}^\infty  \frac{1}{2^n} 1_{k \leq n}\\
& = \sum_{k=1}^\infty \sum_{n=k}^\infty  \frac{1}{2^n}\\
& = \sum_{k=1}^\infty \frac{1}{2^k}\frac{1}{1-\frac{1}{2}}\\
& = 2\sum_{k=1}^\infty \frac{1}{2^k}\\
& = 2.
\end{align}
