Monte Carlo simulation dice roll
Show older comments
Define a single function named display that returns nothing and takes two input parameters, an array of counters and the singular counter for the number of doubles rolled. The function displays the estimated probability of rolling each of the potential values from 1 to the maximum number that can be rolled (which can be calculated from the aforementioned input parameters).
Recall, estimated probability is the calculated estimate of the theoretical probability of a scenario. To calculate an estimated probability we take the number of occurrences for a scenario and divide by the number of possible occurrences (the number of simulations).
I am unsure why my for loop is not printing out the statement. I also dont know how to get the probablity.
[numSims, numDice, numSides]=userInput();
x=zeros(1,numDice*numSides);
y=zeros();
function [numSims, numDice, numSides]=userInput()
numSims=input("How many simulations?");
numDice=input("How many dice?");
numSides=input("How many sides on each die?");
end
function display(x,y)
for i=1:length(x)
fprintf('Estimated probablity of rolling a %d/n',i (': %d/n'));
end
end
Answers (1)
Image Analyst
on 17 Mar 2021
0 votes
It is because you never call display().
Categories
Find more on RF Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!