1

MATLAB でモンティ ホールのパラドックスを証明するスクリプトを作成していますが、問題があります。MATLAB で前の 2 つとは異なる 1 ~ 3 の乱数を生成する方法がわかりません。

これが私のスクリプトです:

% This program demostrates the Monty Hall paradox.
% A_pick1 represents where person chooses to put the five-pound note
% B_pick1 represents which box person B  first identifies
% A_pick2 represents the box that person A opens up - it must be different
% than both A_pick1 and B_pick2

A_pick1 = round(3 * rand(1) + 0.5)
B_pick1 = round(3 * rand(1) + 0.5)
A_pick2 = round(3* rand(1) + 0.5);
while (A_pick2 == A_pick1 || A_pick2 == B_pick1)
   A_pick2 = rand(3 * rand(1) + 0.5) ~= (A_pick1 && B_pick1)
    break
end

while ループの正しい使い方がわかりません。

前もって感謝します

4

3 に答える 3

3

randiとを使用するのはどうsetxorですか。

A_pick1 = randi(3);
B_pick1 = randi(3);

x = setxor(1:3,[A_pick1, B_pick1]);
A_pick2 = x(randi(numel(x)));

統計ツールボックスを持っている場合は他の選択肢がありますが、これでうまくいくと思います。

幸運を!

于 2014-04-03T13:23:59.360 に答える
0
while (A_pick2 == A_pick1 || A_pick2 == B_pick1)
   A_pick2 = rand(3 * rand(1) + 0.5);
end
于 2014-07-21T07:24:49.753 に答える