Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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');

回答(0 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by