资源描述:
《Matlab 各种随机数设置》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Matlab各种随机数设置randn(伪随机正态分布数)NormallydistributedpseudorandomnumbersSyntaxr=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')Descriptionr=randn(n)returnsann-by-nmatrixcontainingpseudorandomvaluesdrawnfromthestandardnormal
2、distribution.randn(m,n)orrandn([m,n])returnsanm-by-nmatrix.randn(m,n,p,...)orrandn([m,n,p,...])returnsanm-by-n-by-p-by-...array.randnreturnsascalar.randn(size(A))returnsanarraythesamesizeasA.r=randn(...,'double')orr=randn(...,'single')returnsanarrayofnormalvaluesofthespecifiedclass.NoteThe
3、sizeinputsm,n,p,...shouldbenonnegativeintegers.Negativeintegersaretreatedas0.Thesequenceofnumbersproducedbyrandnisdeterminedbytheinternalstateoftheuniformpseudorandomnumbergeneratorthatunderliesrand,randi,andrandn.randnusesoneormoreuniformvaluesfromthatdefaultstreamtogenerateeachnormalvalu
4、e.Controlthedefaultstreamusingitspropertiesandmethods.NoteInversionsofMATLABpriorto7.7(R2008b),youcontrolledtheinternalstateoftherandomnumberstreamusedbyrandnbycallingrandndirectlywiththe'seed'or'state'keywords.ExamplesGeneratevaluesfromanormaldistributionwithmean1andstandarddeviation2.r=1
5、+2.*randn(100,1);Generatevaluesfromabivariatenormaldistributionwithspecifiedmeanvectorandcovariancematrix.mu=[12];Sigma=[1.5;.52];R=chol(Sigma);z=repmat(mu,100,1)+randn(100,2)*R;ReplacethedefaultstreamatMATLABstartup,usingastreamwhoseseedisbasedonclock,sothatrandnwillreturndifferentvaluesi
6、ndifferentMATLABsessions.ItisusuallynotdesirabletodothismorethanonceperMATLABsession.RandStream.setDefaultStream...(RandStream('mt19937ar','seed',sum(100*clock)));randn(1,5)Savethecurrentstateofthedefaultstream,generate5values,restorethestate,andrepeatthesequence.defaultStream=RandStream.g
7、etDefaultStream;savedState=defaultStream.State;z1=randn(1,5)defaultStream.State=savedState;z2=randn(1,5)%containsexactlythesamevaluesasz1Normrnd(随机正态分布数)NormalrandomnumbersSyntaxR=normrnd(mu,sigma)R=normrnd(mu,sigma,m,n,...)R=normrnd(mu,sigma,[m,n,...])Descrip