# Variance of piecewise defined random variable

I have the random variable $$$$X = \begin{cases} 0 \;\; &\text{with probability }\frac{1}{2}\\ \exp(\frac{1}{\lambda}) \;\; &\text{with probability }\frac{1}{2} \end{cases}$$$$ I want to compute the variance of this random variable. I first compute the expected value. $$$$\mathbb{E}[X]=\mathbb{E}[\frac{1}{2}\cdot 0+\frac{1}{2}\cdot \exp(\frac{1}{\lambda})]=\frac{1}{2}\mathbb{E}[\exp(\frac{1}{\lambda})]=\frac{1}{2}\lambda$$$$ Next I want to compute the second moment of $$X$$. $$$$\mathbb{E}[X^{2}]=\mathbb{E}[(\frac{1}{2}\cdot 0+\frac{1}{2}\cdot\exp(\frac{1}{\lambda}))^{2}]=\frac{1}{4}\mathbb{E}[(\exp(\frac{1}{\lambda}))^{2}]=\frac{1}{4}\cdot2\lambda^{2}=\frac{1}{2}\lambda^{2}$$$$ This would give me the variance as, $$$$Var(X)=\mathbb{E}[X^{2}]-(\mathbb{E}[X])^{2}=\frac{1}{4}\lambda^{2}$$$$ My teacher told me that the variance should be equal to $$\frac{3}{4}\lambda^{2}$$. I believe that this would mean that the second moment should be equal to $$\lambda^{2}$$, but I can't seem to figure out how I should get that answer. Can someone tell me where I go wrong in my computation?

• Shouldn't $E X^2 = 0.5 * 0^2 + 0.5 *\exp(1/\lambda)^2$? That is, why are you squaring the probabilities? Apr 11, 2022 at 13:38

You seem to be using $$\exp(\frac1 \lambda)$$ to mean an exponentially distributed random variable with mean $$\lambda$$ and variance $$\lambda^2$$, rather than the value $$e^{1/\lambda}$$.
If so, then $$E[(\exp(\frac1 \lambda))^2] = Var(\exp(\frac1 \lambda))+(E[\exp(\frac1 \lambda)])^2 =\lambda^2+\lambda^2=2\lambda^2$$
which makes $$E[X]=\frac12 E[0]+\frac12 E[\exp(\frac1 \lambda)] = \frac12\lambda$$
and $$E[X^2]=\frac12 E[0^2]+\frac12 E[(\exp(\frac1 \lambda))^2] = 0+\frac12 2\lambda^2= \lambda^2$$
and so $$Var(X)= E[X^2]-(E[X])^2=\lambda^2-\frac14\lambda^2=\frac34\lambda^2$$.