关键词不能为空

当前您在: 主页 > 英语 >

(完整版)Matlab各种随机数设置

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-28 08:14
tags:

-

2021年2月28日发(作者:bootstrapper)


Matlab


各种随机数设置



randn


(伪随机正态分布数)



Normally distributed pseudorandom numbers



Syntax



r = randn(n)



randn(m,n)



randn([m,n])



randn(m,n,p,...)



randn([m,n,p,...])



randn(size(A))



r = randn(..., 'double')



r = randn(..., 'single')




Description



r = randn(n) returns an n


-


by


-


n matrix containing pseudorandom values drawn from the standard


normal


distribution.


randn(m,n)


or


randn([m,n])


returns


an


m

< p>
-


by


-


n


matrix.


randn(m,n,p,...)


or


randn([m,n,p,...])


returns


an


m

< p>
-


by


-


n


-


by


-


p


-


by


-


...


array.


randn


returns


a


scalar.


randn(size(A))


returns an array the same size as A.



r = randn(..., 'double') or r = randn(..., 'single') returns an array of normal values of the specified


class.




Note




The size inputs m, n, p, ... should be nonnegative integers. Negative integers are treated


as 0.



The


sequence


of


numbers


produced


by


randn


is


determined


by


the


internal


state


of


the


uniform pseudorandom number generator that underlies rand, randi, and randn. randn uses one


or


more


uniform


values


from


that


default


stream


to


generate


each


normal


value.


Control


the


default stream using its properties and methods.




Note





In


versions


of


MATLAB


prior


to


7.7


(R2008b),


you


controlled


the


internal


state


of


the


random


number


stream


used


by


randn


by


calling


randn


directly


with


the


'seed'


or


'state'


keywords.




Examples



Generate values from a normal distribution with mean 1 and standard deviation 2.



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



Generate


values


from


a


bivariate


normal


distribution


with


specified


mean


vector


and


covariance matrix.



mu = [1 2];



Sigma = [1 .5; .5 2]; R = chol(Sigma);



z = repmat(mu,100,1) + randn(100,2)*R;



Replace the default stream at MATLAB startup, using a stream whose seed is based on clock,


so that randn will return different values in different MATLAB sessions. It is usually not desirable


to do this more than once per MATLAB session.



aultStream ...








(RandStream('mt 19937ar','seed',sum(100*clock)));



randn(1,5)



Save the current state of the default stream, generate 5 values, restore the state, and repeat


the sequence.




defaultStream = aultStream;



savedState =



z1 = randn(1,5)



= savedState;



z2 = randn(1,5) % contains exactly the same values as z1




Normrnd


(随机正态分布数)



Normal random numbers




Syntax



R = normrnd(mu,sigma)



R = normrnd(mu,sigma,m,n,...)



R = normrnd(mu,sigma,[m,n,...])




Description



R


=


normrnd(mu,sigma)


generates


random


numbers


from


the


normal


distribution


with


mean


parameter mu and standard deviation parameter sigma. mu and sigma can be vectors, matrices,


or multidimensional arrays that have the same size, which is also the size of R. A scalar input for


mu or sigma is expanded to a constant array with the same dimensions as the other input.



R


=


normrnd(mu,sigma,m,n,...)


or


R


=


normrnd(mu,sigma,[m,n,...])


generates


an


m


-


by


-


n


-


by


-


...


array. The mu, sigma parameters can each be scalars or arrays of the same size as R.




Examples



n1 = normrnd(1:6,1./(1:6))



n1 =





2.1650



2.3134



3.0250



4.0879



4.8607



6.2827




n2 = normrnd(0,1,[1 5])



n2 =





0.0591



1.7971



0.2641



0.8717



-


1.4462




n3 = normrnd([1 2 3;4 5 6],0.1,2,3)



n3 =





0.9299



1.9361



2.9640



4.1246



5.0577



5.9864




randperm (RandStream)


(区域内的所有整数的随机分布)



Random permutation



randperm(s,n)




Description



randperm(s,n)


generates


a


random


permutation


of


the


integers


from


1


to


n.


For


example,


randperm(s,6) might be [2 4 5 6 1 3]. randperm(s,n) uses random values drawn from the random


number stream s.




betarnd


(贝塔分布)



贝塔分布是一个作为伯 努利分布和二项式分布的共轭先验分布的密度函数





Syntax



R = betarnd(A,B)



R = betarnd(A,B,m,n,...)



R = betarnd(A,B,[m,n,...])




Description



R


=


betarnd(A,B)


generates


random


numbers


from


the


beta


distribution


with


parameters


specified by A and B. A and B can be vectors, matrices, or multidimensional arrays that have the


same size, which is also the size of R. A scalar input for A or B is expanded to a constant array


with the same dimensions as the other input.




R = betarnd(A,B,m,n,...) or R = betarnd(A,B,[m,n,...]) generates an m

-


by


-


n


-


by


-


... array containing


random


numbers


from


the


beta


distribution


with


parameters


A


and


B.


A


and


B


can


each


be


scalars or arrays of the same size as R.




Examples



a = [1 1;2 2];



b = [1 2;1 2];



r = betarnd(a,b)



r =





0.6987



0.6139





0.9102



0.8067




r = betarnd(10,10,[1 5])



r =





0.5974



0.4777



0.5538



0.5465



0.6327




r = betarnd(4,2,2,3)



r =





0.3943



0.6101



0.5768



0.5990



0.2760



0.5474




Binornd


(二项式分布)



二项分布(


binomial distribution


)就是对这类只具有两种互斥结果的离散型随机事件的规


律性进行描 述的一种概率分布。



Syntax



R = binornd(N,P)



R = binornd(N,P


,m,n,...)



R = binornd(N,P


,[m,n,...])




Description



R = binornd(N,P) generates random numbers from the binomial distribution with parameters


specified by the number of trials, N, and probability of success for each trial, P


. N and P can be


vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R.


A scalar input for N or P is expanded to a constant array with the same dimensions as the other


input.




R = binornd(N,P


,m,n,...) or R = binornd(N,P


,[m,n,...]) generates an m


-


by


-


n


-


by


-


.. . array containing


random numbers from the binomial distribution with parameters N and P


. N and P can each be


scalars or arrays of the same size as R.




Algorithm



The binornd function uses the direct method using the definition of the binomial distribution


as a sum of Bernoulli random variables.




Examples



n = 10:10:60;




r1 = binornd(n,1./n)



r1 =






2




1




0




1




1




2




r2 = binornd(n,1./n,[1 6])



r2 =






0




1




2




1




3




1




r3 = binornd(n,1./n,1,6)



r3 =






0




1




1




1




0




3




chi2rnd


(卡方分布)




n


个相互独立的随机变量ξ


?


、ξ


?


、……、ξ


n


,均服从标准正态分布,则这


n


个服从


标准正态分布的随机变量的平方和构成一新的随机变量,其分布规 律称为χ?分布




Syntax



R = chi2rnd(V)



R = chi2rnd(V,m,n,...)



R = chi2rnd(V,[m,n,...])




Description



R


=


chi2rnd(V)


generates


random


numbers


from


the


chi


-


square


distribution


with


degrees


of


freedom parameters specified by V. V can be a vector, a matrix, or a multidimensional array. R is


the same size as V.




R


=


chi2rnd(V,m,n,...)


or


R


=


chi2rnd(V,[m,n,...])


generates


an


m


-


by


-


n


-


by


-


...


array


containing


random numbers from the chi


-


square distribution with degrees of freedom parameter V. V can


be a scalar or an array of the same size as R.




Examples



Note


that


the


first


and


third


commands


are


the


same,


but


are


different


from


the


second


command.



r = chi2rnd(1:6)



r =







0.0037



3.0377



7.8142



0.9021



3.2019



9.0729




r = chi2rnd(6,[1 6])



r =







6.5249



2.6226



12.2497



3.0388



6.3133



5.0388




r = chi2rnd(1:6,1,6)



r =





0.7638



6.0955



0.8273



3.2506



1.5469



10.9197




Copularnd


(连接函数分布)



Copula


函数描述的是变量间的相关性,实际上是一类将联合分布函数与它们各自的边缘


分布函数连接在一起的函数



Syntax



U = copularnd('Gaussian',rho,N)



U = copularnd('t',rho,NU,N)



U = copularnd('family',alpha,N)




Description



U = copularnd('Gaussian',rho,N) returns N random vectors generated from a Gaussian copula


with linear correlation parameters rho. If rho is a p


-


by


-


p correlation matrix, U is an n


-


by


-


p matrix.


If rho is a scalar correlation coefficient, copularnd generates U from a bivariate Gaussian copula.


Each column of U is a sample from a Uniform(0,1) marginal distribution.




U = copularnd('t',rho,NU,N) returns N random vectors generated from a t copula with linear


correlation parameters rho and degrees of freedom NU. If rho is a p


-


by


-


p correlation matrix, U is


an n


-


by


-


p matrix. If rho is a scalar correlation coefficient, copularnd generates U from a bivariate t


copula. Each column of U is a sample from a Uniform(0,1) marginal distribution.




U


=


copularnd('family',alpha,N)


returns


N


random


vectors


generated


from


the


bivariate

-


-


-


-


-


-


-


-



本文更新与2021-02-28 08:14,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/679804.html

(完整版)Matlab各种随机数设置的相关文章