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일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 2월 8일

편집:

2021년 2월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by