How do you program CLT?

18 views (last 30 days)
Bill King
Bill King on 4 Apr 2014
Answered: Image Analyst on 5 Apr 2014
Plot the histogram of 10000 random variables, where each random variable is the mean of n continuous uniform random variables.
Vary n from 1 to 10. The histogram should look increasingly Gaussian as n increases.
Demonstrate the CLT sum the following random variables that you should know how to generate (a) exponential λ = 1 (b) Bernoulli p = 0.5 (c) binomial (5, 0.5) (d) normal N(0, 1)

Accepted Answer

Roger Stafford
Roger Stafford on 5 Apr 2014
Bill, this seems like a rather straightforward assignment, demonstrating the famous central limit theorem. In what respect are you having difficulty with it? As I see it, you should create a 10000-by-n array for each of the values of n from 1 to 10, consisting of random numbers generated by the various required distribution types. That is surely straightforward. Then take the means of each row which will yield ten 10000-by-1 arrays - again very straightforward one-liners. Finally you need to produce histograms of each of these ten arrays, which will necessitate studying up on matlab's histogram functions.
I find the requirement of distribution (d), the normal distribution, rather curious. It is already entirely Gaussian, so what do they expect you to demonstrate there? How Gaussian can you get? All that will happen is a reduction in its standard deviation by one over the square root of n.

More Answers (2)

Image Analyst
Image Analyst on 5 Apr 2014
Hint:
n = 5 % for example.
rv = mean(rand(10000, n), 2) % Mean of n random numbers.
bar(rv) % just for display - to see them.

Joseph Cheng
Joseph Cheng on 4 Apr 2014
you can look at conv() which will do a rolling sum. With the rolling sum you just need to divide by the number of elements to get the rolling average.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!