Discrete and continuous random variables distribution

I want to plot normal Gaussian distribution

9 件のコメント

Walter Roberson
Walter Roberson 2022 年 2 月 26 日
randi() can be used to generate the random values. However I do not understand what you are plotting.
John D'Errico
John D'Errico 2022 年 2 月 26 日
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
Walter Roberson 2022 年 2 月 26 日
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
Torsten 2022 年 2 月 26 日
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
Walter Roberson 2022 年 2 月 27 日
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.
Torsten
Torsten 2022 年 2 月 27 日
編集済み: Torsten 2022 年 2 月 27 日
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
Walter Roberson 2022 年 2 月 27 日
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.
Torsten
Torsten 2022 年 2 月 27 日
編集済み: Torsten 2022 年 2 月 27 日
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
Walter Roberson 2022 年 2 月 27 日
Oh... maybe! The wording of it was rather confusing!

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

 採用された回答

Torsten
Torsten 2022 年 2 月 26 日
編集済み: Torsten 2022 年 2 月 26 日

0 投票

n = 10000;
x = rand(n,1);
n1 = numel(x(x<=0.5));
n2 = numel(x(x>0.5));
y1 = randn(n1,1);
y2 = zeros(n2,1);
y = [y1;y2];
histogram(y,'Normalization','pdf')
hold on
cdfplot(y)

5 件のコメント

john adam
john adam 2022 年 2 月 26 日
thank you for your efforts, can you clearify the steps of the code please and i also need plot of the PDF.
Torsten
Torsten 2022 年 2 月 26 日
編集済み: Torsten 2022 年 2 月 26 日
I can't use MATLAB at the moment, but there should be two curves in the plot: PDF and CDF.
I think the code should be self-explaining.
john adam
john adam 2022 年 2 月 26 日
thank you and I apricate your cooperation but could you clarify n1 = numel(x(x<=0.5)) meaning please ?
Torsten
Torsten 2022 年 2 月 26 日
編集済み: Torsten 2022 年 2 月 26 日
n coin tosses are simulated by producing n uniformly distributed random numbers over [0:1]
(x = rand(n,1)).
We assume that the i-th coin toss gave head if x(i) <= 0.5, else if x(i) > 0.5, it gave tail.
We count the number of heads (n1 = numel(x(x<=0.5))) and the number of tails (n2 = numel(x(x>0.5))).
For the n1 heads, we generate random numbers drawn from the standard normal distribution.
For the n2 tails, we set the outcome to 0.
Now we mix the random numbers (y=[y1;y2]) and compute empirical PDF (histogram(...)) and CDF (cdfplot(...)) of the mixed distribution.
And now it's up to you to compute the explicit formulae for the theoretical PDF and CDF :-)
Walter Roberson
Walter Roberson 2022 年 2 月 27 日
n1 = numel(x(x<=0.5));
can also be written
n1 = nnz(x<=0.5);

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

その他の回答 (2 件)

Image Analyst
Image Analyst 2022 年 2 月 26 日

0 投票

"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 件のコメント

john adam
john adam 2022 年 2 月 26 日
thank you for your help, but i need to plot normal gaussian distribution random variable if the result is head, means the plot represnts mixed random variable the first one is discrete (tossing the coin) and the second is continous (normal gaussian random varriable), could you help me with this?
Image Analyst
Image Analyst 2022 年 2 月 26 日
Looks like you're all set now since you accepted the other answer.

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

Walter Roberson
Walter Roberson 2022 年 2 月 27 日

0 投票

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.

質問済み:

2022 年 2 月 26 日

編集済み:

2022 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by