generate nonrepeated random field values for each Monte Carlo iteration

5 ビュー (過去 30 日間)
Pooneh Shah Malekpoor
Pooneh Shah Malekpoor 2023 年 3 月 9 日
回答済み: Gayatri Rathod 2023 年 4 月 27 日
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 Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by