フィルターのクリア

Problem with generating random numbers when performing a Monte carlo simulation in Matlab ?

3 ビュー (過去 30 日間)
Hi there,
I am performing a Monte carlo simulation and this is the code for it.
clc; clear all;
num_simulations = 1000 ;
P_init = repmat(5,10,1)
numAC = length(P_init) ;
sumReduction = zeros(num_simulations,1);
for i = 1 : num_simulations
DRM_levels = [0.25, 0.5, 0.75, 1.0]';
DRM_prob = [.25, .25, .25, .25];
s = RandStream('mlfg6331_64');
ReductionLevelsVector = randsample(s, DRM_levels , numAC, true, DRM_prob);
ActualReduction = P_init .* ReductionLevelsVector ;
sumReduction(i) = sum(ActualReduction) ;
end
However after performing num_simulations iterations I find that I am ended up getting the same result for sumReduction in each iteration. Is there something wrong with the Random number generator I am using, so it continues to generate the same random number at each iteration.
Can anyone please help me with this ?
Thanks.
  3 件のコメント
Gayan Lankeshwara
Gayan Lankeshwara 2020 年 5 月 17 日
Thanks a lot Walter, now it works fne.
Cheers.
Pradeep Jangid
Pradeep Jangid 2021 年 4 月 1 日
When I run your code after writing randstrem before loop. But when I made plot of xcorr(sumReduction), It's almost trinangle. It means there is no chnge in correltion. Please help If I'm wrong.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by