# Expected value of a random variable $X$ with pmf $p_X(k)=(1/2)^k, k = 1,2,…,$

The Statement of the Problem:

For the random variable $X$ with pmf $p_X(k)=(1/2)^k, k = 1,2,...,$

(a) Calculate $E[X]$ and $E[X(X-1)]$.

(b) Use part (a) to compute Var$[X]$.

Where I Am:

Ok, so I plugged this problem into WolframAlpha to see what it had to say, and it said that the expected value is $\approx 1.27$. But then, when I put just the explicit formula for $E[X]$ in there, it returned the following:

$$\sum_{k=1}^{\infty} \frac{k}{2^k}=2$$

What gives?

EDIT: I figured out what I did wrong with W|A. It interpreted my variable as a normally-distributed r.v. instead of just a plain old natural number.

Hints: $$E(X)=\sum_{k=1}^\infty k\frac{1}{2^k}=2\sum_{k=1}^\infty\frac{k}{2^{k+1}}\cdot$$ To handle the RHS above, consider the function $f(x)=\sum_{k=1}^\infty\frac{1}{x^k}=\frac{1}{x-1}$ which is well-defined for $x>1$. Then $$\frac{1}{(x-1)^2}=-f'(x)=\sum_{k=1}^\infty\frac{k}{x^{k+1}}$$ and so $E(X)=2\times\frac{1}{(2-1)^2}=2$. For $E[X(X-1)]$, use a similar trick: $$E[X(X-1)]=\sum_{k=1}^\infty k(k-1)\frac{1}{2^k}=4\sum_{k=1}^\infty\frac{k(k-1)}{2^{k+2}}=4\left(\sum_{k=1}^\infty\frac{k(k+1)}{2^{k+2}}-\frac{1}{2}\sum_{k=1}^\infty\frac{k}{2^k}\right)$$ and consider $f''(x)$. Once you know $E[X(X-1)]$ and $E(X)$ then $$E(X^2)=E[X(X-1)]+E(X),\quad \text{Var}(X)=E(X^2)-E(X)^2.$$ As for the discrepancy with Wolfram Alpha, you need to check whether you have interacted with WA correctly as $\sum_{k=1}^\infty\frac{k}{2^k}=2$ is correct.

Note that

So $\sum_{k} \frac{k}{2^k} = 2$
For your question $X$ is basically a geometric random variable which denotes the number of trials needed to get the first success in an infinite sequence of Bernoulli trials with $P(success) = p = q = P(failure) = 0.5$.
Now, $$\begin{eqnarray} E(X) &=& \sum_{k=1}^{\infty} kp^k; \quad \text{actually }p = 1/2\\ &=& p \sum_{k=1}^{\infty} kp^{k-1}\\ &=& p \sum_{k=1}^{\infty} \frac{d}{dp} p^k\\ &=& p \frac{d}{dp}\sum_{k=1}^{\infty} p^k\\ &=& p \frac{d}{dp} \left(\frac{p}{1-p}\right)\\ &=& \frac{p}{(1-p)^2} \end{eqnarray}$$ Now put $p = \frac{1}{2}$.
Proceed in a similar way to compute $Var(X)$ and $E[X(X-1)]$.