Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Matlab中有任何函数可以在闭合区间内生成随机实数。我发现了一些东西,unifrnd()但它在开区间内生成数字。如果我使用unifrnd(x,y);我得到 (x,y) 间隔,而不是 [x,y]。
unifrnd()
unifrnd(x,y);
鉴于评论中对准确性的讨论,您可以使用以下内容:
mag = floor(log10( y - x)) num = unifrnd(x-(10^mag)*eps, y+(10^mag)*eps)
这实质上为离散区间表示增加了一个“点”,同时考虑到基于您使用的数字大小的准确性。 unifrnd()本质上是一个包装器rand()(这意味着您实际上并不需要统计工具箱来执行此操作),因此它实际上只是在 (0,1) 上缩放均匀分布。但是,如果您担心端点,那很重要,因为您无法比乘积更细化区间长度的大小eps。
rand()
eps