%(1)
%使用Matlab來產生Bernoulli Random Variable序列之和的樣本空間
%----------------------MATLAB Script-------------------------------------
% poisson_rvs
% Sequence of Poisson Random variables
n=input('Number of RVs n=');
m=input('Number of samples of the sum m=');
u=input('Parameter of Bernoulli RV u=');

% claculate the sum of n Poisson Rvs
for j=1:m
for k=1:n
i=0;
f=exp(-u);
p=f;
u=rand();
while f> poisson_rvs
Number of RVs n=100
Number of samples of the sum m=10
Parameter of Poisson RV u=0.3

Some samples of the sum of these n RVs
i S(i)
1 63
2 46
3 55
4 37
5 60
6 51
7 47
8 48
9 47
10 34


%(2)
%Use two ways to approach the pdf of the sum of the n Poisson RVs. One is
%directly counting the relative frequencies of the sun of all possible
%numbers.
%-----------------------------MATLAB Script---------------------------------
n=input('Number of RVs n=');
m=input('Number of samples of the sum m=');
u=input('Parameter of Poisson RV p=');

for j=1:m
for k=1:n
i=0;
p=exp(-u);
f=p;
u=rand();
while f> pdf_of_the_sum_poisson
Number of RVs n=100
Number of samples of the sum m=10000
Parameter of Poisson RV p=0.3
>>
----------------------------------------------------------------------------
圖形結果如下:


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Irwinlin 的頭像
    Irwinlin

    變化是生活的調味料

    Irwinlin 發表在 痞客邦 留言(0) 人氣()