当前位置:网站首页>matlab中不同随机数的生成
matlab中不同随机数的生成
2022-06-10 05:28:00 【stronger_er】
随机数生成方法:
第一种方法是用 random 语句,其一般形式为
y = random('分布的英文名',A1,A2,A3,m,n),
表示生成 m 行 n 列的 m × n 个参数为 ( A1 , A2 , A3 ) 的该分布的随机数。例如:
(1) R = random('Normal',0,1,2,4): 生成期望为 0,标准差为 1 的(2 行 4 列)2× 4 个正态随机数
(2) R = random('Poisson',1:6,1,6): 依次生成参数为 1 到 6 的(1 行 6 列)6 个 Poisson 随机数
第二种方法是针对特殊的分布的语句:
一. 几何分布随机数 (下面的 P,m 都可以是矩阵)
R = geornd(P) (生成参数为 P 的几何随机数)
R = geornd(P,m) (生成参数为 P 的 × m 个几何随机数)
1
R = geornd(P,m,n) (生成参数为 P 的 m 行 n 列的 m × n 个几何随机数)
例如
(1) R = geornd(1./ 2.^(1:6)) ( 生成参数依次为 1/2,1/2^2,到 1/2^6 的 6 个几何随机数)
(2) R = geornd(0.01,[1 5]) (生成参数为 0.01 的(1行5列)5 个几何随机数).
二.Beta 分布随机数
R = betarnd(A,B) (生成参数为 A,B 的 Beta 随机数)
R = betarnd(A,B,m) (生成 × m 个数为 A,B 的 Beta 随机数)
1
R = betarnd(A,B,m,n) (生成 m 行 n 列的 m × n 个数为 A,B 的 Beta 随机数).
三.正态随机数
R = normrnd(MU,SIGMA) (生成均值为 MU,标准差为 SIGMA 的正态随机数)
R = normrnd(MU,SIGMA,m) (生成 1× m 个正态随机数)
R = normrnd(MU,SIGMA,m,n) (生成 m 行 n 列的 m × n 个正态随机数)
例如
(1) R = normrnd(0,1,[1 5]) 生成 5 个正态(0,1) 随机数
(2) R = normrnd([1 2 3;4 5 6],0.1,2,3) 生成期望依次为[1,2,3;4,5,6], 方差为 0.1 的 2× 3 个正态随机数.
四.二项随机数:类似地有
R = binornd(N,P) R = binornd(N,P,m) R = binornd(N,p,m,n)
例如
n = 10:10:60; r1 = binornd(n,1./n) 或 r2 = binornd(n,1./n,[1 6]) (都生成参数分别为
1 1 ), L, ( 60, ) 的6个二项随机数.
(10,
10 60
五.自由度为 V 的 χ 2 随机数:
R = chi2rnd(V) R = chi2rnd(V R = chi2rnd(V
,m) ,m,n)
六.期望为 MU 的指数随机数(即 Exp 随机数):
1
MU
R = exprnd(MU) R = exprnd(MU,m) R = exprnd(MU,m,n)
七.自由度为 V1, V2 的 F 分布随机数:
R = frnd(V1,V2) R = frnd(V1, V2,m) R = frnd(V1,V2,m,n)
八. Γ ( A, λ ) 随机数:
R = gamrnd(A,lambda) R = gamrnd(A,lambda,m) R = gamrnd(A,lambda,m,n)
九.超几何分布随机数:
R = hygernd(N,K,M) R = hygernd(N,K,M,m) R = hygernd(N,K,M,m,n)
十.对数正态分布随机数
R = lognrnd(MU,SIGMA) R = lognrnd(MU,SIGMA,m) R = lognrnd(MU,SIGMA,m,n)
十一.负二项随机数:
R = nbinrnd(r,p) R = nbinrnd(r,p,m) R = nbinrnd(r,p,m,n)
十二.Poisson 随机数:
R = poissrnd(lambda) R = poissrnd(lambda,m) R = poissrnd(lambda,m,n)
例如,以下 3 种表达有相同的含义:lambda = 2; R = poissrnd(lambda,1,10)
(或 R = poissrnd(lambda,[1 10]) 或 R = poissrnd(lambda(ones(1,10)))
十三.Rayleigh 随机数:
R = raylrnd(B) R = raylrnd(B,m) R = raylrnd(B,m,n)
十四.V 个自由度的 t 分布的随机数:
R = trnd(V) R = trnd(V,m) R = trnd(V,m,n)
42
十五.离散的均匀随机数:
R = unidrnd(N) R = unidrnd(N,m) R = unidrnd(N,m,n)
十六.[A,B] 上均匀随机数
R = unifrnd(A,B) R = unifrnd(A,B,m) R = unifrnd(A,B,m,n)
例如 unifrnd(0,1:6)与 unifrnd(0,1:6,[1 6]) 都依次生成[0,1] 到[0,6]的6个均匀随机数.:
十七.Weibull 随机数
R = weibrnd(A,B) R = weibrnd(A,B,m) R = weibrnd(A,B,m,n)
边栏推荐
猜你喜欢

The world's first financial chart database test benchmark project was approved, and ant group opened patent Co Construction

AI summit ICLR 2022 | wpipe ant group large scale DNN training pipeline parallel technology
![[general database tools] Shanghai daoning provides developers, analysts and database administrators with a tool for all databases and operating systems - dbvisualizer](/img/ce/4d531860a00381f26e09fbf5bc5916.png)
[general database tools] Shanghai daoning provides developers, analysts and database administrators with a tool for all databases and operating systems - dbvisualizer

每日一题—LeetCode497—非重叠矩形中的随机点-前缀和-二分

生成boot_para.img
![[innovative document technology solution] Shanghai daoning provides you with a product - litera, which covers the entire document drafting life cycle, to help users create higher quality documents](/img/7e/a0d1b75a57f9e4e94ccdac5244d30c.png)
[innovative document technology solution] Shanghai daoning provides you with a product - litera, which covers the entire document drafting life cycle, to help users create higher quality documents

蚂蚁集团三项技术方案入选“2021年信息技术应用创新典型解决方案”

《模型輕量化-剪枝蒸餾量化系列》YOLOv5無損剪枝(附源碼)

Odometer. JS digital scrolling plug-in

Power mathematics of leetcode326-3
随机推荐
MTK基于GAT工具和SpOffineDebugSuite工具 dump 抓取和解析
Cubase pro 12
蚂蚁集团加入低碳专利承诺,向全球无偿开放专利,促进节能减排
[Linux < day20 >] - An Introduction to database and container technology
Hevc HM learning 01
[001] analysis of long and difficult sentences one day
MTK 平台sensor arch 介绍-kernel
Recursive function Hanoi Tower
Interview question 08.01 Three step problem
Ant group's all-in-one privacy computing machine has obtained double certification, and 83 indicators meet the requirements
Study notes for typescript
Interview question 05.06 Integer conversion
[general database tools] Shanghai daoning provides developers, analysts and database administrators with a tool for all databases and operating systems - dbvisualizer
Inherit extensions
[simplify] [exclude]
Clear table selection
一文看懂蚂蚁BizStack 云原生开发和治理平台
Interview question 05.08 draw a straight line
And new products? Toyota GR series may expand its product line
AI顶会ICLR 2022 | WPipe 蚂蚁集团大规模 DNN 训练的流水线并行技术