Monte Carlo

조회 수: 11 (최근 30일)
Ruben Verkempynck
Ruben Verkempynck 2011년 5월 3일
[EDIT: Thu May 12 22:03:30 UTC 2011 Duplicate Removed - MKF]
Hey guys,
how can I let certain parameters in my model have a range using Monte Carlo simulations?
I have a relatively simple model and I would want to designate a range to certain parameters. I would like to create scenarios like holding one parameter in its lowest part of the range while another in its highest part, etc.
Cheers, Ruben

채택된 답변

Oleg Komarov
Oleg Komarov 2011년 5월 12일
This example is what you're looking for: http://www.vertex42.com/ExcelArticles/mc/MatlabMCExample.html
MC is computationally heavy. For this example taken from the link I repeat the procedure 100,000 times drawing samples of 1000. It takes 13 seconds using very low amount of memory.
In MC in general the more you have the better, thus you could optimize this example to generate rand(n,something) to fit the 80% of your memory and reduce the number of loops.
tic
n = 1000;
l = 1e5;
s.ymean = zeros(n,1);
s.ystd = s.ymean;
for ii = 1:l
x1 = randn(n,1) * 5 + 100;
x2 = rand (n,1) * 10 + 5;
y = x2.^2 ./ x1;
s.ymean(ii) = mean(y);
s.ystd (ii) = std(y);
end
toc
  댓글 수: 5
Ruben Verkempynck
Ruben Verkempynck 2011년 5월 18일
Maybe it is easier if I just post the code, sorry:
% Monte Carlo simulation of variable parameters
clear all
close all
pe_alles = 200+200*rand(10000,1);
pt_alles = 80+20*rand(10000,1);
ce_alles = 2547+1000*rand(10000,1);
ct_alles = 450+200*rand(10000,1);
for i = 1:10000
pe = pe_alles(i);
pt = pt_alles(i);
ce = ce_alles(i);
ct = ct_alles(i);
Herring_Baltic
end
You see, I have a function Herring_baltic that uses parameters that are a matrix (10,000,1) filled with random samples.
How did you repeat the example 100,000 times each time drawing 1000 samples? Did you create another loop over the example?
Oleg Komarov
Oleg Komarov 2011년 5월 18일
100,000 samples of 1000 observations.
I don't see any problem in your code with regards to memory. Do you still have memory problems, then You need to inspect your function.
Or post a new thread asking to optimize it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Monte-Carlo에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by