在MATLAB中控制随机数/数据集的生成 [英] Controlled random number/dataset generation in MATLAB

查看:289
本文介绍了在MATLAB中控制随机数/数据集的生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说,我有一个尺寸为1x1x1的多维数据集,范围介于坐标(0,0,0)和(1,1,1)之间.我想在此多维数据集中生成一个随机的点集(假设有10个点),这些点有些均匀地分布(即,在彼此之间的一定最小和最大距离之内,并且也不太靠近边界).我如何不使用循环来解决这个问题?如果使用向量/矩阵操作无法做到这一点,那么使用循环的解决方案也可以.

Say, I have a cube of dimensions 1x1x1 spanning between coordinates (0,0,0) and (1,1,1). I want to generate a random set of points (assume 10 points) within this cube which are somewhat uniformly distributed (i.e. within certain minimum and maximum distance from each other and also not too close to the boundaries). How do I go about this without using loops? If this is not possible using vector/matrix operations then the solution with loops will also do.

让我提供有关我的问题的更多背景详细信息(这将在我真正需要什么以及原因方面有所帮助).我想将一个函数F(x,y,z)集成到多面体中.我想按数字进行如下操作:

Let me provide some more background details about my problem (This will help in terms of what I exactly need and why). I want to integrate a function, F(x,y,z), inside a polyhedron. I want to do it numerically as follows:

$ F(x,y,z)= \ sum_ {i} F(x_i,y_i,z_i)\ times V_i(x_i,y_i,z_i)$

$F(x,y,z) = \sum_{i} F(x_i,y_i,z_i) \times V_i(x_i,y_i,z_i)$

这里,$ F(x_i,y_i,z_i)$是点$(x_i,y_i,z_i)$处的函数值,而$ V_i $是权重.因此,为了准确地计算积分,我需要确定彼此之间不太近或彼此不太远的一组随机点(对不起,但我本人不知道该范围是多少.我能够弄清楚只有在我有一个有效的代码后,才能使用参数研究.另外,我需要对具有多个多面体的3D网格执行此操作,因此我想避免使用循环来加快速度.

Here, $F(x_i,y_i,z_i)$ is the value of function at point $(x_i,y_i,z_i)$ and $V_i$ is the weight. So to calculate the integral accurately, I need to identify set of random points which are not too close to each other or not too far from each other (Sorry but I myself don't know what this range is. I will be able to figure this out using parametric study only after I have a working code). Also, I need to do this for a 3D mesh which has multiple polyhedrons, hence I want to avoid loops to speed things out.

推荐答案

看看这个不错的

Check out this nice random vectors generator with fixed sum FEX file. The code "generates m random n-element column vectors of values, [x1;x2;...;xn], each with a fixed sum, s, and subject to a restriction a<=xi<=b. The vectors are randomly and uniformly distributed in the n-1 dimensional space of solutions. This is accomplished by decomposing that space into a number of different types of simplexes (the many-dimensional generalizations of line segments, triangles, and tetrahedra.) The 'rand' function is used to distribute vectors within each simplex uniformly, and further calls on 'rand' serve to select different types of simplexes with probabilities proportional to their respective n-1 dimensional volumes. This algorithm does not perform any rejection of solutions - all are generated so as to already fit within the prescribed hypercube."

这篇关于在MATLAB中控制随机数/数据集的生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆