Generate random number from custom PDF and CDF
Ältere Kommentare anzeigen
I basically have the following CDF and PDF respectivley:


Where the range is from 0 to a as mentioned in the CDF line. I would like to generate random numbers on matlab based on these equations. Has anyone done this before? Anyone has experience on this? I've tried looking on the forum but
Thanks in advance!!
(For those of you interested, it is the distribution of a 1-D Random Waypoint Mobility model proposed by Bettstetter et al.)
Akzeptierte Antwort
Weitere Antworten (1)
Ameer Hamza
am 17 Nov. 2020
Bearbeitet: Ameer Hamza
am 17 Nov. 2020
MATLAB does not support arbitrary CDF functions, but you can approximate it using non-parametric distributions: https://www.mathworks.com/help/stats/nonparametric-and-empirical-probability-distributions.html. If you have statistics and ML toolbox, you can create a PiecewiseLinear distribution or an empirical distribution. The following shows an example
a = 4;
x = 0:0.01:a;
Fx = -2/a^3*x.^3+3/a^2*x.^2;
fx = -6/a^3*x.^2+6/a^2*x;
F_dist = makedist('PiecewiseLinear', 'x', x, 'Fx', Fx);
rand_nums = random(F_dist, 1, 1000000);
histogram(rand_nums, 'Normalization', 'pdf')
hold on
plot(x, fx, 'r', 'LineWidth', 2)
Comparison of generated and the theoretical PDF.

If you don't have the toolbox, you can use following FEX packages
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
