フィルターのクリア

Probability single for loop

1 回表示 (過去 30 日間)
noname
noname 2021 年 2 月 8 日
編集済み: Walter Roberson 2021 年 2 月 21 日
Can anyone show me how to write a single for-loop to computer P[0<x<1] using pdf function for an exponential random variable x? Thanks
  1 件のコメント
darova
darova 2021 年 2 月 21 日
It's too simple question. Please read help

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 21 日
編集済み: Walter Roberson 2021 年 2 月 21 日
count = 0;
N = 10000;
for iteration = 1 : N
thisvalue = exp(rand());
if 0 < thisvalue & thisvalue < 1
count = count + 1;
end
end
P = count ./ N;
fprintf('Probability was %.3f%%\n', P*100);
Probability was 0.000%
The minimum value of rand() is 0, and exp(0) is 1, and 1 < 1 is false, so it makes sense that the probability is 0.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by