TITLE: How to calculate: $\sum_{n=1}^{\infty} n a^n$
QUESTION [18 upvotes]: I've tried to calculate this sum:
$$\sum_{n=1}^{\infty} n a^n$$
The point of this is to try to work out the "mean" term in an exponentially decaying average.
I've done the following:
$$\text{let }x = \sum_{n=1}^{\infty} n a^n$$
$$x = a + a \sum_{n=1}^{\infty} (n+1) a^n$$
$$x = a + a (\sum_{n=1}^{\infty} n a^n + \sum_{n=1}^{\infty} a^n)$$
$$x = a + a (x + \sum_{n=1}^{\infty} a^n)$$
$$x = a + ax + a\sum_{n=1}^{\infty} a^n$$
$$(1-a)x = a + a\sum_{n=1}^{\infty} a^n$$
Lets try to work out the $\sum_{n=1}^{\infty} a^n$ part:
$$let y = \sum_{n=1}^{\infty} a^n$$
$$y = a + a \sum_{n=1}^{\infty} a^n$$
$$y = a + ay$$
$$y - ay = a$$
$$y(1-a) = a$$
$$y = a/(1-a)$$
Substitute y back in:
$$(1-a)x = a + a*(a/(1-a))$$
$$(1-a)^2 x = a(1-a) + a^2$$
$$(1-a)^2 x = a - a^2 + a^2$$
$$(1-a)^2 x = a$$
$$x = a/(1-a)^2$$
Is this right, and if so is there a shorter way?
Edit:
To actually calculate the "mean" term of a exponential moving average we need to keep in mind that terms are weighted at the level of $(1-a)$. i.e. for $a=1$ there is no decay, for $a=0$ only the most recent term counts.
So the above result we need to multiply by $(1-a)$ to get the result:
Exponential moving average "mean term" = $a/(1-a)$
This gives the results, for $a=0$, the mean term is the "0th term" (none other are used) whereas for $a=0.5$ the mean term is the "1st term" (i.e. after the current term).

REPLY [2 votes]: Your approach is really quite good,
and a nice way of discovering the result,
as opposed to deriving an already known result.
The only change I would make is to
make the upper limit of the sum a variable,
and let that go to $\infty$ if you want.
Besides, the finite sum is often useful.
So, let
$S(a, m)=\sum_{n=0}^{m} n a^n$.
I prefer to have the sum start at $0$,
and it doesn't change the result.
Then 
$\begin{align}
S(a, m)
&=0+\sum_{n=1}^{m} n a^n\\
&= a\sum_{n=1}^{m} n a^{n-1}\\
&= a\sum_{n=0}^{m-1} (n+1) a^{n}\\
&= a\big(\sum_{n=0}^{m-1} n a^{n} + \sum_{n=0}^{m-1} a^{n}\big)\\
&=a(S(a, m-1)+T(a, m-1))\\
\end{align}
$
where
$T(a, m)= \sum_{n=0}^{m} a^{n}$.
We now do the same thing for $T$,
with the difference that the term for $n=0$ is not $0$.
$\begin{align}
T(a, m)
&=1+\sum_{n=1}^{m}  a^n\\
&= 1+a\sum_{n=1}^{m} a^{n-1}\\
&= 1+a\sum_{n=0}^{m-1} a^{n}\\
&=1+aT(a, m-1)\\
\end{align}
$
Since $T(a, m-1)
= T(a, m)-a^m$,
$T(a, m) = 1+a(T(a, m)-a^m)
=1+aT(a, m)-a^{m+1}$
so $T(a, m) = (a^{m+1}-1)/(a-1)$.
Putting this in the equation for $S$,
$S(a, m) = a(S(a, m-1)+\frac{a^m-1}{a-1})$.
Again, since $S(a, m-1) = S(a, m)-m a^m$,
$\begin{align}
S(a, m) &= a(S(a, m-1)+\frac{a^m-1}{a-1})\\
&= a(S(a, m)-m a^m+\frac{a^m-1}{a-1})\\
&= aS(a, m)+\frac{a(a^m-1)-m a^{m+1}(a-1)}{a-1}\\
&= aS(a, m)+\frac{a^{m+1}-a-m a^{m+2}+m a^{m+1}}{a-1}\\
&= aS(a, m)-\frac{m a^{m+2}+(m+1) a^{m+1}+a}{a-1}\\
\end{align}
$
so
$(a-1)S(a, m) = \frac{m a^{m+2}+(m+1) a^{m+1}+a}{a-1}$
and
$S(a, m) = \frac{m a^{m+2}+(m+1) a^{m+1}+a}{(a-1)^2}$.
If $|a| < 1$, if we let $m \to \infty$ in the expressions
for $T$ and $S$,
we get
$T(a, \infty) = 1/(1-a)$
and
$S(a, \infty) = a/(1-a)^2$.
Note that by writing
$S(a, m)$ (and, similarly, $T(a, m)$)
in two ways in terms of $S(a, m-1)$,
we avoided having to discover
the expression for $S(a, m)$.
Again, this is certainly not the best way to
$verify$ the formulas
for $S(a, m)$ and $T(a, m)$,
but it is a way to $discover$ them.