randpdf#
- randpdf(p, px, dim)
- RANDPDF
Random numbers from a user defined distribution
- SYNTAX:
- x = randpdf(p, px, dim)
randpdf(p, px, dim)
- INPUT:
p - probability density, px - values for probability density, dim - dimension for the output matrix.
- OUTPUT:
x - random numbers. Run function without output for some plots.
- DESCRIPTION:
x = randpdf(p, px, dim) returns the matrix of random numbers from probability density distribution defined in p and px. p are the density (the y axis) and px are the value (the x axis) of the pdf. p and px must be of the same length. dim define the output matrix dimensions, for example dim=[100 3] define the 100x3 two dimensional matrix with 300 random numbers.
REMEMBER: This is not a realy random number generator but only some kind of transformation of uniformly distributed pseudorandom numbers to desired pdf!
- EXAMPLE 1:
Generation of normal distributed random numbers. This is not typical normal distribution because is limited from the left and right side, i.e. 0 < px < 80 .
px=0:80; p=1./(10*sqrt(2*pi))*exp((-(px-40).^2)./(2*10^2)); randpdf(p,px,[10000,1])
- EXAMPLE 2:
Generation using user defined pdf.
px=[1 2 3 4 5 6 7 8 9]; p= [0 1 3 0 0 4 5 4 0]; randpdf(p,px,[50000,1])