I have no idea how to write in Python. Please help me with this! Best answer if you write the program!
Central Limit Theorem I
Goal
Write a python program that will use your accept / reject Monte Carlo algorithm to
demonstrate the central limit theorem.
Recall:
The central limit theorem states that if s = ∑j=1 N xj
(ie. s is a sum of M random variables x1, ..., xM), then the distribution of s approaches a Gaussian distribution as M increases.
Here the index j is being used to indicate different variables. Furthermore, the mean of
the resulting Gaussian is just the sum of means of each of the xj and the σ² of the
resulting Gaussian is the sum of σ² for each of the xj.
In general, there could be a different distribution for each of the xj. For instance, f(x1)
might be a Gaussian, while f(x2) might be our absolute |x2| function above, and f(x3)
might be something totally different. For this problem, we consider the case where all
the xj are sampled from the same distribution (the |x| distribution from above).
Your program should perform N Monte Carlo ‘experiments’. Each experiment will
produce one value for s, which will come from summing over M ‘measurements’ of x1, ..., xM.
Instructions:
1. form a loop of N experiments. For each experiment use acceptReject(M) to
produce M measurements of {xi} and calculate the sum s using “np.sum( ... )”.
2. plot a normalized histogram of the variable s
3. overlay a Gaussian distribution with a mean and standard deviation expected from
the central limit theorem for that value of M.
4. make plots for N=10,000 and M=1,2,4,8,16, 32
Hint: The standard deviation of f(x)=|x| for x in the range [-1,1] is √½:
σ² = ∫ f(x) (x-µ)² dx = 2 ∫₀¹ x (x-0)² dx = 1/2