generate nonrepeated random field values for each Monte Carlo iteration

9 次查看(过去 30 天)
Hello
If I want to generate different random field values (with the same statistical parameters) for different iterations of a Monte Carlo simulation, what command shall I use?
Thanks
Pooneh
  2 个评论
John D'Errico
John D'Errico 2023-3-9
编辑:John D'Errico 2023-3-9
Far too vague a question. A a start, I might ask...
Do you want the random elements to come from the same population? This is trivial. Just use rand, or randn, or any tool. The point is, there is a difference between a population mean, and a sample mean from a random set of variates.
Are these integer variables, or discrete variables?
What cannot repeat? Is the vector [1 2] distinct from [2 1]?
What statistical parameters must be maintained? Mean? Variance? Skewness? Kurtosis? Median?
What number of dimensions does this problem lie in?
Can you generate the set of all samples in advance, or is there some reason why you think you need to do so sequentially?
Please give an example of exactly what you would like to see done.
the cyclist
the cyclist 2023-3-9
I'll add to John's comment that if you google the terms MATLAB random, the first hit you get will probably be the MATLAB documentation page Random Number Generation, which will probably answer whatever questions you have.

请先登录,再进行评论。

回答(1 个)

Gayatri Rathod
Gayatri Rathod 2023-4-27
Hi Pooneh,
  • To generate different random field values for different iterations of a Monte Carlo simulation with the same statistical parameters, you can use MATLAB's randn function. This function generates an array of normally distributed random numbers with a mean of 0 and a standard deviation of 1.
  • You can then transform these numbers to match the desired statistical parameters of your random field using linear scaling method.
  • Assuming you want to generate a random field of size m by n, with a mean of mu and standard deviation of sigma, you can use the following code:
% Set the random seed for reproducibility
rng(0);
% Generate the random field, transform the random numbers to the desired distribution
random_field = mu + sigma * randn(m, n);
  • The rng function sets the random seed to a fixed value (in this case, 0) to ensure that the same sequence of random numbers is generated each time the code is run. You can change the seed value to generate a different sequence of random numbers.
  • The randn function generates an array of normally distributed random numbers with a mean of 0 and a standard deviation of 1. The mu and sigma values are used to transform the random numbers to the desired mean and standard deviation.
You can read more about the randn and rng functions from the following documentations: randn function, rng function.
Hope it helps!

类别

Help CenterFile Exchange 中查找有关 Parallel Computing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by