Code covered by the BSD License  

Highlights from
Random numbers from a user defined piecewise polynomial distribution

image thumbnail

Random numbers from a user defined piecewise polynomial distribution



RANDPDFS returns pseudorandom values drawn from an arbitrary distribution defined by the pp-form.

%% Randpdfs
% Distributed pseudorandom numbers from an user defined distribution function.

%% Syntax
% r=randpdfs(ppdf,n)
% r=randpdfs(ppdf,n,m)
% r=randpdfs(ppdf,[n,m])

%% Description
% r=randpdfs(ppdf,n) returns an n-by-n matrix containing pseudorandom values
% drawn from an user defined probability distribution. 
% The probability distribution function is defined by using a pp-form 
% which can be easily created using spline matlab command. 
% The syntax to create random matrix is the same one used by rand command.  

x=0:.05:2*pi; y=1+.5*cos(3*x-pi);

% All the information required to compute the random sequence are extracted
% from the pp-form structure, in particular the lowest and the highest 
% generated numbers corresponds to the first and last break of the pp form 
% respectively.
% randpdfs uses fnint to compute the cumulative distribution function,
% therefore spline toolbox has to be accessible to allow randpdfs working
% properly.

%% Example
% Generate values from an arbitraty distribution on the interval [0 2*pi]

clf; hold on
hold off
xlabel('Values','FontSize',12); ylabel('Occurence','FontSize',12)

%% See also
% rand, spline, fnint 

Contact us