Info

This question is closed. Reopen it to edit or answer.

How can I use this following script to demonstrate central limit theorem?

1 view (last 30 days)
clear
sim_length = 20*1000; %number of samples
N = 5;
X = -1 + 2*rand(N, sim_length); % generate N times 20000 ... uniformely distributed random variable matrix over (-1,1)
Z = sum(X); % take the column sum to obtain Z = \sum {n=1}ˆ5 X n
step = 0.04;
nbins = -10:step:10;
[Zd, y]= hist(Z,nbins); % generating histogram
pdf_Z = Zd/(sim_length*(step));
M = mean(Z); % evaluating mean of Z
V = var(Z); % evaluating variance of Z
Gd = 1/(sqrt(2 *pi * V))*exp(-0.5*(y - M).^2/V); % Gaussian ... distribution with same mean and varinace of Z
plot(y, pdf_Z,'o','color',[0 0 1]);
hold on;
plot(y, Gd,'-','color',[1 0 0]);
legend ('PDF of Z','Gaussian PDF');

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!