以下利用Matlab program來分別以Binomial RV及Bernoulli RV
%來試驗中央極限定理(Central Limit Theorem)
%Binomial RVs
%-------------MATLAB Script-------------------------------------
% file binomial_rv
n=input('Number of Bernoulli trials n=');
p=input('Parameter of Bernoulli RV p=');
m=input('Number of sample mean m=');
for k=1:m
i=0;
f=(1.0-p)^n;
q=f;
u=rand();
while f> binomial_rv
Number of Bernoulli trials n=6
Parameter of Bernoulli RV p=0.3
Number of sample mean m=10000
The mean is = 1.791700
>>
>> binomial_rv
Number of Bernoulli trials n=6
Parameter of Bernoulli RV p=0.3
Number of sample mean m=100000
The mean is = 1.801410
>>
The E[X]=np=1.8
As the number of samples approaches infinity, the sample mean approaches the E[X].
------------------------------------------------------
%以Bernoulli RV來測試CLT
%Bernoulli RVs
-------------MATLAB Script-------------------------------------
% file bernoulli_rv.m
n=input('Number of Bernoulli trials n=');
p=input('Parameter of Bernoulli RV p=');
B=rand(n,1)> bernoulli_rv
Number of Bernoulli trials n=10000
Parameter of Bernoulli RV p=0.4
The mean is = 0.388700
>>
>> bernoulli_rv
Number of Bernoulli trials n=100000
Parameter of Bernoulli RV p=0.4
The mean is = 0.399340
>>
The E[X]=p=0.4.
It is very obvious that as the trials approaches infinity, the sample mean will approach E[x].
- Oct 19 Thu 2006 05:23
Matlab的應用-機率篇4
close
全站熱搜
留言列表