MATLAB kommandoer som illustrerer sentralgrensesetningen (se avsnitt 5.3 i Rice)

 

% Vi bruker stokastisk simulering til ? se hvordan fordelingen til det standardiserte gjennomsnittet

% avhenger av n og av fordelingen til observasjonene (se den andre obligatoriske oppgaven for detaljer).

 

% F?rst trekker vi observasjonene fra den uniforme fordelingen over (0,1)

subplot(2,2,1)

n = 3;

X = unifrnd(0,1,n,10000);

meanX= mean(X);

m=1/2;

s=sqrt(1/12);

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Uniform n=3')

axis([-4,4,0,1000])

subplot(2,2,2)

n = 10;

X = unifrnd(0,1,n,10000);

meanX= mean(X);

m=1/2;

s=sqrt(1/12);

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Uniform n=10')

axis([-4,4,0,1000])

subplot(2,2,3)

n = 30;

X = unifrnd(0,1,n,10000);

meanX= mean(X);

m=1/2;

s=sqrt(1/12);

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Uniform n=30')

axis([-4,4,0,1000])

subplot(2,2,4)

n = 100;

X = unifrnd(0,1,n,10000);

meanX= mean(X);

m=1/2;

s=sqrt(1/12);

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Uniform n=100')

axis([-4,4,0,1000])

 

 

 

% S? trekker vi observasjonene fra eksponentialfordelingen med lambda=1

subplot(2,2,1)

n = 3;

X = exprnd(1,n,10000);

meanX= mean(X);

m=1;

s=1;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Eksponential n=3')

axis([-4,4,0,1000])

subplot(2,2,2)

n = 10;

X = exprnd(1,n,10000);

meanX= mean(X);

m=1;

s=1;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Eksponential n=10')

axis([-4,4,0,1000])

subplot(2,2,3)

n = 30;

X = exprnd(1,n,10000);

meanX= mean(X);

m=1;

s=1;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Eksponential n=30')

axis([-4,4,0,1000])

subplot(2,2,4)

n = 100;

X = exprnd(1,n,10000);

meanX= mean(X);

m=1;

s=1;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Eksponential n=100')

axis([-4,4,0,1000])

 

 

% Til slutt trekker vi observasjonene fra Bernoulli fordelingen med p=1/2.

subplot(2,2,1)

n = 3;

X = binornd(1,0.5,n,10000);

meanX= mean(X);

m=1/2;

s=1/2;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Bernoulli n=3')

subplot(2,2,2)

n = 10;

X = binornd(1,0.5,n,10000);

meanX= mean(X);

m=1/2;

s=1/2;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Bernoulli n=10')

subplot(2,2,3)

n = 30;

X = binornd(1,0.5,n,10000);

meanX= mean(X);

m=1/2;

s=1/2;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Bernoulli n=30')

subplot(2,2,4)

n = 100;

X = binornd(1,0.5,n,10000);

meanX= mean(X);

m=1/2;

s=1/2;

Z = sqrt(n)*(meanX-m)/s ;

hist(Z,-4:0.20:4)

title('Bernoulli n=100')