How to find the average of monte carlo simulation

5 ビュー (過去 30 日間)
Eric Chua
Eric Chua 2020 年 5 月 12 日
コメント済み: Eric Chua 2020 年 5 月 13 日
Hi, I'm generating a poisson distribution random variable for 1000 times, here is the code i've wrote
N = 1000;
lambda = 60.21;
for i = 1:N
r = poissrnd(lambda)
end
I will get the random variable 1000 times, what code should i write to make these 1000 random variable too add up and find the average? Please help me thanks.

採用された回答

James Tursa
James Tursa 2020 年 5 月 12 日
You could save the r's in a vector. E.g.,
r(i) = poissrnd(lambda);
Or you could generate all of the r's at once without the loop
r = poissrnd(lambda,N,1);
and then use the mean( ) function.
  2 件のコメント
Eric Chua
Eric Chua 2020 年 5 月 13 日
thanks, could you show me how to use the mean() function? Im quite new to matlab
Eric Chua
Eric Chua 2020 年 5 月 13 日
I think i got it already thanks!

サインインしてコメントする。

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by