Normally distributed Random numbers generator issue
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I've used the randn function (setting rng(1)) and plotted the histogram:
% ----------------
rng(1)
figure
hist(randn(500,1),50)
% ------------------------
the result I've got in Matlab 2020b was rather far from a normal distribution.
Increasing the amount of generated numbers helps a bit - but not enough.
Any ideas on how to get a more adequate, normally distributed, bumbers ?
0 commentaires
Réponses (4)
Veronica Taurino
le 24 Mar 2021
Modifié(e) : Veronica Taurino
le 24 Mar 2021
The following (but also yours, from my pov) seems quite normal to me, why is it not ''enough'' normal for you?
figure
number = 1000000
hist(randn(number,1),50)
0 commentaires
Jan
le 24 Mar 2021
Modifié(e) : Jan
le 24 Mar 2021
This is a perfect normal distribution of 500 values. With such a small set of data, a lot of noise is expected. Otherwise it would not be a random normal distribution.
So the only problem is, that you expect something else, which does not match the defition of normally distributed randomness.
So what do you need? Do you want a perfect normal distribution without randomness, e.g. by just shuffling the values?
0 commentaires
Stanislav Lifshitz
le 24 Mar 2021
5 commentaires
Jan
le 24 Mar 2021
@Stanislav Lifshitz: Again: randn(500,1) is a perfect random distribution already. If you want the shape of the values to be a a perfect bell wave, the values are not random anymore.
Your question is similar to asking for throwing a set of 6 dice and having the need to get each value 1 time. Of course this works, but then it is not random anymore.
Veronica Taurino
le 25 Mar 2021
I totally agree with Jan. You have been confused by the shape of the data, perhaps? But for definition, it is a normal distribution (as Walter has pointed out, mean 0 and std 1). If you just want to change the shape, it is not randon anymore.
Jeff Miller
le 24 Mar 2021
As the other posters have said, you aren't necessarily going to get an exactly normal-looking distribution if you generate the numbers randomly. But you can nonrandomly generate an exactly normal-looking set of numbers like this:
nPoints = 500;
cdfvals = (0.5:1:nPoints) / nPoints;
evenRand = norminv(cdfvals);
figure;
hist(evenRand,50);
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!