Random Variates when the cumulative distribution is known.
Afficher commentaires plus anciens
(This question has been removed)
2 commentaires
Stephen23
le 15 Oct 2020
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.
Réponses (1)
Ameer Hamza
le 1 Oct 2020
Modifié(e) : Ameer Hamza
le 1 Oct 2020
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)

If you don't have toolbox, then use this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/26003-random-numbers-from-a-user-defined-distribution
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.
Catégories
En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!