개발자 뺚
[Cody] Problem 44951. Verify Law of Large Numbers 본문
If a large number of fair N-sided dice are rolled, the average of the simulated rolls is likely to be close to the mean of 1,2,...N i.e. the expected value of one die. For example, the expected value of a 6-sided die is 3.5.
Given N, simulate 1e8 N-sided dice rolls by creating a vector of 1e8 uniformly distributed random integers. Return the difference between the mean of this vector and the mean of integers from 1 to N.
function dice_diff = loln(N)
rollin = randi(N, 100000000, 1);
mean1 = mean(rollin);
mean2 = (1 + N) / 2;
dice_diff = mean2 - mean1;
end
'Solution > MATLAB' 카테고리의 다른 글
[Cody] Problem 44946. Solve a System of Linear Equations (0) | 2023.08.23 |
---|---|
[Cody]Problem 44947. Find the Oldest Person in a Room (0) | 2023.08.23 |
[Cody] Problem 44944. Convert from Fahrenheit to Celsius (0) | 2023.08.23 |
[Cody] Problem 128. Sorted highest to lowest? (0) | 2023.08.22 |
[Cody] Problem 44943. Calculate Amount of Cake Frosting (0) | 2023.08.22 |