how I write independent random numbers from a normal distribution, for example between (0,1)?

19 ビュー (過去 30 日間)
How I write independent random numbers from a normal distribution, for example between (0,1)? And how I can put this numbers in a matrix. Thank you.

採用された回答

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 8 日
編集済み: Massimo Zanetti 2016 年 10 月 8 日
There is specific matlab function https://it.mathworks.com/help/matlab/ref/randn.html
For example, create 4x5 matrix of normal distributed random numbers:
A=randn(4,5)
Notice that a Gaussian distributed random variable takes values between (-inf,inf), there is no Gaussian variable in (0,1).
randn assumes the distribution is Gaussian with mean=0 and variance=1. If you want to customize it, you can do as follows:
MU=2; %mean
SIG=5; %variance
A= SIG*randn(4,5)+MU;
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 10 月 8 日
nu(k) = randn();
If you want to create a vector of length N then
nu = randn(1,N);
The 1, N is the size, not the mean and standard deviation. For other means or standard deviations use the SIG MU transformation that Massimo Zanetti shows.
mike papas
mike papas 2016 年 10 月 8 日
編集済み: mike papas 2016 年 10 月 8 日
Thank you very much! It was really helpful.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 10 月 8 日
If you restrict values drawn from a Normal distribution to any particular range (such as 0 to 1), then the values will no longer be normally distributed. It is impossible for anything to be Normally distributed unless it has infinite tails in both direction. MATLAB's randn() can produce values from -realmax to +realmax which is not truly infinite but the probability lost is tiny. Restricting to (0, 1) would be a significant probability loss and a major distortion of the normal distribution.
If you need non-uniform random numbers that must be within a particular finite range, then you should be considering using the Beta distribution; https://www.mathworks.com/help/stats/beta-distribution-1.html and http://www.mathworks.com/help/stats/betapdf.html

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by