# What are the mean and standard deviation of the probability density function given by p(x)=k-x+xe^(-x^2)  for  x in [0,4], in terms of k, with k being a constant such that the cumulative density across the range of x is equal to 1?

Apr 10, 2016

$\mu = - 3.89$
$\sigma = 5.2$

#### Explanation:

Given: $p \left(x\right) = k - x + x {e}^{- {x}^{2}}$ for $x \in \left[0 , 4\right]$

Required: Mean and Standard Deviation

Solution Strategy:
1) Normalize $p \left(x\right)$, i.e. determine the $k : P \left(x\right) = {\int}_{0}^{4} p \left(x\right) \mathrm{dx} = 1$
2) Calculate the mean, $\mu = {\int}_{0}^{4} x p \left(x\right) \mathrm{dx}$
3) Calculate the standard deviation, $\sigma = {\int}_{0}^{4} {\left(x - \mu\right)}^{2} p \left(x\right) \mathrm{dx}$

1) $P \left(x\right) = {\int}_{0}^{4} \left[k - x + x {e}^{- {x}^{2}}\right] \mathrm{dx} = 1$ Apply linearity and write
$1 = {\int}_{0}^{4} k \mathrm{dx} - {\int}_{0}^{4} x \mathrm{dx} + {\int}_{0}^{4} x {e}^{- {x}^{2}} \mathrm{dx}$
$1 = k x - {x}^{2} / 2 + {\int}_{0}^{4} x {e}^{- {x}^{2}} \mathrm{dx}$ Let's deal with the 3rd integral
$I = {\int}_{0}^{4} x {e}^{- {x}^{2}} \mathrm{dx} , \text{ let } u = - {x}^{2}$
$I = - \frac{1}{2} \int {e}^{u} \mathrm{du} = - \frac{1}{2} {e}^{u}$ Undo substitution
$I = - \frac{1}{2} {\left[{e}^{- {x}^{2}}\right]}_{0}^{4} = \frac{1}{2} - \frac{1}{2 {e}^{16}} = \frac{{e}^{16} - 1}{2 {e}^{16}} \to \frac{1}{2}$
$1 = 4 K - 8 + \frac{1}{2} \implies K = \frac{17}{8}$
Check: $\frac{17}{2} - \frac{16}{2} + \frac{1}{2} = 1$

Thus $p \left(x\right) = \frac{17}{8} - x + x {e}^{- {x}^{2}}$

2) Mean: $\mu = {\int}_{0}^{4} x \left[\frac{17}{8} - x + x {e}^{- {x}^{2}}\right] \mathrm{dx}$
$\mu = {\int}_{0}^{4} \frac{17}{8} x \mathrm{dx} - {\int}_{0}^{4} {x}^{2} \mathrm{dx} + \textcolor{red}{{\int}_{0}^{4} {x}^{2} {e}^{- {x}^{2}} \mathrm{dx}}$
$= {\left\{\frac{17}{16} {x}^{2} - {x}^{3} / 3 + \textcolor{red}{\sqrt{\pi} \frac{\text{erf} \left(x\right)}{4} - \frac{x}{2 {e}^{{x}^{2}}}}\right\}}_{0}^{4}$

$\approx \frac{17}{16} \cdot 16 - \frac{64}{3} + \textcolor{red}{.443} \approx - 3.89$

3) ${\sigma}^{2} = {\int}_{0}^{4} {\left(x - 3.89\right)}^{2} \left[\frac{17}{2} - x + x {e}^{- {x}^{2}}\right] \mathrm{dx}$

$\approx 27.23134392285682$

$\sigma = \sqrt{27.23134392285682} \approx 5.2$