# number of simulations
N <- 1000
# simulate random break point
X <- runif(N, min = 0, max = 1)
# length of the longer piece
L <- pmax(X, 1 - X)
cat("Expected Length of Longer Piece:", mean(L))Expected Length of Longer Piece: 0.7503822
Definition 44.1 (Uniform distribution) Let \(a\) and \(b\) be two given real numbers such that \(a<b\). Let \(X\) be a random variable such that it is known that \(a\leq X\leq b\) and, for every subinterval of \([a,b]\), the probability that \(X\) will belong to that subinterval is proportional to the length of that subinterval. We then say that the random variable \(X\) has the Uniform distribution on the interval \([a,b]\). The PDF of \(X\) is \[f(x)=\begin{cases} \frac{1}{b-a} & \textrm{for }a\leq x\leq b\\ 0 & \textrm{otherwise} \end{cases}\]
This is a valid PDF since \[\int_{-\infty}^{+\infty}f(x)dx=\int_{a}^{b}\frac{1}{b-a}dx=\frac{1}{b-a}\int_{a}^{b}dx=1.\]
The CDF of \(X\) is
\[F(x)=\int_{-\infty}^{x}f(t)dt=\int_{a}^{x}f(t)dt=\begin{cases} 0 & x<a\\ \frac{x-a}{b-a} & a\leq x\leq b\\ 1 & x>b \end{cases}.\]
The expectation of \(X\):
\[E(X)=\int_{a}^{b}x\frac{1}{b-a}dx=\frac{1}{b-a}\left[\frac{x^{2}}{2}\right]_{a}^{b}=\frac{a+b}{2}.\]
To figure out the variance, first compute
\[E(X^{2})=\int_{a}^{b}x^{2}\frac{1}{b-a}dx=\frac{1}{b-a}\left[\frac{x^{3}}{3}\right]_{a}^{b}=\frac{a^{2}+ab+b^{2}}{3}\]
Thus,
\[Var(X)=E(X^{2})-E^{2}(X)=\frac{a^{2}+ab+b^{2}}{3}-\frac{(a+b)^{2}}{4}=\frac{(b-a)^{2}}{12}.\]
Example 44.1 (Longer piece of a broken stick) A stick of unit length is broken at a random point X. What is the expected length of the longer piece?
Solution. The lengths of the two pieces are \(X\) and \(1-X\), with \(X\sim U(0,1)\). The longer piece is \(\max(X,1-X)\). For \(X<0.5\), the longer piece is \(1-X\), and for \(X\geq0.5\), it is \(X\). The expected value is: \[E[\max(X,1-X)]=\int_{0}^{0.5}(1-X)\,dx+\int_{0.5}^{1}X\,dx=\frac{3}{4}.\]
Intuition might suggest that since the stick is broken at a random point, the longer piece should be “somewhat larger” than the shorter piece, but not as large as 3/4. However, the uniform distribution of the break point means that the longer piece can sometimes be much larger than the shorter piece, especially when the break point is close to one end.
# number of simulations
N <- 1000
# simulate random break point
X <- runif(N, min = 0, max = 1)
# length of the longer piece
L <- pmax(X, 1 - X)
cat("Expected Length of Longer Piece:", mean(L))Expected Length of Longer Piece: 0.7503822
Example 44.2 (Buffon’s needle revisited) A plan is ruled by the lines \(y=0,\pm 1,\pm 2,...\) and a needle of unit length is cast randomly on to the plane. What is the probability that it intersects some line?
Solution. Let \(Z\) be the distance from the needle’s center to the nearest line beneath it. Let \(\Theta\) be the angle made by the needle and the \(x\)-axis. The fact that the needle is cast randomly means \(Z\sim U(0,1)\), \(\Theta\sim U(0,\pi)\) and \(Z\) and \(\Theta\) are independent. Thus the joint density function of \((Z,\Theta)\) is \[f(z,\theta)=\frac{1}{\pi},\quad 0\leq z\leq 1,0\leq\theta\leq\pi.\] An intersection occurs if and only if (draw a diagram to see this): \[z \leq\frac{1}{2}\sin\theta\textrm{ or }1-z \leq\frac{1}{2}\sin\theta\] Hence \[\begin{aligned} P(\text{intersection}) & =\frac{1}{\pi}\int_0^\pi\left( \int_0^{\frac{1}{2}\sin\theta}dz + \int_{1-\frac{1}{2}\sin\theta}^1 dz \right)d\theta \\ &= \frac{2}{\pi}. \end{aligned}\]