What to do with for-while loop?

1 次查看(过去 30 天)
Sherman Ng
Sherman Ng 2022-4-3
回答: Torsten 2022-4-3
The question is "Create the matrix based on the probabilities [0.125 0.125 0.125 0.125 0.125 0.125 0.125 0.125] until you get the 1st 8 "
So apparently the question is only asking for the u's and b's so I do not have to compute the list of s. Apparently I need a for-while-loop to fill in values of u and b. How should I do the for-while loop though?
  2 个评论
Torsten
Torsten 2022-4-3
u = rand()
gives you only one random number.
So over what do you sum in the next line of your code ?
Sherman Ng
Sherman Ng 2022-4-3
I think u should be between 0 and 1 and b should be the position of u inside the cdf.
And then I have to do a for-while loop to repeat that step until the answer is equal to 8.

请先登录,再进行评论。

回答(1 个)

Torsten
Torsten 2022-4-3
number_on_dice = 6;
bu = [ ];
while number_on_dice ~= 8
u = rand();
number_on_dice = sum(cdf <= u) + 1;
bu = [bu;[u,number_on_dice]];
end

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by