Problem 44951. Verify Law of Large Numbers

조회 수: 3 (최근 30일)
Tavish Pattanayak
Tavish Pattanayak 2020년 5월 7일
댓글: Tavish Pattanayak 2020년 5월 7일
function dice_diff = loln(N)
add = 0; mean = 0; mean1 = 0;add1=0;
for c=1:1*exp(8)
num = randi(N);
add = add + num;
end
mean = add/(1*exp(8))
for c=1:N
add1=add1+c;
end
mean1=add1/N
dice_diff = mean-mean1
end
The code works fine but the result is not as expected. Could anyone tell the reason?

채택된 답변

Walter Roberson
Walter Roberson 2020년 5월 7일
If you want 2980 iterations then why not use 2980 instead of exp(8) ?
mean = add/(1*exp(8))
Incorrect. You do an integer number of iterations, 2980, but you divide by exp(8) which is about 2980.96 so you get the wrong mean() value. You sould be dividing by the number of iterations you do. Or you should use mean()
  댓글 수: 5
Walter Roberson
Walter Roberson 2020년 5월 7일
The question requires that you simulate 1e8 rolls, not 1*exp(8) . 1e8 is 1*10^8
Tavish Pattanayak
Tavish Pattanayak 2020년 5월 7일
Yes it worked. Thank you so much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by