Effacer les filtres
Effacer les filtres

how to write a function that ask to outcome the probability of rolling i dice and getting number 5 from the first time?

2 vues (au cours des 30 derniers jours)
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

Réponses (1)

Image Analyst
Image Analyst le 10 Déc 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 commentaire
Image Analyst
Image Analyst le 10 Déc 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)
rolls = 1000×3
5 5 3 1 6 6 1 4 6 2 6 5 5 1 4 2 5 5 2 5 1 2 5 1 2 4 1 1 6 1

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by