永发信息网

matlab中rand('state',123) s=sign(rand(1,1000)-.5) n

答案:2  悬赏:50  手机版
解决时间 2021-03-04 17:42
  • 提问者网友:眉目添风霜
  • 2021-03-04 05:21
matlab中rand('state',123) s=sign(rand(1,1000)-.5) n
最佳答案
  • 五星知识达人网友:逐風
  • 2021-03-04 05:36
rand('state',123) \x05=>用'state'参数可以控制随机数流的内部状态.2010bx64下帮助中说2008b后仍然支持但不推荐,但实际无法执行.提示如下:>> z=rand('state',123)Error using ==> randToo many output arguments.后面参数123这样给是要生成一个123x123的矩阵了.In versions of MATLAB prior to 7.7 (R2008b),you controlled the internal state of the random number stream used by rand by calling rand directly with the 'seed','state',or 'twister' keywords.That syntax is still supported for backwards compatibility,but is not recommended.To update your code,see Updating Your Random Number Generator Syntax in the MATLAB Mathematics documentation.n=sum(s==-1)\x05=>s==-1是逻辑表达式,会按每元素的逻辑表达式成立与否得出对应位置的1/0,所以上面求出的s变量中-1的位置全部替换成1,而其它值都是0.\x05sum是求和,对矢量直接就是加和,这里就是求s中-1值的个数.运行了一下得到500,很完美的验证了均匀随机数生成算法rand相对于0.5的均衡性(因为默认rand是生成0~1随机数,应该在中值0.5左右有等数量的样本).
全部回答
  • 1楼网友:舍身薄凉客
  • 2021-03-04 06:34
对的,就是这个意思
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯