Discrete and continuous random variables distribution
Mostrar comentarios más antiguos
I want to plot normal Gaussian distribution
9 comentarios
Walter Roberson
el 26 de Feb. de 2022
randi() can be used to generate the random values. However I do not understand what you are plotting.
John D'Errico
el 26 de Feb. de 2022
A coin toss is NOT Gaussian. However, the law of large numbers tells you that the sum of MANY coin tosses will be effectively the sum of many iid binomial random variables, which in aggregate, will be approximately and asymptotically normally distributed.
Walter Roberson
el 26 de Feb. de 2022
Sometimes for this purpose you want to generate a 2d array of random values 0 1, and sum them along one dimension and divide by the length of the dimension. There result is an experimental probability that the coin was in a particular state after that many tosses. The other dimension corresponds to repeating the experiment.
Torsten
el 26 de Feb. de 2022
The OP searches for the PDF and CDF for a random variable which gives 0 with probability 0.5 and a number drawn from the standard normal distribution also with probability 0.5.
Walter Roberson
el 27 de Feb. de 2022
I do not agree. The question specifically mentions discrete random variables. That is not the same as "a random variable which gives 0 with probability 0.5".
Consider a symmetric beta distribtution over
to
. Then there is a value of α for which the peak PDF would be 0.5 at x = 0 -- but it would not be a discrete distribution.
In my opinion, the OP searches for the PDF and CDF of a "mixture" random variable (i.e. a random variable that is neither discrete nor continuous). There will be a discontinuity at x=0 for the PDF as well as for the CDF. In all other points, it will be continuous.
Walter Roberson
el 27 de Feb. de 2022
Unfortunately the poster edited away the original question. It referred to coin tosses -- and coin tosses are discrete.
I believe they were being asked to simulate coin tosses and determine an imperical PDF and CDF.
I only remember the OP's name: Mohamed Wnis.
The problem was that a random variable was defined to give 0 if the coin toss gave tail and to give a number randomly drawn from the standard normal distribution if the coin toss gave head.
Walter Roberson
el 27 de Feb. de 2022
Oh... maybe! The wording of it was rather confusing!
Respuesta aceptada
Más respuestas (2)
"tosses a coin and the result is head, and if the result is tail plot 0 in that point,"
Here's a start
numTosses = 30;
tosses = randi([0,1], numTosses, 1);
bar(tosses);
grid on;
xlabel('Toss Number');
2 comentarios
john adam
el 26 de Feb. de 2022
Image Analyst
el 26 de Feb. de 2022
Looks like you're all set now since you accepted the other answer.
Walter Roberson
el 27 de Feb. de 2022
0 votos
For this purpose you want to generate a 2d array of random values 0 1, and sum them along one dimension and divide by the length of the dimension. There result is an experimental probability that the coin was in a particular state after that many tosses. The other dimension corresponds to repeating the experiment. Histogram the experimental probabilities to get pdf. cumsum the pdf to get the cdf.
Categorías
Más información sobre Exploration and Visualization en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
