generate nonrepeated random field values for each Monte Carlo iteration
7 次查看(过去 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
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
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
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!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!