# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# %matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

# ### Set up a series of random uniform distributions
# The central limit theorem states that for random processes, if we measure the mean of independent random variates, the distribution of the means of those distributions will be Gaussianly distributed. This result is independent of the character of the random distribution. We can show this by using a collection of uniform random variates and measuring th emeans many times

n_exp=10000 #number of experiments
n_draw=10
n_bins=100
x_min=.15
x_max=.85
means=np.zeros(n_exp)

# ### Let's perform the experiment

# loop over the number of experiments
for i in range (n_exp):
    #pull 10 random variates from a uniform distribution
    z=np.random.uniform(0,1,n_draw)
    
    #record the mean
    means[i]=np.mean(z)


# ### Define a function to plat a Gaussian

def gaussian(x,mu,sigma):
    return 1/(2.0*np.pi*sigma**2)**.5 * np.exp(-.5*((x-mu)/sigma)**2)


# ### Make a histogram

# +
fig=plt.figure(figsize=(7,7))
y_hist,x_hist, ignored=plt.hist(means, bins=n_bins, range=[x_min,x_max], density=True)
xx=np.linspace(x_min,x_max,1000)

#set the RMS of the Gaussian
sigma=1/12**.5/10**.5

plt.plot(xx,gaussian(xx,.5,sigma), color="red")
plt.ylim([0,1.1*gaussian(.5,.5,sigma)])
plt.xlim([x_min,x_max])
#plt.gca().set_aspect(2)
plt.xlabel('x')
plt.ylabel('y(x)')
plt.show()
# -





StarcoderdataJupyterScriptsDedupFiltered