Packing radios into cartons - why is my solution wrong? A manufacturer of car radios ships them to retailers in cartons of $n$ radios. The profit per radio is $\$59.50$, minus shipping cost of $\$25$ per carton, so the profit is $59.5n-25$ dollars per carton. To promote sales by assuring high quality, the manufacturer promises to pay the retailer $\$200X^2$ if $X$ radios in the carton are defective. Suppose radios are produced independently and that $5\%$ of radios are defective. How many radios should be packed per carton to maximize expected net profit per carton?
My solution:
Suppose that $n$ radios are packed into a carton. Then, the expected profit is clearly $$\mu = 59.5n-25-200(0.05n)^2$$ Simplifying we get $$\mu = 59.5n-25-0.5n^2$$
We want to find a maximum, so we find a derivative:
$$\mu'=59.5-n^2$$
Clearly there is just one maximum, so set $\mu'=0$ we find that $$n^2=59.5$$ and thus $$n\approx 7.7136\dots$$This however seems to be wrong. The textbook gives an answer of exactly $50$ in the solution without any explanation of the steps.
 A: $X$ is binomially distributed with $n$ trials and success probability $0.05$.  For any random variable $X$ whose mean and variance exist,
\begin{eqnarray*}
{\Bbb E}X^2&=&({\Bbb E}X)^2+\text{Var } X,
\end{eqnarray*}
and since the mean and variance of a binomial distribution with $n$ trials and success probability $p$ are $np$ and $np(1-p)$, in this case this equals
\begin{eqnarray*}
&&(0.05 n)^2+n\cdot 0.05 \cdot (1-0.05)\\
&=& 0.0025 n^2+0.0475 n
\end{eqnarray*}
and the expected profit is
\begin{eqnarray*}
&\ &59.5n-25-200{\Bbb E}X^2\\
&=&59.5n-25-0.5n^2-9.5n\\
&=&1225-\frac 12 (n-50)^2,
\end{eqnarray*}
which is maximized at $n=50$.
A: The expected loss isn't just $(0.05n)^2$, you must compute its average the hard way ($\mathbb{E}(x^2) \ne (\mathbb{E}(x))^2$ in general!). If the probability of $n$ ones broken is $p_n$, your expected loss due to breakage is
$$
\sum_{n \ge 0} p_n \cdot 200 n^2 = 200 \sum_{n \ge 0} p_n n^2
$$
Presumably you can start assuming that the number of radios in each box isn't limited, that should give a starting point. Once you have an approximate number of radios per box, refine.
A: The profit $Y$ is given by
$$Y=59.5n -25-200 X^2,$$
where $X$ is the number of defectives.
The number of defectives has binomial distribution, with $p=0.05$. 
We want to find $E(X^2)$. There are various ways to do this. One way is to recall that the relevant binomial has mean $np$ and variance $np(1-p)$. But the variance of $X$ is $E(X^2)-(E(X))^2. So E(X^2)=np(1-p) +n^2p^2$.  
There are various other ways to find $E(X^2)$.
So we are maximizing $59.5n-25-200np(1-p)-200n^2p^2$, which in this case is $-(0.5n^2 -50n  +25)$. 
For the maximization, complete the square, or use calculus.  
The answer does turn out to be exactly $50$. 
Remark: You asked why your answer was wrong. One way was uninteresting. You differentiated $59.5n-0.5n^2$ and got $59.5-n^2$ instead of the correct $59.5-n$.
That would have given an answer of $59.5$, say $60$-ish.
The actual answer is less, and for an interesting reason. The penalty for bad radios is $200X^2$. This is quite sensitive to large values of $X$. Roughly speaking that explains why the optimal number of radios is smaller than the $59.5$ given by your method.   
