Probability single for loop
3 次查看(过去 30 天)
显示 更早的评论
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 个)
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);
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!