How to use the random variables Xt (outcomes of a dice roll) to define another random variable T5 ?

3 ビュー (過去 30 日間)
I am trying to model Dice Rolling (fair die) as a Stochastic process.
I used a row vector p of size 6 with each entry equals to 1/6 in order to represent probabilties of outcomes (1 to 6):
p = ones(1,6)/6
This gives me the following output :
p =
0.1667 0.1667 0.1667 0.1667 0.1667 0.1667
Now, I want to define another random variable T5 such that it shows me the first time I got a 5 when rolling the dice . I tried to plot the outcomes in another matrix [1,2,3,4,5,6] and also tried to do it using a rand function. But I am not getting the desires expression for it.
What would be the MatLab expression for :
P[T5=t] = P { Xt is the first random variable with outcome 5} .

回答 (1 件)

Steven Lord
Steven Lord 2021 年 6 月 12 日
I wouldn't use rand here. I'd use randi to directly generate the values of the fair die roll. [If you were later going to simulate a non-fair die then rand would have a role to play, perhaps combined with discretize.]
Since this sounds like a homework assignment I'm only going to describe how I'd do it rather than giving you the code. Try implementing this procedure and if you encounter difficulty show how far you've gotten with that implementation.
Roll the die t times. If the only 5 in that vector of rolls was the last entry, it counts as a success. Otherwise it counts as a failure. Repeat this process as many times as you need to get an accurate estimate of the probability. You could run a block of multiple runs at once by generating a matrix, if you wanted to minimize the number of calls to the random number generator.


Find more on Creating and Concatenating Matrices 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!

Translated by