# Expected value of a random variable with minimun

Let $M$ be a positive integer, and $X$ distributed $Geo (p)$. Calculate the expected value of $Y=min(X,M)$.

-

HINT: Write the definition of the expectation and split the sum into sums over subregions where $\min(X,M)$ resolves into $X$ or $M$: $$\mathbb{E}\left(\min(X,M)\right) = \sum_{k=0}^\infty \min(k,M) p (1-p)^k = \sum_{k=0}^{M-1} k p (1-p)^k + M \sum_{k=M}^\infty p (1-p)^k$$ Now evaluate sums. You should get: $$\mathbb{E}\left(\min(X,M)\right) = \frac{1-p}{p} \left(1- (1-p)^M \right)$$
Let $Y$ be the minimum of $X$ and $M$. Then for any $k$ with $1\le k\lt M$, we have $\Pr(Y=k)=(1-p)^{k-1}p$. The probability that $Y=M$ is the probability of $M-1$ failures in a row, which is $(1-p)^{M-1}$. Thus by the usual formula for expectation, we have $$E(Y)=\left(1\cdot p+2\cdot (p-1)p +\cdots +(M-1)\cdot (1-p)^{M-2}p\right)+ M(1-p)^{M-1}.$$ So we have found an answer. However, we may want to find a nicer expression for the bracketed expression above. Note that it is equal to $$p\left(1+2\cdot (p-1)+3\cdot (p-1)^2+\cdots +(M-1)\cdot (1-p)^{M-2}\right).$$ In order to cut down on the messiness of the expression, and for other reasons, let $x=1-p$. Then we want to find a simple expression for $$1+2x+3x^2+\cdots +(M-1)x^{M-2}.$$
we recognize this as the derivative of $$1+x+x^2+\cdots +x^{M-1}.$$ Now by the usual formula for the sum of a finite geometric series, we have $$1+x+x^2+\cdots+x^{M-1}=\frac{1-x^{M}}{1-x}.$$ Differentiate this, and all we need to do is to put the pieces together.