教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 高等教育 >

Matlab中的随机函数 (2)

来源:网络收集 时间:2026-05-22
导读: RNG The sequence of numbers produced by randi is determined by the settings of the uniform random number generator that underlies RAND, RANDN, and randi. randi uses one uniform random value to create each integer random value. Control that

RNG

The sequence of numbers produced by randi is determined by the settings of the uniform random number generator that underlies RAND, RANDN, and randi. randi uses one uniform random value to create each integer random value. Control that shared random number generator using RNG.

randi

Pseudorandom integers from a uniform discrete distribution.

1) randi(IMAX) returns a scalar.

2) R = randi(IMAX,N) returns an N-by-N matrix containing pseudorandom integer values drawn from the discrete uniform distribution on 1:IMAX.

3) randi(IMAX,M,N,P,...) or randi(IMAX,[M,N,P,...]) returns an M-by-N-by-P-by-... array.

4) R = randi([IMIN,IMAX],...) returns an array containing integer values drawn from the discrete uniform distribution on IMIN:IMAX.

5) randi(..., CLASSNAME) returns an array of integer values of class CLASSNAME.

设置随机函数的格式Example 1: Save the settings for the random number generator used by RAND, randi, and RANDN, generate 5 values from randi, restore the settings, and repeat those values.

s = rng

i1 = randi(10,1,5)

rng(s);

i2 = randi(10,1,5) % i2 contains exactly the same values as i1

让每次执行随机结果不一Example 2: Reinitialize the random number generator used by RAND,randi, and RANDN with a seed based on the current time. randi will return different values each time you do this. NOTE: It is usually not necessary to do this more than once per MATLAB session.

rng('shuffle');

randi(10,1,5)

To get unique integer values, sometimes referred to as sampling without replacement,then coming into being.

RANDPERM.

Diag

对角矩阵 eg、 a = [1,2,3] 则: diag(a) = (1 0 0 ;0 2 0;0 0 6);

Triu

上三角矩阵 eg、 a2 = [1,2,3;4,5,6,;7,8,9] 则: diag(a2) = (1 2 3 ;0 5 6;0 0 9); Tril

下三角矩阵 eg、 a3 = a2 则: diag(a) = (1 0 0 ;4 5 0;7 8 9);

Zeros

全零矩阵

Ones

全一矩阵

Eye

单位矩阵

Matlab中的随机函数 (2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1714026.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)