matlab中的中心极限定理

Ara*_*hdn 0 matlab

我试图通过比较三个RV和正态分布之和的直方图来在matlab中证明CLT.

这是我的代码:

clc;clear;
len = 50000;

%y0 : Exponential Distribution
lambda = 3;
y0=-log(rand(1,len))./lambda;


%y1 :  Rayleigh Distribution
mu = 0;
sig = 2;
var1 = mu + sig*randn(1,len);
var2 = mu + sig*randn(1,len);
t1 = var1 .^ 2;
t2 = var2 .^ 2;
y1 = sqrt(t1+t2);


% %y2: Normal Distribution
y2 =  randn(1,len);


%y3 : What result excpected to be:
mean0 = (sum(y0)+ sum(y1)+ sum(y2)) / (len * 3);%how do I calculate this?
var0 =  1;%how do I calculate this?
y3 = mean0 + var0*randn(1,len);
delta = 0.1;
x3 = min(y3):delta:max(y3);
figure('Name','Normal Distribution');
hist(y3,x3);


%Central Limit Theorem:
%what result is:
res = y0+y1+y2;
xn = min(res):delta:max(res);
figure('Name','Final Result');
hist(res,xn);
Run Code Online (Sandbox Code Playgroud)

我有两个主要问题.

  1. 如何计算y3的均值和方差(结果应该是什么)

  2. 我的代码是否正确?

Dan*_*010 5

因为y0,y1并且y2是行向量,你必须做的:

mean0 = mean([y0 y1 y2]);
variance0 = var([y0 y1 y2]);
Run Code Online (Sandbox Code Playgroud)

在创建时,[y0 y1 y2]您正在创建一个包含单个向量中所有先前样本的大向量(就好像它们是一个单一分布的样本一样).

现在只需将其插入您想要的功能(均值和方差),如上所示.


关于统计部分:我认为你有些不对劲.中心极限定理适用于根据相同分布分布的变量之和.它确实可以是任何分布D,但所有变量必须具有相同的分布D.您试图对不同的分布求和.

该定理说:

CLT

我编写了一个根据指数分布分布的变量的例子.运行它,你会发现当你增加N时,得到的分布往往是预期的正态分布.对于N = 1,你有指数分布(与正态分布非常不同),但是对于N = 100,你已经有一个非常接近预期正态分布的分布(你可以看到均值和方差基本相同)现在).

N = 1的指数的CLT N = 1的指数之和

N = 3的指数的CLT N = 3的指数之和

N = 10的指数的CLT N = 10的指数之和

N = 100的指数的CLT N = 100的指数之和

预期的正态分布(CLT的收敛分布) 预期正常

clc;clear;
len = 50000;
lambda = 3;

%yA : Exponential Distribution A
yA=-log(rand(1,len))./lambda;

%yB : Exponential Distribution B
yB=-log(rand(1,len))./lambda;

%yC : Exponential Distribution C
yC=-log(rand(1,len))./lambda;

%yD : Exponential Distribution D
yD=-log(rand(1,len))./lambda;

%yE : Exponential Distribution E
yE=-log(rand(1,len))./lambda;

%yF : Exponential Distribution F
yF=-log(rand(1,len))./lambda;

%yG : Exponential Distribution G
yG=-log(rand(1,len))./lambda;

%yH : Exponential Distribution H
yH=-log(rand(1,len))./lambda;

%yI : Exponential Distribution I
yI=-log(rand(1,len))./lambda;

%yJ : Exponential Distribution J
yJ=-log(rand(1,len))./lambda;


%y1 : What result you expect it to be (centred Gaussian with same variation as exponential):
mean0 = 0;
var0 =  var(yA);
y1 = mean0 + sqrt(var0)*randn(1,len);
delta = 0.01;
x1 = min(y1):delta:max(y1);
figure('Name','Normal Distribution (Expected)');
hist(y1,x1);


%Central Limit Theorem:
%what result is:
res1 = (((yA)/1) - mean(yA))*sqrt(1);
res2 = (((yA+yB)/2) - mean(yA))*sqrt(2);
res3 = (((yA+yB+yC)/3) - mean(yA))*sqrt(3);
res4 = (((yA+yB+yC+yD)/4) - mean(yA))*sqrt(4);
res5 = (((yA+yB+yC+yD+yE)/5) - mean(yA))*sqrt(5);
res10 = (((yA+yB+yC+yD+yE+yF+yG+yH+yI+yJ)/10) - mean(yA))*sqrt(10);
delta = 0.01;
xn = min(res1):delta:max(res1);
figure('Name','Final Result for N=1');
hi  st(res1,xn);
xn = min(res2):delta:max(res2);
figure('Name','Final Result for N=2');
hist(res2,xn);
xn = min(res3):delta:max(res3);
figure('Name','Final Result for N=3');
hist(res3,xn);
xn = min(res4):delta:max(res4);
figure('Name','Final Result for N=4');
hist(res4,xn);
xn = min(res5):delta:max(res5);
figure('Name','Final Result for N=5');
hist(res5,xn);
xn = min(res10):delta:max(res10);
figure('Name','Final Result for N=10');
hist(res10,xn);

%for N = 100
y100=-log(rand(100,len))./lambda;
res100 = ((sum(y100)/100) - mean(yA))*sqrt(100);
xn = min(res100):delta:max(res100);
figure('Name','Final Result for N=100');
hist(res100,xn);
Run Code Online (Sandbox Code Playgroud)

  • 完全同意你的看法.目的不是要展示任何东西.使用数值编程进行数学演示是没有意义的,但是matlab非常适合于可视化结果并获得事物的直觉(例如CLT). (2认同)