normal distribution range

2 vues (au cours des 30 derniers jours)
M ST
M ST le 27 Jan 2011
Commenté : Steven Lord le 16 Jan 2019
Hello, I would like to use 'randn' create random numbers normally distributed. I noticed that it creates positive and negative numbers with mean 0.
How do I create only positive numbers, say within a range 1 to 100 with a mean of around 50 (std dev can be 2).
I noticed that we can specify the mean and std dev, but not the range. How can I specify the range too.
Thanks.
  2 commentaires
Andrew Newell
Andrew Newell le 27 Jan 2011
Why don't you want negative numbers? Strictly speaking, a normal distribution with bounds on it is not a normal distribution. However, in the example you provided, a negative number should be extremely rare.
M ST
M ST le 27 Jan 2011
This is for a problem that that has X number of items numbered from 1-X. We choose the numbers randomly (normally distributed). Since the items are numbered positive, I wanted my range to be from 1-X.
Thanks.

Connectez-vous pour commenter.

Réponses (3)

the cyclist
the cyclist le 27 Jan 2011
I encourage you to be very careful about your terminology. It is contradictory to say that your variable has a range from 1-100, and is normally distributed (because a truly normal distribution has infinite tails).
A distribution that is truly finite in extent, but can be made to look "normal-ish", is the beta distribution. For example, take a look at this:
>> hist(100*betarnd(5,5,10000,1),50)
Finally, it is not really clear to me whether this is a discrete or a continuous distribution. You mention "number of items", which suggests a discrete count. But the distributions being suggested are continuous. Is it OK to have 64.7 items?

Bruno Luong
Bruno Luong le 27 Jan 2011
Please take a look at my FEX submission.
% Generate 1000000 numbers with mean ~ 50, range = [1 100], std = 20
X = 50+TruncatedGaussian(20,[1 100]-50,[1 1e6]);
>> min(X)
ans =
1.0008
>> max(X)
ans =
99.9996
>> mean(X)
ans =
50.0717
>> std(X)
ans =
19.9901
>> hist(X)
% Bruno
  4 commentaires
Burak TASCIOGULLARI
Burak TASCIOGULLARI le 16 Jan 2019
Hi Bruno, I cannot use that formula because matlab does not define it. I use Matlab R2017a. Is it a problem of Matlab version
Steven Lord
Steven Lord le 16 Jan 2019
It's an add-on from the File Exchange, not a function in a MathWorks product.
You can follow the link Bruno posted to download it then install it. Alternately you can click on the "Add-Ons" button in the Toolstrip, search for "truncated gaussian", open the submission from Bruno, and add it to your installation using the Add button. In this second case, MATLAB will default to putting it on your MATLAB path.

Connectez-vous pour commenter.


Oleg Komarov
Oleg Komarov le 27 Jan 2011

Directly from the example in the documentation of randn:

r = 50 + 2.*randn(10000,1);
hist(r,100)

Oleg

  3 commentaires
Bruno Luong
Bruno Luong le 27 Jan 2011
[ I noticed this one ranges from 42-56. ]
Wrong. range of Gaussian is always [-Inf,Inf].
Most of the time you can believe in your eye. But sometime you won't.
Bruno
Oleg Komarov
Oleg Komarov le 27 Jan 2011
I just suggest:
1) Use Bruno's function
2) Play with the example I posted, augmenting the number of draws and changing stdev etc...

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by