Continuous Uniform Distribution and its expectation and variance


Here I wrote the expectation and variance of a continuous uniform distribution. It is very simple calculation because of the simple density function.

Let’s consider the continuous uniform distribution, \(X \sim \textrm{Uniform}(a, b)\) . The density function, \(f(x)\), is as follows.

\[ f(x) = \begin{cases} 0 & (x \not \in [a, b] \\ \frac{1}{b – a} & (x \in [a, b]) \end{cases} \]

Expectation

\begin{eqnarray*} \textrm{E}(X) & = & \int _ {- \infty} ^ \infty x f(x) dx \\ &= & \int _{a} ^{b} x f(x) dx \\ &= & \frac{1}{b-a} \int _{a} ^{b} x dx \\ &=& \frac{1}{b – a} \left[ \frac{x^2}{2} \right] ^b _a \\ & = & \frac{1}{b – a} \left( b^2 – a^2 \right) \\ & =& \frac{a + b}{2} \end{eqnarray*}

Variance

\begin{eqnarray*} \textrm{V}(X) & = & \int _{-\infty} ^{\infty} f(x) \left( x – \textrm{E}(X) \right)^2 dx\\ & = & \int _{a} ^{b} f(x) \left( x – \frac{a + b}{2} \right) ^2 dx \\ & = & \frac{1}{b – a} \int _{a} ^{b} \left( x – \frac{a + b}{2} \right) ^2 dx \\ & = & \frac{1}{b – a} \left[ \frac{1}{3} \left( x – \frac{a + b}{2} \right) ^ 3 \right] _a ^ b \\ & = & \frac{1}{b – a} \left( \frac{1}{3} \left( \left( \frac{b-a}{2} \right) ^3 – \left( \frac{a – b}{2} \right) ^3 \right) \right) \\ &=& \frac{1}{b-a} \frac{1}{3} \frac{(b – a)^3}{4} \\ & = & \frac{1}{3} \frac{(b – a)^2}{4} \\ & = & \frac{(b-a)^2}{12} \end{eqnarray*}