Probability single for loop

1 visualización (últimos 30 días)
noname
noname el 8 de Feb. de 2021
Editada: Walter Roberson el 21 de Feb. de 2021
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 comentario
darova
darova el 21 de Feb. de 2021
It's too simple question. Please read help

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Feb. de 2021
Editada: Walter Roberson el 21 de Feb. de 2021
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.

Categorías

Más información sobre Elementary Math en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by