How can I do a Monte Carlo simulation for 1000 runs on this operation?

조회 수: 1 (최근 30일)
Uche
Uche 2023년 3월 8일
댓글: Uche 2023년 3월 11일
Please can someone help to verify that this is the proper way to run a monte carlo simulation on this code?
% A = T(:,1); %Column vector
A = [71.213; 74.499; 79.175; 54.163; 83.008; 52.615];
B = length(A); %size of column (number of elements)
t = 0; %Variable to store harvest time
number_of_runs = 1000;
for n = 1:number_of_runs
for i = 1:B
H = A(i);
while H > 0
H = H - randi([5 10]);
t = t + randi([2 4]);
end
end
end
t_mean = t/number_of_runs;
disp(t_mean);
  댓글 수: 2
John D'Errico
John D'Errico 2023년 3월 8일
편집: John D'Errico 2023년 3월 9일
Hard to say. That is the proper way to simulate what you simulated. Is it the proper way to simulate what you think you were simulating? That is impossible to tell, since we see only the code you wrote. So perhaps you need to explain what is the goal.

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

채택된 답변

Torsten
Torsten 2023년 3월 9일
Maybe you mean:
% A = T(:,1); %Column vector
A = [71.213; 74.499; 79.175; 54.163; 83.008; 52.615];
B = length(A); %size of column (number of elements)
number_of_runs = 1000;
T = zeros(number_of_runs,1); %Variable to store harvest time
for n = 1:number_of_runs
t = 0;
for i = 1:B
H = A(i);
while H > 0
H = H - randi([5 10]);
t = t + randi([2 4]);
end
end
T(n) = t;
end
plot(1:number_of_runs,T)
t_mean = sum(T)/number_of_runs;
disp(t_mean);
175.9570

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Verification, Validation, and Test에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by