Effacer les filtres
Effacer les filtres

Using a triangular distribution in a Monte Carlo simulation

4 vues (au cours des 30 derniers jours)
Rabia Sonmez
Rabia Sonmez le 25 Sep 2021
Modifié(e) : Image Analyst le 25 Sep 2021
Hello everyone. I am trying to simulate Monte Carlo analysis using a triangular distribution. I have 10 different subassemblies with its min, max, and best values. I put them into a matrix, as shown below. The first row of the matrix represents subassembly 1 and second row is subassembly 2 and it goes like this. I've chosen random numbers from all different subassemblies, and I sum these numbers. But I want to do this 1000 times, so it should give 100 results. But I could not put it into code. Please help!! Thank you
clear all
clc
sub=[97 122 185;56 68 98;143 164 225;29 33 48;68 74 96;131 147 194;107 132 178;41 46 62;69 81 117;58 63 92];
sum=0;
ntime=3;
for i=1:10
b(i,:)=randi([min(sub(i,:)),max(sub(i,:))],1);
sum=sum+b(i,:);
end
  1 commentaire
Image Analyst
Image Analyst le 25 Sep 2021
sum is a built-in function so you should not use it as the name of your variable.
If you want to do that 10-iteration for loop 1000 times (or 100 times), just put it inside another for loop where you loop 1000 times (or 100 times).

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by