# Expectation of a discrete random variable that is case-defined from other discrete random variables

Background

The question arises from the following real-life situation: I buy a newspaper at 3 dollars and sell it at 6 dollars. I know the demand for news paper is a binomial random variable with $$n=12$$ and $$p=0.7$$, I want to maximise my expected profit.

Problem

The answer is obviously 8 because it is nearest to the expected demand for newspaper. But my question is about how this can be derived more vigorously. My attempt is as follows but I am stuck at the last step:

Let $$p$$ be the newspaper I purchased, and X be the demand for newspaper, then the profit is a discrete random variable with the following functional forms:

$$Y= \begin{cases} 6X-3p & X

The answer is obtained when the expectation of Y is obtained in terms of p. Then it is a function to be maximised. But the problem now is: how can the expectation of such a random variable that depends on another random variable be obtained? I would very appreciate a proof of why a method works.

• If you mean random variables $X$ and $Y$, answer is $Y$ is derived from $X$. $E(Y) = E(f(X))$ – user158565 Dec 16 '18 at 16:30
• but then Y also changes when X becomes greater than or equal to p, how should this be considered? – hephaes Dec 16 '18 at 17:02

Let $$N$$ be the the newspaper purchased. It is fixed and $$0\le N \le 12$$. Let $$p_i$$ probability of the demand for news paper being $$i$$, $$0\le i \le 12$$. It can be got by following the binomial distribution with parameters 12 and 0.7. Then
$$E(Y|N)=-3Np_0+(6-3N)p_1 + ... +[6(N-1)-3N]p_{N-1}+ 3N(p_N + ...+ p_{12})$$,