PaC Exercise 3.2
Posted on February 18, 2021
import numpy as np
Exercise 3.2
Let X be a number chosen uniformly at random from [ − k, k]. Find Var[X].
Solution: If we shifted X by k + 1, we would get the uniform distribution over [1, 2k + 1]. Therefore, by exercise 3.1 we have
$$
\mathrm{Var}[X] = \frac{(2k+1)^2 - 1}{12} = \frac{4k^2 + 4k}{12} = \frac{k^2+k}{3}.
$$
In particular, for k = 29 we get Var[X] = 290.
We verify this by simple sampling.
= 10**7
num_samples = 29
k
= np.random.randint(low=-k, high=k+1, size=num_samples)
samples
- samples.mean())**2) np.mean((samples
290.12070818521016