How do I write pdf of random variable?

11 ビュー (過去 30 日間)
Zaref Li
Zaref Li 2021 年 11 月 10 日
編集済み: DGM 2021 年 11 月 10 日
Hi. I want to generate a set of 1000 uniform random numbers in the interval [0, l] using the MATLAB function rand(l, N). Plot the histogram and the probability distribution function for the sequence and the histogram may be determined by quantizing the interval in ten equal-width subintervals covering the range [0, l] and counting the numbers in each subinterval.
so,
N=1000;
A = rand(1,N);
histogram(A)
B=pdf(A,??);
I created a random variable. I created a histogram. But I don't know how to write probability density function. Can it be written manually? What should I do. I will be glad if you help me.

回答 (1 件)

DGM
DGM 2021 年 11 月 10 日
The PDF for uniform random numbers is just a simple piecewise-constant function.
Consider uniform random numbers with a lower bound of A and an upper bound of B; the central non-zero portion of the PDF has a value of 1/(B-A).
A = 2; % lower bound
B = 12; % upper bound
x = linspace(0,16,1000); % interval to evaluate PDF
p = ((x>=A) & (x<=B))/(B-A); % PDF
plot(x,p)
  2 件のコメント
Zaref Li
Zaref Li 2021 年 11 月 10 日
How can I combine this with the rand() command?
DGM
DGM 2021 年 11 月 10 日
編集済み: DGM 2021 年 11 月 10 日
Since this is some sort of assignment, it all depends what you're assuming you know about the random "data". I assumed that we already knew A and B. In that case, the output of rand() is unnecessary except to do the histogram part of the task. In your case, A is 0 and B is 1.
If you assume that you don't know A and B, then you can approximate them by finding the min() and max() of the random data. Of course at that point, you're still assuming that you know that the distribution is uniform.

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

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by