We now find the mean and variance of a rectangular distribution.

Example

What are the mean and variance of the \(\RectDistn(a, b)\) distribution?

This distribution has probability density function

\[ f(x) = \begin{cases} \dfrac 1 {b-a} & \quad \text{for } a \lt x \lt b \\[0.5em] 0 & \quad \text{otherwise} \end{cases} \]

The distribution's mean is

\[ \begin{align} E[X] \;\;=\;\; \int_{-\infty}^{\infty} {x \times f(x) \; d x} &\;\;= \int_a^b {x \times \frac 1 {b-a} \; d x} \\ &\;\;= \left[\frac {x^2} 2 \times \frac 1 {b-a} \right]_a^b \\ &\;\;= \frac {b^2 - a^2} {2 (b-a)} \\ &\;\;= \frac {a+b} 2 \end{align} \]

To get the distribution's variance, we first find

\[ \begin{align} E[X^2] \;\;=\;\; \int_{-\infty}^{\infty} {x^2 \times f(x) \; d x} &\;\;= \int_a^b {x^2 \times \frac 1 {b-a} \; d x} \\ &\;\;= \left[\frac {x^3} 3 \times \frac 1 {b-a} \right]_a^b \\ &\;\;= \frac {b^3 - a^3} {3 (b-a)} \\ &\;\;= \frac {a^2 + ab + b^2} 3 \end{align} \]

From this,

\[ \begin{align} \Var (X) \;=\; E[X^2] - \left( E[X] \right)^2 \;&=\; \frac {a^2 + ab + b^2} 3 - \left(\frac {a+b} 2 \right)^2 \\ &=\; \frac {4(a^2 + ab + b^2) - 3(a^2 + 2ab + b^2)} {12} \\ &=\; \frac {(b-a)^2} {12} \end{align} \]