how to write a function that ask to outcome the probability of rolling i dice and getting number 5 from the first time?
3 views (last 30 days)
Show older comments
im trying to write a function that ask the probability of getting number five from rolling a dice ( 1 - 6)
is answer is suppose to be 1\6
0 Comments
Answers (1)
Image Analyst
on 10 Dec 2022
Are you wanting to wanting to solve it by a Monte Carlo simulation? Then simply use randi and histogram.
This looks like a homework problem. If you have any questions ask your instructor or read the link below to get started:
Obviously we can't give you the full solution because you're not allowed to turn in our code as your own.
1 Comment
Image Analyst
on 10 Dec 2022
And we don't recomment using "i" as a variable name since that's the imaginary constant sqrt(-1). So if you roll "i" dice (like i = 8 or something), what does "getting number 5 from the first time" mean? Do you mean like all dice are labeled 1 to i and you're only interested in dice #1's value and none of the rest of the (i-1) dices values? And how many times are you going to roll this set of i dice? You'd need to do it lots of times to get a probability.
i = 3; % Would be better if you called this numberOfDice. This is the number of dice rolled per experiment.
numExperiments = 1000; % However many times you're going to roll the set of i dice.
rolls = randi(6, numExperiments, i)
See Also
Categories
Find more on Monte-Carlo 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!