Consider a loop of string with unit length. Take n cuts independently and randomly along the string, what is the expected length of the smallest and the largest piece?
1 回表示 (過去 30 日間)
古いコメントを表示
This is what I did.
The probability is (1+(1-n)x)^n
So, expected value of x is it integral for x varies from 0 to 1/n which evaluates to 1/n^2
If this is right how should I write the code?
7 件のコメント
回答 (1 件)
Are Mjaavatten
2016 年 2 月 8 日
Your question is not very clear. The code below is an answer to: How can I code a test of this result?
N=100000; % Number of samples
n=8; % Number of cuts
d = zeros(N,n); % Allocate space for results
for i = 1:N
a = sort(rand(1,n)); % Draw random cut poins and distribute them along the string
b = [a(end)-1,a]; % Join ends
d(i,:) = sort(diff(b)); % Sort the pieces by length
end
mean_lengths = mean(d); % mean_lengths(i) is the mean length of the i'th shortest piece
disp(mean_lengths);
2 件のコメント
Walter Roberson
2016 年 2 月 9 日
編集済み: Walter Roberson
2016 年 2 月 9 日
mean_lengths(end) is the mean of the longest.
The shortest out of all of the runs is min(d(:)) and the longest out of all of the runs is max(d(:)) (those might occur on different runs.)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!