Using normrnd for generating natural values (without decimal values)
古いコメントを表示
I would like to generate data with average of 27 and standard deviation of 1.41, but I would like the data have no decimal values, ex to be like this 12, 24, 27 ... . Could you please help me how I can do so?
4 件のコメント
Walter Roberson
2022 年 6 月 14 日
Do you care about the distribution of the values? You cannot get normally distributed values that way.
Sahar khalili
2022 年 6 月 14 日
Walter Roberson
2022 年 6 月 14 日
You cannot use the fact that the sum of identically distributed uniform distribution approximates normal. You can generate 54 binary values and sum them. That will have a mean of 27, but the std will be 3.67.
Sahar khalili
2022 年 6 月 14 日
回答 (1 件)
How about this data set {25, 26, 27, 27, 28, 29}?
A = [25, 26, 27, 27, 28, 29]
M = mean(A)
S = std(A)
5 件のコメント
Walter Roberson
2022 年 6 月 14 日
I calculate that this or a permutation of this is the only set that works.
Wow! I actually don't know the exact steps to find the data set. I just based on the desired mean 27 and used heuristic trial-and-error approach to gradually distribute 6 integers away from the mean, and found this data set. Thanks @Walter Roberson for the confirmation.
Walter Roberson
2022 年 6 月 14 日
編集済み: Walter Roberson
2022 年 6 月 15 日
std is sqrt(2). std() involves sqrt(N-1). N=6 so that is division by sqrt(5). In order for that to give sqrt(2) it follows that the numerator must be sqrt(10) and so the sum of exactly 6 squares of values minus mean must be 10.
Can any of the differences from the mean be 4 or more? No that would give a term of 4*4 which exceeds 10.
Can any of the differences be 3? 3*3 = 9 which is less than 10, but that requires that the total sum of squares for the other 5 terms is 1. But you cannot balance a difference of 3 with a single difference of 1 to get the right mean.
Can any of the differences be 2? Yes, make one be -2 and another be +2 and one be -1 and another be +1 and you get a mean balance and sum of squares 2*2 + 2*2 + 1*1 + 1*1 = 10, which works out.
Can exactly one be difference of 2? That contributes 4 to the sum of squares, leaving 6 to be distributed among the remaining 5 values. But under hypothesis none are 2 (squared) and so you have a pigeon-hole problem of distribution of 6 in 5 values that are 0 or 1, and that cannot fit.
Can all the differences be 0 or 1? No, sum of squares for 6 values like that cannot reach 10.
So we conclude that Sam's arrangement (possibly permuted) is the only solution.
[x1, x2, x3, x4, x5, x6] = ndgrid(27-4:27+4);
meanmask = (x1 + x2 + x3 + x4 + x5 + x6)/6 == 27;
sx1 = x1(meanmask); sx2 = x2(meanmask); sx3 = x3(meanmask);
sx4 = x4(meanmask); sx5 = x5(meanmask); sx6 = x6(meanmask);
sx = [sx1, sx2, sx3, sx4, sx5, sx6];
st = std(sx, [], 2);
inrange = st >= 1.405 & st < 1.415;
values_that_work = sx(inrange,:);
whos values_that_work
unique(sort(values_that_work, 2), 'rows')
360 matches... but to within permutations they are all the same.
Notice that, as predicted by my analysis, no deviations of 4 or 3 match, only -2, -1, 0, 0, +1, +2
Sam Chak
2022 年 6 月 15 日
Many thanks to @Walter Roberson for explaning and showing the Permutation search procedure. The permutation-based method is effective.
カテゴリ
ヘルプ センター および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!