1. 程式人生 > >【matlab】Matlab中產生正態分佈隨機數的函式normrnd

【matlab】Matlab中產生正態分佈隨機數的函式normrnd

Date: 2018.8.5

功能:生成服從正態分佈的隨機數
語法:
R=normrnd(MU,SIGMA)
R=normrnd(MU,SIGMA,m)
R=normrnd(MU,SIGMA,m,n)
說 明:
R=normrnd(MU,SIGMA):生成服從正態分佈(MU引數代表均值,DELTA引數代表標準差)的隨機數。輸入的向量或矩陣MU和SIGMA必須形式相同,輸出R也和它們形式相同。標量輸入將被擴充套件成和其它輸入具有 相同維數的矩陣。

R=norrmrnd(MU,SIGMA,m):生成服從正態分佈(MU引數代表均值,DELTA引數代表標準差)的 隨機數矩陣,矩陣的形式由m定義。m是一個1×2向量,其中的兩個元素分別代表返回值R中行與列的維數。

R=normrnd(MU,SIGMA,m,n): 生成m×n形式的正態分佈的隨機數矩陣。

>> help normrnd
NORMRND Random arrays from the normal distribution.
R = NORMRND(MU,SIGMA) returns an array of random numbers chosen from a
normal distribution with mean MU and standard deviation SIGMA. The size
of R is the common size of MU and SIGMA if both are arrays. If either
parameter is a scalar, the size of R is the size of the other
parameter.

R = NORMRND(MU,SIGMA,M,N,…) or R = NORMRND(MU,SIGMA,[M,N,…])
returns an M-by-N-by-… array.

例:生成正態分佈隨機數。

>> a=normrnd(0,1)

  a =

     -1.4814

  >> a=normrnd(0,1,1,6)

  a =

      1.1287   -0.2900    1.2616    0.4754    1.1741    0.1269

  >> a=normrnd(0,1,[1 6])

  a =

      0.1555
0.8186 -0.2926 -0.5408 -0.3086 -1.0966 >> a=normrnd(10,2,2,3) a = 13.6280 13.6090 11.0531 10.6240 8.5538 9.4795

注:正態分佈只需要2個引數。
randn() 是標準正態分佈;
normrnd()是自己可以指定均數和標準差的正太分佈。

THE END!