Exercise: Central Limit Theorem

In this exercise we will show what is the Central Limit Theorem and how it applies

Part 1: Generate random number according to a uniform distriobution

The first goal is to generate n random numbers according to a uniform distribution between [-1,1], fill an histogram and compute the average of the generated numbers. Display also the obtained histogram.

Let's start with n = 10


In [1]:
int n = 10; 
TRandom3 r(0);  // initialize with zero to have a random seed

Create and book the histogram


In [ ]:

Generate the numbers and fill the histogram. You can compute the average directly or let the histogram computing it for you


In [ ]:

Display the histogram and print out the average result


In [ ]:

Part 2: Study the distribution of the sample mean composed of n numbers uniformly distributed

Now repeat many times what has been done before to study the distribution of the average, $\mu$. The exercise will show that this distribution will converge very quickly to a Gaussian distribution. It is enough to have a very small $n$ to get already a pretty good Gaussian. For having the sigma of the distribution indipendent on the number of generated events $n$, we will make an histogram of $\sqrt{n} \times \mu$.

Do then as following:

  • Make a loop where for each time $n$ uniform numbers are generated and their average $\mu$ is computed.
  • Make an histogram now of $\sqrt{n} \times \mu$.

Start using a very small $n$ (e.g. $n=3$) but use for the loop, which performs the generation of $n$ numbers, a large value (e.g. $n_{experiments} = 10000$.


In [2]:
hout = new TH1D("h","Distribution of average values",50,-2,2);
int nexp = 10000;

In [3]:
n = 2;
hout->Reset(); // for running this cell a second time
for (int i = 0; i < nexp; ++i){ 
   // generate n uniform numbers, compute average and fill histogram 
}

Part 3: Fit the obtained histogram with a Gaussian function

we perform now a fit with a Gaussian distribution and see how the obtained data agree with the function


In [ ]:

Repeat the operation above by increasing $n$ to a larger value (e.g. $n=10$). For the Central Limit Theorem as $n$ is increased the obtained distribution will converge to a Gaussian.

Question : What is the computed standard deviation of the distribution when we generate $n$ uniform number between [-1,1] ? What will be then the $\sigma$ if I generate the number between [$-\sqrt{3},\sqrt{3}$] ?