generate random numbers according to pdf or cdf

Versión 1.0.2 (1,68 KB) por halleyhit
generate random numbers according to a user defined probability density function (pdf) or cumulative distribution function (cdf)
306 descargas
Actualizado 15 ago 2018

Ver licencia

Coded by halleyhit on Aug. 15th, 2018
Email: halleyhit@sjtu.edu.cn or halleyhit@163.com

Syntax
y = randdf(S,D,F)
S - Size of dimension, integer values.
Example: S=10 creates a 10-by-1 array
Example: S=[10,2] creates a 10-by-2 matrix

D - Density function, numeric matrix
Pdf or cdf is described by a matrix, whose size is N-by-2.
Sampling points of pdf or cdf form the second row.
Function value of pdf or cdf form the first row.

F - Flag, 'pdf' or 'cdf'

Example:
x=[-1:0.01:1];% Sampling points
y=2*(x<0).*(x>-0.1)+4*(x<0.5).*(x>0.3);% Function value of pdf
plot(x,y,'black')
r=randdf([10000],[y;x],'pdf'); % generate random numbers
hold on
h=histogram(r);
h.Normalization='pdf';
h.BinWidth=0.01;
h.EdgeColor='none'; % view the pdf of the generated numbers

Citar como

halleyhit (2024). generate random numbers according to pdf or cdf (https://www.mathworks.com/matlabcentral/fileexchange/68492-generate-random-numbers-according-to-pdf-or-cdf), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2018a
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Etiquetas Añadir etiquetas

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
1.0.2

update screenshot

1.0.1

Update summary

1.0.0