how can i create Bernoulli random variable of a given probability

8 ビュー (過去 30 日間)
smr
smr 2022 年 8 月 15 日
編集済み: Torsten 2022 年 8 月 15 日
i have avalue of propability but i want to create a bernoulli random variable
P_LOS_1(i)=exp(-d(i)*lambda1);
x(i)=binornd(1,P_LOS_1(i));
P_NLOS1(i)=1-P_LOS1(i);
y(i)=binornd(1,P_NLOS_1(i));
If x(i) is one, y(i) MUST be zero and vice versa
but by this code it not true
i want to know what is error here ??

採用された回答

Torsten
Torsten 2022 年 8 月 15 日
編集済み: Torsten 2022 年 8 月 15 日
p = 0.2;
n = 20000;
A = binornd(ones(n,1),p)
A = 20000×1
1 0 0 0 1 1 0 0 1 0
p_num = sum(A)/n
p_num = 0.2020
B = 1 - A
B = 20000×1
0 1 1 1 0 0 1 1 0 1
one_minus_p_num = sum(B)/n
one_minus_p_num = 0.7981

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElementary Math についてさらに検索

タグ

製品


リリース

R11.1

Community Treasure Hunt

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

Start Hunting!

Translated by