Random Variates when the cumulative distribution is known.

조회 수: 1 (최근 30일)
Vinay Ahir
Vinay Ahir 2020년 10월 1일
편집: Stephen23 2020년 10월 15일
(This question has been removed)
  댓글 수: 2
Stephen23
Stephen23 2020년 10월 15일
Random Variates when the cumulative distribution is known.
Vinay Ahir on 1st of October 2020 at 14:00:
For a simulation, I need to generate random variate numbers (RVN).
The cumulative distribution F is known and is according the following code:
x=0:(pi/100):pi/2;
F=sin(x); % an always growing curve
I need to generate 2000 random variate number and show the histogram of the numbers.

댓글을 달려면 로그인하십시오.

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 1일
편집: Ameer Hamza 2020년 10월 1일
If you have statictics and machine learning toolbox, the try piecewise linear distributon
x=0:(pi/100):pi/2;
PDF = sin(x);
CDF = cumtrapz(x, PDF);
CDF(end) = 1; % requirement of PiecewiseLinear, last element must be exactly 1.
p = makedist('PiecewiseLinear', 'x', x, 'Fx', CDF);
x = random(p, 100000, 1); % generate 100000 samples
histogram(x)
Also, look at this method: https://en.wikipedia.org/wiki/Inverse_transform_sampling. CDF is easily invertible in this interval, so you can code your own method from scratch too.
  댓글 수: 2
Vinay Ahir
Vinay Ahir 2020년 10월 1일
Thank you so much. Works flawlessly.
Ameer Hamza
Ameer Hamza 2020년 10월 1일
I am glad to be of help!

댓글을 달려면 로그인하십시오.

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by