Code covered by the BSD License  

Highlights from
Simple Rejection Sampling

Be the first to rate this file! 31 Downloads (last 30 days) File Size: 1.68 KB File ID: #27590 Version: 1.0

Simple Rejection Sampling



Return values sampled from a user defined distribution. Samples are not guaranteed IID.

| Watch this File

File Information

SAMPLEDIST Sample from an arbitrary distribution
    sampleDist(f,M,N,b) retruns an array of size X of random values sampled from the distribution defined by the probability density function referred to by handle f, over the range b = [min, max]. M is the threshold value for the proposal distribution, such that f(x) < M for all x in b.
    sampleDist(...,true) also generates a histogram of the results with an overlay of the true pdf.
    %Sample from a step function over [0,1]:
    X = sampleDist(@(x)1.3*(x>=0&x<0.7)+0.3*(x>=0.7&x<=1),...
    %Sample from a normal distribution over [-5,5]:
    X = sampleDist(@(x) 1/sqrt(2*pi) *exp(-x.^2/2),...

MATLAB release MATLAB 7.9 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.

Contact us